-
Notifications
You must be signed in to change notification settings - Fork 0
Hw two #67
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
Hw-Two
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
Hw two #67
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/HomeworkTwo/HomeworkTwo.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,46 @@ | ||
| module HomeworkTwo.Tests.Counts | ||
|
|
||
| open FsUnit | ||
| open FsCheck | ||
| open Counts | ||
| open NUnit.Framework | ||
|
|
||
| let inputs = | ||
| [ | ||
| [1..10], 5 | ||
| [3], 0 | ||
| [2], 1 | ||
| [2; 4; 6; 8; 10], 5 | ||
| [1; 3; 5; 7; 9; 11; 13], 0 | ||
| [-1; 0; 1], 1 | ||
| [-2], 1 | ||
| [-4; -10; 241212], 3 | ||
| [], 0 | ||
| ] |> List.map (fun (list, result) -> TestCaseData(list, result)) | ||
|
|
||
| [<TestCaseSource("inputs")>] | ||
| [<Test>] | ||
| let filterTest list count = filterCount list |> should equal count | ||
|
|
||
| [<TestCaseSource("inputs")>] | ||
| [<Test>] | ||
| let foldTest list count = foldCount list |> should equal count | ||
|
|
||
| [<TestCaseSource("inputs")>] | ||
| [<Test>] | ||
| let mapTest list count = mapCount list |> should equal count | ||
|
|
||
| let filterEqualsMap list = filterCount list = mapCount list | ||
|
|
||
| let foldEqualsMap list = foldCount list = mapCount list | ||
|
|
||
| let filterEqualsFold list = filterCount list = foldCount list | ||
|
|
||
| [<Test>] | ||
| let ``filter equals map``() = Check.QuickThrowOnFailure filterEqualsMap | ||
|
|
||
| [<Test>] | ||
| let ``fold equals map``() = Check.QuickThrowOnFailure foldEqualsMap | ||
|
|
||
| [<Test>] | ||
| let ``filter equals fold``() = Check.QuickThrowOnFailure filterEqualsFold |
30 changes: 30 additions & 0 deletions
30
semester4/HomeworkTwo/HomeworkTwo.Tests/HomeworkTwo.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>netcoreapp3.1</TargetFramework> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| <GenerateProgramFile>false</GenerateProgramFile> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="FsCheck" Version="3.0.0-alpha4" /> | ||
| <PackageReference Include="FsUnit" Version="4.0.0" /> | ||
| <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="CountsTests.fs" /> | ||
| <Compile Include="TreeMapTests.fs" /> | ||
| <Compile Include="ParseTreeTests.fs" /> | ||
| <Compile Include="InfinitePrimeNumbersTests.fs" /> | ||
| <Compile Include="Program.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\HomeworkTwo\HomeworkTwo.fsproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
23 changes: 23 additions & 0 deletions
23
semester4/HomeworkTwo/HomeworkTwo.Tests/InfinitePrimeNumbersTests.fs
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,23 @@ | ||
| module HomeworkTwo.Tests.InfinitePrimeNumbersTests | ||
|
|
||
| open NUnit.Framework | ||
| open PrimeSequence | ||
| open FsUnit | ||
|
|
||
| let cases = | ||
| [ | ||
| 2, 0 | ||
| 3, 1 | ||
| 5, 2 | ||
| 7, 3 | ||
| 11, 4 | ||
| 13, 5 | ||
| 17, 6 | ||
| 19, 7 | ||
| 23, 8 | ||
| ] |> List.map (fun (number, pos) -> TestCaseData(number, pos)) | ||
|
|
||
| [<TestCaseSource("cases")>] | ||
| [<Test>] | ||
| let infinitePrimesTest number pos = | ||
| Seq.item(pos) primeSeq |> should equal number |
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 @@ | ||
| module HomeworkTwo.Tests.ParseTree_Tests | ||
|
|
||
| open NUnit.Framework | ||
| open FsUnit | ||
| open ParseTree | ||
|
|
||
| let cases = | ||
| [ | ||
| Sum(Digit(100), Digit(32)), 132 | ||
| Multiplication(Subtraction(Digit(50), Digit(3)), Digit(2)), 94 | ||
| Multiplication(Digit(5000), Digit(0)), 0 | ||
| Multiplication(Digit(5000), Digit(-1)), -5000 | ||
| Division(Digit(10), Digit(2)), 5 | ||
| Subtraction(Multiplication(Digit(13), Digit(5)), Division(Digit(25), Digit(5))), 60 | ||
| ] |> List.map (fun (tree, result) -> TestCaseData(tree, result)) | ||
|
|
||
|
|
||
| [<TestCaseSource("cases")>] | ||
| [<Test>] | ||
| let ``simple parse tree testes`` tree result = calculateTree tree |> should equal result | ||
|
|
||
| [<Test>] | ||
| let ``division by zero test`` () = | ||
| (fun () -> calculateTree (Division(Digit(10), Digit(0))) |> ignore) |> should throw typeof<System.DivideByZeroException> |
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 @@ | ||
| module Program | ||
| let [<EntryPoint>] 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,17 @@ | ||
| module HomeworkTwo.Tests.TreeMap | ||
|
|
||
| open NUnit.Framework | ||
| open FsUnit | ||
| open TreeMap | ||
|
|
||
| let intTree = (Node(5, Node(3, None, None), Node(0, Node(313, Tree.None, Tree.None), Tree.None))) | ||
| let intAnswer = (Node(10, Node(6, None, None), Node(0, Node(626, Tree.None, Tree.None), Tree.None))) | ||
|
|
||
| [<Test>] | ||
| let intTest () = mapTree (fun (x: int) -> (x * 2)) intTree |> should equal intAnswer | ||
|
|
||
| let stringTree = (Node("Hello", Node("World", Node("Another", Node("Word", Tree.None, Tree.None), Tree.None), Tree.None), Tree.None)) | ||
| let stringAnswer = (Node("Helloa", Node("Worlda", Node("Anothera", Node("Worda", Tree.None, Tree.None), Tree.None), Tree.None), Tree.None)) | ||
|
|
||
| [<Test>] | ||
| let stringTest () = mapTree (fun (x: string) -> x + "a") stringTree |> should equal stringAnswer |
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}") = "HomeworkTwo", "HomeworkTwo\HomeworkTwo.fsproj", "{0C6E1509-6286-49C0-8923-48C031618E87}" | ||
| EndProject | ||
| Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "HomeworkTwo.Tests", "HomeworkTwo.Tests\HomeworkTwo.Tests.fsproj", "{6AA3EB61-29BD-4819-BB4B-0DA0027156A6}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {0C6E1509-6286-49C0-8923-48C031618E87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {0C6E1509-6286-49C0-8923-48C031618E87}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {0C6E1509-6286-49C0-8923-48C031618E87}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {0C6E1509-6286-49C0-8923-48C031618E87}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {6AA3EB61-29BD-4819-BB4B-0DA0027156A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {6AA3EB61-29BD-4819-BB4B-0DA0027156A6}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {6AA3EB61-29BD-4819-BB4B-0DA0027156A6}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {6AA3EB61-29BD-4819-BB4B-0DA0027156A6}.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,13 @@ | ||
| module Counts | ||
|
|
||
| /// Count all even numbers with filter function | ||
| let filterCount list = | ||
| List.length <| List.filter (fun x -> x % 2 = 0) list | ||
|
|
||
| /// Count all even numbers with map function | ||
| let mapCount list = | ||
| List.sum <| List.map (fun x -> abs(x + 1) % 2) list | ||
|
|
||
| /// Count all even numbers with fold functions | ||
| let foldCount list = | ||
| List.fold (fun acc x -> (abs(x + 1) % 2) + acc) 0 list |
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,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netcoreapp3.1</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Count.fs" /> | ||
| <Compile Include="TreeMap.fs" /> | ||
| <Compile Include="ParseTree.fs" /> | ||
| <Compile Include="InfinitePrimeNumbers.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,11 @@ | ||
| module PrimeSequence | ||
|
|
||
| /// Checks if number is prime | ||
| let isPrime n = | ||
| if n < 2 then false | ||
| else | ||
| let searchEnd = (float >> sqrt >> int) n | ||
| List.forall (fun x -> n % x <> 0)([2..searchEnd]) | ||
|
|
||
| /// Creates infinity sequence of prime numbers | ||
| let primeSeq = (Seq.initInfinite id |> Seq.filter (isPrime)) |
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,20 @@ | ||
| module ParseTree | ||
|
|
||
| /// Simple parse tree | ||
| type ParseTree = | ||
| | Digit of int | ||
| | Sum of ParseTree * ParseTree | ||
| | Subtraction of ParseTree * ParseTree | ||
| | Multiplication of ParseTree * ParseTree | ||
| | Division of ParseTree * ParseTree | ||
|
|
||
| /// Function that calculates the result of parse tree | ||
| let rec calculateTree tree = | ||
| match tree with | ||
| | Digit x -> x | ||
| | Sum(l, r) -> calculateTree l + calculateTree r | ||
| | Subtraction(l, r) -> calculateTree l - calculateTree r | ||
| | Multiplication(l, r) -> calculateTree l * calculateTree r | ||
| | Division(l, r) -> let right = calculateTree r | ||
| if right = 0 then raise (System.DivideByZeroException()) | ||
| else (calculateTree l) / right |
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 @@ | ||
| module TreeMap | ||
|
|
||
| /// Simple binary tree | ||
| type Tree<'a> = | ||
| | Node of 'a * Tree<'a> * Tree<'a> | ||
| | None | ||
|
|
||
| /// Function that transforms tree with given function | ||
| let rec mapTree mapFunc tree = | ||
| match tree with | ||
| | None -> None | ||
| | Node(c, l, r) -> Node(mapFunc c, mapTree mapFunc l, mapTree mapFunc r) |
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.
Тут тоже, пустой main вполлне можно не писать, если собирать библиотеку