diff --git a/appveyor.yml b/appveyor.yml index 855f34f..a6edfb8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,17 @@ -image: Visual Studio 2017 +image: Visual Studio 2019 + +init: + - git config --global core.autocrlf true + +environment: + matrix: + - solution: Semester4/Workflows/Workflows.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% diff --git a/semester4/Workflows/Workflows.Tests/Program.fs b/semester4/Workflows/Workflows.Tests/Program.fs new file mode 100644 index 0000000..0695f84 --- /dev/null +++ b/semester4/Workflows/Workflows.Tests/Program.fs @@ -0,0 +1 @@ +module Program = let [] main _ = 0 diff --git a/semester4/Workflows/Workflows.Tests/RoundWorkflowTest.fs b/semester4/Workflows/Workflows.Tests/RoundWorkflowTest.fs new file mode 100644 index 0000000..8b9400f --- /dev/null +++ b/semester4/Workflows/Workflows.Tests/RoundWorkflowTest.fs @@ -0,0 +1,68 @@ +module Workflows.Tests + +open NUnit.Framework +open FsUnit +open RoundWorkflow + + + +[] +let ``zero accuracy test`` () = + let workflow = RoundResultBuilder(0) + workflow { + let! a = 1.0 * 1.5 + let! b = 1.5 * 5.0 + let! c = b / a + return c + } |> should equal 4 + +[] +let ``one digit accuracy test `` () = + let workflow = RoundResultBuilder(1) + workflow { + let! a = 2.5 * 5.0 + return a + } |> should equal 12.5 + +[] +let ``two digit accuracy test`` () = + let workflow = RoundResultBuilder(2) + workflow { + let! a = 1.5 * 1.5 + let! b = 1.1 * 1.4 + let! c = a / b + return c + } |> should equal 1.46 + +[] +let ``three digits accuracy test`` () = + let workflow = RoundResultBuilder(3) + workflow { + let! a = 1.5 * 1.5 + let! b = 1.1 * 1.4 + let! c = 1.25 * 2.54 + let! d = 32.3421 / 7.1224 + let! e = a + c * (b / d) + return e + } |> should (equalWithin 0.0001) 3.327 + +[] +let ``four digits accuracy test`` () = + let workflow = RoundResultBuilder(4) + workflow { + let! a = 1.111 * 1.5 + let! b = 1.1 / 2.345 + let! c = 1.25 + 2.54 + let! d = 32.3421 / 7.1224 + let! e = a * c - (b / d) + return e + } |> should (equalWithin 0.00001) 6.2127 + +[] +let ``example test`` () = + let workflow = RoundResultBuilder(3) + workflow { + let! a = 2.0 / 12.0 + let! b = 3.5 + return a / b + } |> should (equalWithin 0.0001) 0.048 \ No newline at end of file diff --git a/semester4/Workflows/Workflows.Tests/StringWorkflowTests.fs b/semester4/Workflows/Workflows.Tests/StringWorkflowTests.fs new file mode 100644 index 0000000..533041a --- /dev/null +++ b/semester4/Workflows/Workflows.Tests/StringWorkflowTests.fs @@ -0,0 +1,72 @@ +module StringWorkflowTests + +open NUnit.Framework +open FsUnit +open StringWorkflow + +let workflow = StringBuilder() + +[] +let ``simple plus test`` () = + workflow { + let! a = "5" + let! b = "2" + let c = a + b + return c + } |> should equal (Some(7)) + +[] +let ``simple multiply test`` ()= + workflow { + let! a = "3" + let! b = "15" + let c = b * a + return c + } |> should equal (Some(45)) + +[] +let ``simple test`` () = + workflow { + let! a = "3" + let! b = "15" + let! c = "2" + let d = c * b + let e = d / a + return e + } |> should equal (Some(10)) + +[] +let ``simple subtraction test`` () = + workflow { + let! a = "3" + let! b = "15" + let c = b - a + return c + } |> should equal (Some(12)) + +[] +let ``simple division test`` () = + workflow { + let! a = "3" + let! b = "15" + let c = b / a + return c + } |> should equal (Some(5)) + +[] +let ``one word test`` () = + workflow { + let! a = "3" + let! b = "isword" + let c = a + b + return c + } |> should equal None + +[] +let ``two words test`` () = + workflow { + let! a = "mmhmhmh" + let! b = "isword" + let c = a / b + return c + } |> should equal None \ No newline at end of file diff --git a/semester4/Workflows/Workflows.Tests/Workflows.Tests.fsproj b/semester4/Workflows/Workflows.Tests/Workflows.Tests.fsproj new file mode 100644 index 0000000..0b9059d --- /dev/null +++ b/semester4/Workflows/Workflows.Tests/Workflows.Tests.fsproj @@ -0,0 +1,27 @@ + + + + netcoreapp3.1 + + false + false + + + + + + + + + + + + + + + + + + + + diff --git a/semester4/Workflows/Workflows.sln b/semester4/Workflows/Workflows.sln new file mode 100644 index 0000000..d58b492 --- /dev/null +++ b/semester4/Workflows/Workflows.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Workflows", "Workflows\Workflows.fsproj", "{5AF0A1D8-0BFE-4046-B410-F7D147EF368B}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Workflows.Tests", "Workflows.Tests\Workflows.Tests.fsproj", "{D70FC128-7397-4ABC-9E14-69BFC7C044CA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5AF0A1D8-0BFE-4046-B410-F7D147EF368B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5AF0A1D8-0BFE-4046-B410-F7D147EF368B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5AF0A1D8-0BFE-4046-B410-F7D147EF368B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5AF0A1D8-0BFE-4046-B410-F7D147EF368B}.Release|Any CPU.Build.0 = Release|Any CPU + {D70FC128-7397-4ABC-9E14-69BFC7C044CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D70FC128-7397-4ABC-9E14-69BFC7C044CA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D70FC128-7397-4ABC-9E14-69BFC7C044CA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D70FC128-7397-4ABC-9E14-69BFC7C044CA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/semester4/Workflows/Workflows/RoundWorkflow.fs b/semester4/Workflows/Workflows/RoundWorkflow.fs new file mode 100644 index 0000000..0d67b37 --- /dev/null +++ b/semester4/Workflows/Workflows/RoundWorkflow.fs @@ -0,0 +1,10 @@ +module RoundWorkflow + +open System + +/// Workflow witch calculates expression and rounding its result +type RoundResultBuilder(accuracy : int) = + member this.Bind(x : float, f) = + Math.Round(x, accuracy) |> f + member this.Return(x : float) = + Math.Round(x, accuracy) \ No newline at end of file diff --git a/semester4/Workflows/Workflows/StringWorkflow.fs b/semester4/Workflows/Workflows/StringWorkflow.fs new file mode 100644 index 0000000..387b259 --- /dev/null +++ b/semester4/Workflows/Workflows/StringWorkflow.fs @@ -0,0 +1,12 @@ +module StringWorkflow + +open System + +/// Workflow witch calculates expression with string numbers +type StringBuilder() = + member this.Bind(x : string, f) = + match Int32.TryParse(x) with + | true, number -> number |> f + | _ -> None + member this.Return(x) = + Some(x) \ No newline at end of file diff --git a/semester4/Workflows/Workflows/Workflows.fsproj b/semester4/Workflows/Workflows/Workflows.fsproj new file mode 100644 index 0000000..7c42bb2 --- /dev/null +++ b/semester4/Workflows/Workflows/Workflows.fsproj @@ -0,0 +1,12 @@ + + + + netcoreapp3.1 + + + + + + + +