diff --git a/HW_6/HW_6.Tests/HW_6.Tests.fsproj b/HW_6/HW_6.Tests/HW_6.Tests.fsproj new file mode 100644 index 0000000..30302e3 --- /dev/null +++ b/HW_6/HW_6.Tests/HW_6.Tests.fsproj @@ -0,0 +1,34 @@ + + + + net7.0 + + false + false + true + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive +all + + runtime; build; native; contentfiles; analyzers; buildtransitive +all + + + + + + + + + + diff --git a/HW_6/HW_6.Tests/Program.fs b/HW_6/HW_6.Tests/Program.fs new file mode 100644 index 0000000..5da7e48 --- /dev/null +++ b/HW_6/HW_6.Tests/Program.fs @@ -0,0 +1,5 @@ +module Program = + + [] + let main _ = 0 + diff --git a/HW_6/HW_6.Tests/UnitTest.fs b/HW_6/HW_6.Tests/UnitTest.fs new file mode 100644 index 0000000..f612063 --- /dev/null +++ b/HW_6/HW_6.Tests/UnitTest.fs @@ -0,0 +1,55 @@ +module HW_6.Tests + +open NUnit.Framework +open FsUnit +open Calculator +open Rounder + +[] +let ``test both incorrect args`` () = + let calculator = new StringCalculatorBuilder() + calculator { + let! x = "a" + let! y = "b" + let result = x + y + return x + y + } |> should equal None + +[] +let ``test the first arg is incorrect`` () = + let calculator = new StringCalculatorBuilder() + calculator { + let! x = "a" + let! y = "3" + let result = x + y + return x + y + } |> should equal None + +[] +let ```test the second arg is incorrect`` () = + let calculator = new StringCalculatorBuilder() + calculator { + let! x = "3" + let! y = "b" + let result = x + y + return x + y + } |> should equal None + +[] +let ```test both args are correct`` () = + let calculator = new StringCalculatorBuilder() + calculator { + let! x = "3" + let! y = "5" + let result = x + y + return x + y + } |> should equal (Some 8) + +[] +let ```test rounder`` () = + let rounder = new RounderBuilder(3) + rounder { + let! a = 2.0 / 12.0 + let! b = 3.5 + return a / b + } |> should equal 0.048 \ No newline at end of file diff --git a/HW_6/HW_6.sln b/HW_6/HW_6.sln new file mode 100644 index 0000000..099e589 --- /dev/null +++ b/HW_6/HW_6.sln @@ -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}") = "HW_6", "HW_6\HW_6.fsproj", "{52EA7D0B-F67E-46E4-A1D3-2DD43F9C690A}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "HW_6.Tests", "HW_6.Tests\HW_6.Tests.fsproj", "{2140255C-4543-4BA8-9060-B81B47A780AF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {52EA7D0B-F67E-46E4-A1D3-2DD43F9C690A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52EA7D0B-F67E-46E4-A1D3-2DD43F9C690A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {52EA7D0B-F67E-46E4-A1D3-2DD43F9C690A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {52EA7D0B-F67E-46E4-A1D3-2DD43F9C690A}.Release|Any CPU.Build.0 = Release|Any CPU + {2140255C-4543-4BA8-9060-B81B47A780AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2140255C-4543-4BA8-9060-B81B47A780AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2140255C-4543-4BA8-9060-B81B47A780AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2140255C-4543-4BA8-9060-B81B47A780AF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3576E2CC-E843-417D-A205-E43F05928B38} + EndGlobalSection +EndGlobal diff --git a/HW_6/HW_6/HW_6.fsproj b/HW_6/HW_6/HW_6.fsproj new file mode 100644 index 0000000..91967f7 --- /dev/null +++ b/HW_6/HW_6/HW_6.fsproj @@ -0,0 +1,13 @@ + + + + net7.0 + true + + + + + + + + diff --git a/HW_6/HW_6/HW_6.sln b/HW_6/HW_6/HW_6.sln new file mode 100644 index 0000000..220c663 --- /dev/null +++ b/HW_6/HW_6/HW_6.sln @@ -0,0 +1,25 @@ + +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}") = "HW_6", "HW_6.fsproj", "{61E04143-50A6-4A38-B64A-F844D2D78067}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {61E04143-50A6-4A38-B64A-F844D2D78067}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {61E04143-50A6-4A38-B64A-F844D2D78067}.Debug|Any CPU.Build.0 = Debug|Any CPU + {61E04143-50A6-4A38-B64A-F844D2D78067}.Release|Any CPU.ActiveCfg = Release|Any CPU + {61E04143-50A6-4A38-B64A-F844D2D78067}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BAAC7CD5-B34F-4CA2-87E0-B62A951F39D7} + EndGlobalSection +EndGlobal diff --git a/HW_6/HW_6/RounderBuilder.fs b/HW_6/HW_6/RounderBuilder.fs new file mode 100644 index 0000000..670dd40 --- /dev/null +++ b/HW_6/HW_6/RounderBuilder.fs @@ -0,0 +1,9 @@ +module Rounder + +open System + +type RounderBuilder(accuracy : int) = + member this.Bind(x : float, func) = + func (Math.Round(x, accuracy)) + + member this.Return(x : float) = Math.Round(x, accuracy) \ No newline at end of file diff --git a/HW_6/HW_6/StringCalculatorBuilder.fs b/HW_6/HW_6/StringCalculatorBuilder.fs new file mode 100644 index 0000000..7a2b8e1 --- /dev/null +++ b/HW_6/HW_6/StringCalculatorBuilder.fs @@ -0,0 +1,11 @@ +module Calculator + +open System + +type StringCalculatorBuilder() = + member this.Bind(x : string, computation) = + match Int32.TryParse(x) with + | true, intX -> computation intX + | false, _ -> None + + member this.Return(x) = Some x \ No newline at end of file