-
Notifications
You must be signed in to change notification settings - Fork 0
Hw 4 #4
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
AnNyiiik
wants to merge
16
commits into
main
Choose a base branch
from
HW_4
base: main
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
Hw 4 #4
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ee8bee5
added phone book
AnNyiiik 940ef26
added point free and brackets
AnNyiiik a8c21d8
added tests to phone book
AnNyiiik f9220bc
added new tests
AnNyiiik cb0b578
added tests to brackets
AnNyiiik f384b7a
changed
AnNyiiik dfdf154
added test cases
AnNyiiik 9aca942
added tests to point free
AnNyiiik 66078e7
changed book
AnNyiiik 1b58735
changed brackets checker
AnNyiiik baae483
changed point free
AnNyiiik 227519f
changed book
AnNyiiik 6ce9bab
add brackets
AnNyiiik 3e29bc1
changed phone book
AnNyiiik 289347e
changed
AnNyiiik 8d5090a
deleted exception
AnNyiiik 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 |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 16 | ||
| VisualStudioVersion = 25.0.1706.10 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Brackets", "Brackets\Brackets.fsproj", "{B26871CD-3266-4D15-A5D9-E56EF988A7EF}" | ||
| EndProject | ||
| Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "BracketsChecker.Tests", "BracketsChecker.Tests\BracketsChecker.Tests.fsproj", "{38386C22-13A1-4BFF-B58C-A23812F7FDD0}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {B26871CD-3266-4D15-A5D9-E56EF988A7EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {B26871CD-3266-4D15-A5D9-E56EF988A7EF}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {B26871CD-3266-4D15-A5D9-E56EF988A7EF}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {B26871CD-3266-4D15-A5D9-E56EF988A7EF}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {38386C22-13A1-4BFF-B58C-A23812F7FDD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {38386C22-13A1-4BFF-B58C-A23812F7FDD0}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {38386C22-13A1-4BFF-B58C-A23812F7FDD0}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {38386C22-13A1-4BFF-B58C-A23812F7FDD0}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {5AFD0F68-0793-4F4E-8C8D-6924AFE7632C} | ||
| 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,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| <GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="BracketsChecker.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,24 @@ | ||
| namespace Brackets | ||
|
|
||
| module Brackets = | ||
|
|
||
| let bracketPairs = Map['(', ')'; '{', '}'; '[', ']'] | ||
|
|
||
| let checkSequence (sequence : string) = | ||
| let rec checkRec (sequence : string) stack position counter = | ||
| if (position = sequence.Length) then if (counter = 0) then true else false | ||
|
|
||
| else | ||
| let bracket = sequence.[position] | ||
| if bracketPairs.ContainsKey bracket then | ||
| checkRec sequence (bracket :: stack) (position + 1) (counter + 1) | ||
| else | ||
| if (bracketPairs.Values.Contains bracket) then | ||
| match stack with | ||
| | [] -> false | ||
| | head :: tail -> | ||
| if (bracket = bracketPairs.[head]) then | ||
| checkRec sequence tail (position + 1) (counter - 1) | ||
| else false | ||
| else checkRec sequence stack (position + 1) counter | ||
| checkRec sequence [] 0 0 |
30 changes: 30 additions & 0 deletions
30
Brackets/BracketsChecker.Tests/BracketsChecker.Tests.fsproj
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,30 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| <GenerateProgramFile>false</GenerateProgramFile> | ||
| <IsTestProject>true</IsTestProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="UnitTest.fs" /> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
| <PackageReference Include="NUnit" Version="3.13.3" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="4.4.2" /> | ||
| <PackageReference Include="NUnit.Analyzers" Version="3.6.1" /> | ||
| <PackageReference Include="coverlet.collector" Version="3.2.0" /> | ||
| <PackageReference Include="FsUnit" Version="6.0.0"> | ||
| <GeneratePathProperty></GeneratePathProperty> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Brackets\Brackets.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,5 @@ | ||
| module Program = | ||
|
|
||
| [<EntryPoint>] | ||
| let main _ = 0 | ||
|
|
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,27 @@ | ||
| module BracketsChecker.Tests | ||
|
|
||
| open FsUnit | ||
| open NUnit.Framework | ||
| open Brackets.Brackets | ||
| let testCasesTrue = | ||
| seq { | ||
| yield (TestCaseData("[][{}([][(){()()}])]")) | ||
| } | ||
|
|
||
| let testCasesFalse = | ||
| seq { | ||
| yield (TestCaseData("[]{{}}}")) | ||
| yield (TestCaseData("[{(})]")) | ||
| yield (TestCaseData("))((")) | ||
| yield (TestCaseData(")")) | ||
| yield (TestCaseData("(")) | ||
| } | ||
| [<TestCaseSource("testCasesTrue")>] | ||
| let ``Test cases true`` (sequence : string) = | ||
| let res = checkSequence sequence | ||
| Assert.That(checkSequence sequence) | ||
|
|
||
| [<TestCaseSource("testCasesFalse")>] | ||
| let ``Test cases false`` (sequence : string) = | ||
| let res = checkSequence sequence | ||
| Assert.That(not (checkSequence sequence)) | ||
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,35 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| <GenerateProgramFile>false</GenerateProgramFile> | ||
| <IsTestProject>true</IsTestProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="UnitTests.fs" /> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
| <PackageReference Include="NUnit" Version="4.1.0" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="4.5.0" /> | ||
| <PackageReference Include="NUnit.Analyzers" Version="4.1.0"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="coverlet.collector" Version="3.2.0" /> | ||
| <PackageReference Include="FsUnit" Version="6.0.0"> | ||
| <GeneratePathProperty></GeneratePathProperty> | ||
| </PackageReference> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\PhoneBook\PhoneBook.fsproj" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <None Include="readTest.txt" /> | ||
| </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,5 @@ | ||
| module Program = | ||
|
|
||
| [<EntryPoint>] | ||
| let main _ = 0 | ||
|
|
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,55 @@ | ||
| module PhoneBookTests | ||
|
|
||
| open FsUnit | ||
| open NUnit.Framework | ||
| open PhoneBook.PhoneBook | ||
|
|
||
| let data = | ||
| [ | ||
| {Name = "Tom"; Number = "89019892909"}; | ||
| {Name = "Alice"; Number = "83890198101"}; | ||
| {Name = "John"; Number = "82839281789"}; | ||
| {Name = "Bob"; Number = "+72898271890"}; | ||
| {Name = "Hanna"; Number = "+71289019813"}; | ||
| {Name = "Sara"; Number = "81278918789"} | ||
| ] | ||
|
|
||
| let comparePersons (p1 : Person) (p2 : Person) = | ||
| if p1 < p2 then -1 else | ||
| if p1 = p2 then | ||
| if p1 < p2 then -1 | ||
| else 1 | ||
| else 1 | ||
|
|
||
| [<Test>] | ||
| let ``test add record basic`` () = | ||
| let person = {Name = "Julia"; Number = "+79110606382"} | ||
| let newData = fst (addRecord person data) | ||
| let correctResult = List.sortWith comparePersons [{Name = "Tom"; Number = "89019892909"}; | ||
| {Name = "Alice"; Number = "83890198101"}; | ||
| {Name = "John"; Number = "82839281789"}; | ||
| {Name = "Bob"; Number = "+72898271890"}; | ||
| {Name = "Hanna"; Number = "+71289019813"}; | ||
| {Name = "Sara"; Number = "81278918789"}; | ||
| {Name = "Julia"; Number = "+79110606382"}] | ||
| let actual = List.sortWith comparePersons newData | ||
| Assert.That(actual, Is.EqualTo(correctResult)) | ||
|
|
||
| [<Test>] | ||
| let ``test find name by phone`` () = | ||
| (findByPhone "82839281789" data).Value |> should equal "John" | ||
| findByPhone "82839281780" data |> should equal None | ||
|
|
||
| [<Test>] | ||
| let ``test find name by name`` () = | ||
| (findByName "Sara" data).Value |> should equal "81278918789" | ||
| findByName "Kat" data |> should equal None | ||
|
|
||
| [<Test>] | ||
| let ``test read from file`` () = | ||
| let dataWrite = "Tom 89019892909\nAlice 83890198101\nJohn 82839281789\nBob +72898271890\nHanna +71289019813\nSara 81278918789" | ||
| let dataEmpty = [] | ||
| match fill dataWrite dataEmpty with | ||
| | None -> Assert.Fail() | ||
| | Some data -> | ||
| List.sortWith comparePersons data |> should equal (List.sortWith comparePersons data) |
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,6 @@ | ||
| Tom 89019892909 | ||
| Alice 83890198101 | ||
| John 82839281789 | ||
| Bob +72898271890 | ||
| Hanna +71289019813 | ||
| Sara 81278918789 |
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,31 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 16 | ||
| VisualStudioVersion = 25.0.1706.10 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PhoneBook", "PhoneBook\PhoneBook.fsproj", "{6505FB31-C578-46DB-BA5D-4EC7EE43949E}" | ||
| EndProject | ||
| Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PhoneBook.Tests", "PhoneBook.Tests\PhoneBook.Tests.fsproj", "{ECE029B1-5E76-4E6D-B1D3-A810FCA77DA6}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {6505FB31-C578-46DB-BA5D-4EC7EE43949E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {6505FB31-C578-46DB-BA5D-4EC7EE43949E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {6505FB31-C578-46DB-BA5D-4EC7EE43949E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {6505FB31-C578-46DB-BA5D-4EC7EE43949E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {ECE029B1-5E76-4E6D-B1D3-A810FCA77DA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {ECE029B1-5E76-4E6D-B1D3-A810FCA77DA6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {ECE029B1-5E76-4E6D-B1D3-A810FCA77DA6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {ECE029B1-5E76-4E6D-B1D3-A810FCA77DA6}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {977DFA75-7185-40AB-8D5A-13BB914B801E} | ||
| 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,55 @@ | ||||||
| namespace PhoneBook | ||||||
|
|
||||||
| open System.Text.RegularExpressions | ||||||
|
|
||||||
| module PhoneBook = | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Я бы ещё сказал, что надо комментарии |
||||||
|
|
||||||
| type Person = { Name: string; Number: string } | ||||||
|
|
||||||
| let phoneRegex () = Regex(@"(\+7|7|8)+\d{10}", RegexOptions.Compiled) | ||||||
| let nameRegex () = Regex(@"[A-Z][a-z]+", RegexOptions.Compiled) | ||||||
|
|
||||||
| ///Add new record to the data | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| let addRecord (person : Person) data = | ||||||
| if List.exists(fun (p : Person) -> p.Number = person.Number) data | ||||||
| then | ||||||
| (data, None) | ||||||
| else (person :: data, Some 1) | ||||||
|
|
||||||
| ///Find by phone a name of a person | ||||||
| let findByPhone phone data = | ||||||
| let result = List.tryFind(fun (p : Person) -> p.Number = phone) data | ||||||
|
|
||||||
| match result with | ||||||
| | Some p -> Some p.Name | ||||||
| | None -> None | ||||||
|
|
||||||
| ///Find a phone by name | ||||||
| let findByName name data = | ||||||
| let result = List.tryFind(fun (p : Person) -> p.Name = name) data | ||||||
|
|
||||||
| match result with | ||||||
| | Some p -> Some p.Number | ||||||
| | None -> None | ||||||
|
|
||||||
| ///Convert all the data to string | ||||||
| let convertDataToString data = | ||||||
| data | ||||||
| |> List.fold (fun acc person -> | ||||||
| acc + $"{person.Name} {person.Number}\n") "" | ||||||
|
|
||||||
| ///Parse data from string and create list of records | ||||||
| let fill (personsString : string) data = | ||||||
|
|
||||||
| let persons = personsString.Split('\n') | ||||||
| let rec addPersons (persons : list<string>) data = | ||||||
| match persons with | ||||||
| | [] -> Some data | ||||||
| | head :: tail -> | ||||||
| let personData = (head.ToString()).Split([|' '|]) | ||||||
| let newPerson = {Name = personData.[0]; Number = personData.[1]} | ||||||
| if not (phoneRegex().IsMatch(personData.[1]) && nameRegex().IsMatch(personData.[0])) then | ||||||
| None | ||||||
| else if (personData.Length) = 2 then addPersons tail (newPerson :: data) | ||||||
| else None | ||||||
| addPersons (Seq.toList persons) data | ||||||
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,21 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="PhoneBook.fs" /> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Include="dataWrite.txt"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| <None Include="dataRead.txt"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
| </Project> |
Oops, something went wrong.
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.
нужны тесты на "", ")", "("