Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
module CalculateStringsTests

open NUnit.Framework
open CalculateStrings
open FsUnit

let testCase1 =
[
"1", "2", "3"
"2", "1", "3"
"123", "0", "123"
"0", "753", "753"
"�", "2", "None"
"b", "0", "None"
"c", "12a", "None"
"123r", "17", "None"
"154", "307", "461"
] |> List.map (fun (op1, op2, result) -> TestCaseData(op1, op2, result))

let testCase2 =
[
"1", "2", "-1"
"2", "1", "1"
"123", "0", "123"
"0", "753", "-753"
"�", "2", "None"
"b", "0", "None"
"c", "12a", "None"
"123r", "17", "None"
"154", "307", "-153"
] |> List.map (fun (op1, op2, result) -> TestCaseData(op1, op2, result))

let testCase3 =
[
"1", "2", "0"
"2", "1", "2"
"123", "1", "123"
"0", "753", "0"
"�", "2", "None"
"b", "0", "None"
"c", "12a", "None"
"123r", "17", "None"
"150", "10", "15"
] |> List.map (fun (op1, op2, result) -> TestCaseData(op1, op2, result))

let testCase4 =
[
"1", "2", "2"
"2", "1", "2"
"123", "2", "246"
"0", "753", "0"
"�", "2", "None"
"b", "0", "None"
"c", "12a", "None"
"123r", "17", "None"
"150", "10", "1500"
] |> List.map (fun (op1, op2, result) -> TestCaseData(op1, op2, result))

let calculate = new CalculateBuilder()

let calcRes f op1 op2 = calculate {
let! x = op1
let! y = op2
let z = f x y
return z
}

[<Test>]
[<TestCaseSource("testCase1")>]
let ``Tests adds correctly`` op1 op2 result =
calcRes (+) op1 op2 |> should equal result

[<Test>]
[<TestCaseSource("testCase2")>]
let ``Tests subtracts correctly`` op1 op2 result =
calcRes (-) op1 op2 |> should equal result

[<Test>]
[<TestCaseSource("testCase3")>]
let ``Tests divides correctly`` op1 op2 result =
calcRes (/) op1 op2 |> should equal result

[<Test>]
[<TestCaseSource("testCase4")>]
let ``Tests mutiplies correctly`` op1 op2 result =
calcRes (*) op1 op2 |> should equal result
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FsUnit" Version="3.8.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
</ItemGroup>

<ItemGroup>
<Compile Include="CalculateStringsTests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\WorkflowCalculateStrings\WorkflowCalculateStrings.fsproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.7.2" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Program = let [<EntryPoint>] main _ = 0
31 changes: 31 additions & 0 deletions hw6/WorkflowCalculateStrings/WorkflowCalculateStrings.sln
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 = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "WorkflowCalculateStrings", "WorkflowCalculateStrings\WorkflowCalculateStrings.fsproj", "{00B86A55-0A4D-4505-9389-2625B1A8468D}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "CalculateStringsTests", "CalculateStringsTests\CalculateStringsTests.fsproj", "{46E3D343-2EC6-4A11-9BD3-52CE5AB9B8BA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{00B86A55-0A4D-4505-9389-2625B1A8468D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00B86A55-0A4D-4505-9389-2625B1A8468D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00B86A55-0A4D-4505-9389-2625B1A8468D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{00B86A55-0A4D-4505-9389-2625B1A8468D}.Release|Any CPU.Build.0 = Release|Any CPU
{46E3D343-2EC6-4A11-9BD3-52CE5AB9B8BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{46E3D343-2EC6-4A11-9BD3-52CE5AB9B8BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46E3D343-2EC6-4A11-9BD3-52CE5AB9B8BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46E3D343-2EC6-4A11-9BD3-52CE5AB9B8BA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {631AB5C8-71E1-48E4-A386-38072C4492F4}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module CalculateStrings

open System

/// Implements interface letting calculate strings of integer numbers.
type CalculateBuilder() =
member this.Bind(x : string, f) =
match System.Int32.TryParse x with
| (true, number) -> (f number).ToString()
| _ -> "None"

member this.Return(x) = x
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Program

let main argv =

0
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
<Compile Include="CalculateStrings.fs" />
</ItemGroup>

</Project>