From 407befd6e0d60eb54ca8cbfc4f5373f63fd1c518 Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Tue, 26 Apr 2022 01:33:20 +0300 Subject: [PATCH 1/3] workflow --- Workflow/Workflow.Test/Program.fs | 4 ++ Workflow/Workflow.Test/Workflow.Test.fsproj | 27 +++++++++++ Workflow/Workflow.Test/WorkflowTest.fs | 51 +++++++++++++++++++++ Workflow/Workflow.sln | 22 +++++++++ Workflow/Workflow/Program.fs | 18 ++++++++ Workflow/Workflow/Workflow.fsproj | 13 ++++++ 6 files changed, 135 insertions(+) create mode 100644 Workflow/Workflow.Test/Program.fs create mode 100644 Workflow/Workflow.Test/Workflow.Test.fsproj create mode 100644 Workflow/Workflow.Test/WorkflowTest.fs create mode 100644 Workflow/Workflow.sln create mode 100644 Workflow/Workflow/Program.fs create mode 100644 Workflow/Workflow/Workflow.fsproj diff --git a/Workflow/Workflow.Test/Program.fs b/Workflow/Workflow.Test/Program.fs new file mode 100644 index 0000000..176a7b6 --- /dev/null +++ b/Workflow/Workflow.Test/Program.fs @@ -0,0 +1,4 @@ +module Program = + + [] + let main _ = 0 diff --git a/Workflow/Workflow.Test/Workflow.Test.fsproj b/Workflow/Workflow.Test/Workflow.Test.fsproj new file mode 100644 index 0000000..769bb1f --- /dev/null +++ b/Workflow/Workflow.Test/Workflow.Test.fsproj @@ -0,0 +1,27 @@ + + + + net6.0 + + false + false + + + + + + + + + + + + + + + + + + + + diff --git a/Workflow/Workflow.Test/WorkflowTest.fs b/Workflow/Workflow.Test/WorkflowTest.fs new file mode 100644 index 0000000..c68edec --- /dev/null +++ b/Workflow/Workflow.Test/WorkflowTest.fs @@ -0,0 +1,51 @@ +module Workflow.Test + +open System +open NUnit.Framework +open FsUnit +open Program + +[] +let RoundTest () = + let rounding i = new RoundBuilder(i) + let result = + rounding 3 { + let! a = 2.0 / 12.0 + let! b = 3.5 + return a / b + } + result |> should equal 0.048 + +[] +let RoundTestWithException () = + let rounding i = new RoundBuilder(i) + (fun() -> + rounding -1 { + let! a = 2.0 / 12.0 + let! b = 3.5 + return a / b + } |> ignore) |> should throw typeof + +[] +let CalculateTest () = + let calculate = new CalculateBuilder() + let result = + calculate { + let! a = "1" + let! b = "3" + let z = a + b + return z + } + result |> should equal (Some 4) + +[] +let CalculateTestIncorrect () = + let calculate = new CalculateBuilder() + let result = + calculate { + let! a = "1" + let! b = "." + let z = a + b + return z + } + result |> should equal None \ No newline at end of file diff --git a/Workflow/Workflow.sln b/Workflow/Workflow.sln new file mode 100644 index 0000000..367eef9 --- /dev/null +++ b/Workflow/Workflow.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Workflow", "Workflow\Workflow.fsproj", "{A6036D48-D2F8-46B8-9DEE-AB17878E8806}" +EndProject +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Workflow.Test", "Workflow.Test\Workflow.Test.fsproj", "{92E2C706-313D-4973-B32E-5BE88E2980CB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A6036D48-D2F8-46B8-9DEE-AB17878E8806}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6036D48-D2F8-46B8-9DEE-AB17878E8806}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6036D48-D2F8-46B8-9DEE-AB17878E8806}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A6036D48-D2F8-46B8-9DEE-AB17878E8806}.Release|Any CPU.Build.0 = Release|Any CPU + {92E2C706-313D-4973-B32E-5BE88E2980CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {92E2C706-313D-4973-B32E-5BE88E2980CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {92E2C706-313D-4973-B32E-5BE88E2980CB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {92E2C706-313D-4973-B32E-5BE88E2980CB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Workflow/Workflow/Program.fs b/Workflow/Workflow/Program.fs new file mode 100644 index 0000000..cff6a55 --- /dev/null +++ b/Workflow/Workflow/Program.fs @@ -0,0 +1,18 @@ +open System + + +type RoundBuilder(i) = + let debug (x : float) (i : int) = Math.Round(x, i) + member this.Bind(x, f) = + f (debug x i) + member this.Return(x : float) = Math.Round(x, i) + +type CalculateBuilder() = + member this.Bind(x : string, f) = + try + match Int32.TryParse x with + | true, x -> f x + | false, x -> raise(ArgumentException()) + with + | :? ArgumentException -> None + member this.Return(x) = Some x \ No newline at end of file diff --git a/Workflow/Workflow/Workflow.fsproj b/Workflow/Workflow/Workflow.fsproj new file mode 100644 index 0000000..761405f --- /dev/null +++ b/Workflow/Workflow/Workflow.fsproj @@ -0,0 +1,13 @@ + + + + Exe + net6.0 + Windows + + + + + + + From 405660b30d4a571be4af1a66d210329d44a52dca Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Thu, 28 Apr 2022 23:58:46 +0300 Subject: [PATCH 2/3] delete test --- Workflow/Workflow.Test/WorkflowTest.fs | 11 ----------- Workflow/Workflow/Program.fs | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/Workflow/Workflow.Test/WorkflowTest.fs b/Workflow/Workflow.Test/WorkflowTest.fs index c68edec..b2f79f5 100644 --- a/Workflow/Workflow.Test/WorkflowTest.fs +++ b/Workflow/Workflow.Test/WorkflowTest.fs @@ -1,6 +1,5 @@ module Workflow.Test -open System open NUnit.Framework open FsUnit open Program @@ -16,16 +15,6 @@ let RoundTest () = } result |> should equal 0.048 -[] -let RoundTestWithException () = - let rounding i = new RoundBuilder(i) - (fun() -> - rounding -1 { - let! a = 2.0 / 12.0 - let! b = 3.5 - return a / b - } |> ignore) |> should throw typeof - [] let CalculateTest () = let calculate = new CalculateBuilder() diff --git a/Workflow/Workflow/Program.fs b/Workflow/Workflow/Program.fs index cff6a55..f1b7152 100644 --- a/Workflow/Workflow/Program.fs +++ b/Workflow/Workflow/Program.fs @@ -12,7 +12,7 @@ type CalculateBuilder() = try match Int32.TryParse x with | true, x -> f x - | false, x -> raise(ArgumentException()) + | false, _ -> raise(ArgumentException()) with | :? ArgumentException -> None member this.Return(x) = Some x \ No newline at end of file From e816abccb031e86cacb31068e8af7bb925a5e1c0 Mon Sep 17 00:00:00 2001 From: MikePuzanov Date: Tue, 17 May 2022 22:48:27 +0300 Subject: [PATCH 3/3] fix and add test --- Workflow/Workflow.Test/WorkflowTest.fs | 12 +++++++++++- Workflow/Workflow/Program.fs | 16 ++++++---------- Workflow/Workflow/Workflow.fsproj | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Workflow/Workflow.Test/WorkflowTest.fs b/Workflow/Workflow.Test/WorkflowTest.fs index b2f79f5..d9af79f 100644 --- a/Workflow/Workflow.Test/WorkflowTest.fs +++ b/Workflow/Workflow.Test/WorkflowTest.fs @@ -1,8 +1,9 @@ module Workflow.Test +open System open NUnit.Framework open FsUnit -open Program +open Workflows [] let RoundTest () = @@ -15,6 +16,15 @@ let RoundTest () = } result |> should equal 0.048 +[] +let RoundWithTest () = + (fun () -> + RoundBuilder.rounding -3 { + let! a = 2.0 / 12.0 + let! b = 3.5 + return a / b + } |> ignore) |> should throw typeof + [] let CalculateTest () = let calculate = new CalculateBuilder() diff --git a/Workflow/Workflow/Program.fs b/Workflow/Workflow/Program.fs index f1b7152..e533ba5 100644 --- a/Workflow/Workflow/Program.fs +++ b/Workflow/Workflow/Program.fs @@ -1,18 +1,14 @@ +module Workflows open System - -type RoundBuilder(i) = - let debug (x : float) (i : int) = Math.Round(x, i) - member this.Bind(x, f) = - f (debug x i) - member this.Return(x : float) = Math.Round(x, i) +type RoundBuilder(i : int) = + static member rounding = RoundBuilder + member this.Bind(x: float, f) = f (Math.Round(x, i)) + member this.Return(x: float) = Math.Round(x, i) type CalculateBuilder() = member this.Bind(x : string, f) = - try match Int32.TryParse x with | true, x -> f x - | false, _ -> raise(ArgumentException()) - with - | :? ArgumentException -> None + | false, _ -> None member this.Return(x) = Some x \ No newline at end of file diff --git a/Workflow/Workflow/Workflow.fsproj b/Workflow/Workflow/Workflow.fsproj index 761405f..525d1e6 100644 --- a/Workflow/Workflow/Workflow.fsproj +++ b/Workflow/Workflow/Workflow.fsproj @@ -1,9 +1,9 @@  - Exe net6.0 Windows + Exe