-
Notifications
You must be signed in to change notification settings - Fork 0
PhoneBook #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vologin-dmitry
wants to merge
2
commits into
master
Choose a base branch
from
PhoneBook
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
PhoneBook #71
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,17 @@ | ||
| image: Visual Studio 2017 | ||
| image: Visual Studio 2019 | ||
|
|
||
| init: | ||
| - git config --global core.autocrlf true | ||
|
|
||
| environment: | ||
| matrix: | ||
| - solution: Semester4/PhoneBook/PhoneBook.sln | ||
|
|
||
| before_build: | ||
| - nuget restore semester2/6.1/HW6T2.sln | ||
| - nuget restore %solution% | ||
|
|
||
| build: | ||
| project: semester2/2.3/2.3.sln | ||
| project: $(solution) | ||
|
|
||
| test_script: | ||
| - dotnet test %solution% |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PhoneBook", "PhoneBook\PhoneBook.fsproj", "{79F13619-3F30-4C58-ADA5-3ED232855DE0}" | ||
| EndProject | ||
| Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PhoneBookTests", "PhoneBookTests\PhoneBookTests.fsproj", "{83419304-CBAE-4658-8FB7-85AC0545BC76}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {79F13619-3F30-4C58-ADA5-3ED232855DE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {79F13619-3F30-4C58-ADA5-3ED232855DE0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {79F13619-3F30-4C58-ADA5-3ED232855DE0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {79F13619-3F30-4C58-ADA5-3ED232855DE0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {83419304-CBAE-4658-8FB7-85AC0545BC76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {83419304-CBAE-4658-8FB7-85AC0545BC76}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {83419304-CBAE-4658-8FB7-85AC0545BC76}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {83419304-CBAE-4658-8FB7-85AC0545BC76}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| EndGlobal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| module PhoneBook | ||
|
|
||
| open System | ||
| open System.IO | ||
|
|
||
| /// Simple phonebook with names and phone numbers | ||
| type PhoneBook = | ||
|
|
||
| /// Add new record | ||
| static member Add name number seq = | ||
| if not <| Seq.contains (name, number) seq then | ||
| Seq.append seq [(name, number)] | ||
| else seq | ||
|
|
||
| /// Get name of person by its telephone number | ||
| static member GetName number seq = | ||
| Seq.filter(fun x -> snd x = number) seq | ||
|
|
||
| /// Get telephone number of person by its name | ||
| static member GetNumber name seq = | ||
| Seq.filter(fun x -> fst x = name) seq | ||
|
|
||
| /// Read some records from file | ||
| static member ReadFromFile filePath seq = | ||
| File.ReadLines (filePath) | ||
| |> Seq.filter(fun x -> x |> System.String.IsNullOrWhiteSpace |> not) | ||
| |> Seq.map(fun x -> x.Split (".....", StringSplitOptions.RemoveEmptyEntries)) | ||
| |> Seq.map(fun x -> (x.[0], x.[1])) | ||
| |> Seq.filter(fun x -> Seq.contains x seq |> not) | ||
| |> Seq.append seq | ||
|
|
||
| /// Write all your records in file | ||
| static member WriteToFile filePath seq = | ||
| File.WriteAllLines(filePath, seq |> Seq.map(fun x -> fst x + "....." + snd x)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp3.1</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="PhoneBook.fs" /> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| open System | ||
| open System.IO | ||
| open PhoneBook | ||
|
|
||
| [<EntryPoint>] | ||
| let main argv = | ||
| /// Main menu of phonebook | ||
| let rec menu (seq) = | ||
| match Console.ReadLine () with | ||
| | "1" -> 0 | ||
| | "2" -> | ||
| printfn "Please enter name" | ||
| let name = Console.ReadLine () | ||
| printfn "Please enter phone" | ||
| let number = Console.ReadLine () | ||
| printfn "Done!" | ||
| menu (PhoneBook.Add name number seq) | ||
| | "3" -> | ||
| printfn "Please enter name to search" | ||
| let name = Console.ReadLine () | ||
| let answer = PhoneBook.GetNumber name seq | ||
| if Seq.length answer = 0 then | ||
| printfn "Sorry, name not found" | ||
| menu seq | ||
| else | ||
| Seq.iter (fun x -> x |> snd |> printfn "Number is: %A") answer | ||
| menu seq | ||
| | "4" -> | ||
| printfn "Please enter phone to search" | ||
| let number = Console.ReadLine () | ||
| let answer = PhoneBook.GetName number seq | ||
| if Seq.length answer = 0 then | ||
| printfn "Sorry, number not found" | ||
| menu seq | ||
| else | ||
| Seq.iter (fun x -> x |> fst |> printfn "Name is: %A") answer | ||
| menu seq | ||
| | "5" -> | ||
| printfn "Your data:" | ||
| seq |> Seq.iter(fun (name, number) -> printfn "%A %A" name number) | ||
| menu seq | ||
| | "6" -> | ||
| printfn "Please enter file path" | ||
| let path = Console.ReadLine () | ||
| PhoneBook.WriteToFile path seq | ||
| printfn "Done!" | ||
| menu seq | ||
| | "7" -> | ||
| printfn "Please enter file path" | ||
| let path = Console.ReadLine () | ||
| try | ||
| let answer = PhoneBook.ReadFromFile path seq | ||
| printfn "Done!" | ||
| answer |> menu | ||
| with | ||
| | :? FileNotFoundException -> | ||
| printfn "File not found!" | ||
| menu seq | ||
| | :? ArgumentException -> | ||
| printfn "Something bad with file path" | ||
| menu seq | ||
| | _ -> | ||
| printfn "IO Exception!" | ||
| menu seq | ||
| | _ -> menu seq | ||
|
|
||
| printfn "Welcome to the PhoneBook!" | ||
| printfn "Press 1 to exit" | ||
| printfn "Press 2 to add data" | ||
| printfn "Press 3 to find number by name" | ||
| printfn "Press 4 to find name by number" | ||
| printfn "Press 5 to print all data" | ||
| printfn "Press 6 to save all data in file" | ||
| printfn "Press 7 to input data from file" | ||
| menu <| Seq.empty<string * string> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| module TestProject1 | ||
|
|
||
| open NUnit.Framework | ||
| open FsUnit | ||
| open PhoneBook | ||
|
|
||
| [<Test>] | ||
| let ``add test`` () = | ||
| let seq = PhoneBook.Add "Hello" "213-222-555" Seq.empty<string * string> | ||
| seq |> should contain ("Hello", "213-222-555") | ||
|
|
||
| [<Test>] | ||
| let ``add two equal test`` () = | ||
| let seq = Seq.empty<string * string> |> PhoneBook.Add "hey" "213-222-555" | ||
| |> PhoneBook.Add "hey" "213-222-555" | ||
| Seq.length seq |> should equal 1 | ||
|
|
||
| [<Test>] | ||
| let ``add two test`` () = | ||
| let seq = Seq.empty<string * string> |> PhoneBook.Add "Hello" "213-222-555" | ||
| |> PhoneBook.Add "hey" "213-222-556" | ||
| seq |> should contain ("Hello", "213-222-555") | ||
| seq |> should contain ("hey", "213-222-556") | ||
|
|
||
| [<Test>] | ||
| let ``search name test`` () = | ||
| let seq = Seq.empty<string * string> |> PhoneBook.Add "Hello" "213-222-555" | ||
| |> PhoneBook.Add "hey" "213-222-556" | ||
| let answer = PhoneBook.GetName "213-222-555" seq | ||
| Seq.length answer |> should equal 1 | ||
| Seq.contains ("Hello", "213-222-555") answer |> should equal true | ||
|
|
||
| [<Test>] | ||
| let ``search number test`` () = | ||
| let seq = Seq.empty<string * string> |> PhoneBook.Add "Hello" "213-222-555" | ||
| |> PhoneBook.Add "hey" "213-222-556" | ||
| let answer = PhoneBook.GetNumber "hey" seq | ||
| Seq.length answer |> should equal 1 | ||
| Seq.contains ("hey", "213-222-556") answer |> should equal true | ||
|
|
||
| [<Test>] | ||
| let ``search name test two matches`` () = | ||
| let seq = Seq.empty<string * string> |> PhoneBook.Add "Hello" "213-222-555" | ||
| |> PhoneBook.Add "hey" "213-222-556" | ||
| |> PhoneBook.Add "Hello again" "213-222-555" | ||
| let answer = PhoneBook.GetName "213-222-555" seq | ||
| Seq.length answer |> should equal 2 | ||
| Seq.contains ("Hello", "213-222-555") answer |> should equal true | ||
| Seq.contains ("Hello again", "213-222-555") answer |> should equal true | ||
|
|
||
| [<Test>] | ||
| let ``search number test two matches`` () = | ||
| let seq = Seq.empty<string * string> |> PhoneBook.Add "Ivan" "213-222-555" | ||
| |> PhoneBook.Add "Ivan" "213-222-556" | ||
| |> PhoneBook.Add "Ivan Ivanov" "213-222-555" | ||
| let answer = PhoneBook.GetNumber "Ivan" seq | ||
| Seq.length answer |> should equal 2 | ||
| Seq.contains ("Ivan", "213-222-555") answer |> should equal true | ||
| Seq.contains ("Ivan", "213-222-556") answer |> should equal true | ||
|
|
||
| [<Test>] | ||
| let ``read from file to empty sequence test`` () = | ||
| let data = PhoneBook.ReadFromFile "TestFile.txt" Seq.empty | ||
| Seq.contains ("Ivan", "111-222-333") data |> should equal true | ||
| Seq.contains ("Ivanov", "123-456-222") data |> should equal true | ||
|
|
||
| [<Test>] | ||
| let ``read from file to sequence test`` () = | ||
| let data = Seq.empty |> PhoneBook.Add "Badnames" "132-132-132"|> PhoneBook.ReadFromFile "TestFile.txt" | ||
| Seq.contains ("Ivan", "111-222-333") data |> should equal true | ||
| Seq.contains ("Badnames", "132-132-132") data |> should equal true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netcoreapp3.1</TargetFramework> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| <GenerateProgramFile>false</GenerateProgramFile> | ||
| <RootNamespace>TestProject1</RootNamespace> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="FsCheck" Version="3.0.0-alpha4" /> | ||
| <PackageReference Include="FsUnit" Version="4.0.1" /> | ||
| <PackageReference Include="nunit" Version="3.12.0" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="3.15.1" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="PhoneBookTest.fs" /> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\PhoneBook\PhoneBook.fsproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| module Program = let [<EntryPoint>] main _ = 0 |
2 changes: 2 additions & 0 deletions
2
semester4/PhoneBook/PhoneBookTests/bin/Debug/netcoreapp3.1/TestFile.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Ivan.....111-222-333 | ||
| Ivanov.....123-456-222 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тип с только статическими методами --- это же буквально модуль, модули именно в это и компилятся. Сделали б module PhoneBook = ... или, что то же самое, просто module PhoneBook в начале файла (как сейчас), и дальше просто функции как обычно