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
29 changes: 29 additions & 0 deletions F#/Workflows.Test/Workflows.Test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<GenerateProgramFile>true</GenerateProgramFile>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<Compile Include="WorkflowsTest.fs" />

</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="FsUnit" Version="6.0.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

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

</Project>
29 changes: 29 additions & 0 deletions F#/Workflows.Test/WorkflowsTest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Workflows.Test

open NUnit.Framework
open FsUnit

[<Test>]
let roundingTest () =
rounding 3 {
let! a = 2.0 / 12.0
let! b = 3.5
return a / b
} |> should equal 0.048

[<Test>]
let stringCalcTest () =
calculate {
let! a = "1"
let! b = "2"
return a + b
} |> should equal (Some(3))

[<Test>]
let stringIncorrectCalcTest () =
calculate {
let! a = "1"
let! b = "a"
let z = a + b
return z
} |> should equal None
31 changes: 31 additions & 0 deletions F#/Workflows/Workflows.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Workflows

/// <summary>
/// Rounding to a precision workflow builder
/// </summary>
/// <param name="prec"> Workflow precision </param>
type RoundingBuilder(prec: int) =
member this.Bind(x: float, f) =
f (System.Math.Round(x, prec))
member this.Return(x: float) = System.Math.Round(x, prec)

/// <summary>
/// Builds rounding to a precision workflow
/// </summary>
let rounding = RoundingBuilder

/// <summary>
/// String calculation workflow builder
/// </summary>
type StringCalculateBuilder() =
member this.Bind(x: string, f) =
let res = 0
let parsed = System.Int32.TryParse(x, ref res)
if parsed then Some(res) else None
member this.Return(x: int) = Some(x)


/// <summary>
/// Build string calculation workflow
/// </summary>
let calculate = StringCalculateBuilder()
12 changes: 12 additions & 0 deletions F#/Workflows/Workflows.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="Workflows.fs" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions F#/forSpbu.sln
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "07.03", "07.03", "{5CA9053B
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Homework1", "Homework1\Homework1.fsproj", "{04B15EE4-079A-42ED-ACC8-E2DCD25281C6}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Workflows", "Workflows\Workflows.fsproj", "{C69807AF-66FC-4C75-811D-FA1242A2219E}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Workflows.Test", "Workflows.Test\Workflows.Test.fsproj", "{94AE559A-A34E-42F2-8C59-F486247239EA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -58,6 +62,14 @@ Global
{89A935E8-B5F3-435D-ACC3-A99DD7C66178}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89A935E8-B5F3-435D-ACC3-A99DD7C66178}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89A935E8-B5F3-435D-ACC3-A99DD7C66178}.Release|Any CPU.Build.0 = Release|Any CPU
{C69807AF-66FC-4C75-811D-FA1242A2219E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C69807AF-66FC-4C75-811D-FA1242A2219E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C69807AF-66FC-4C75-811D-FA1242A2219E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C69807AF-66FC-4C75-811D-FA1242A2219E}.Release|Any CPU.Build.0 = Release|Any CPU
{94AE559A-A34E-42F2-8C59-F486247239EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94AE559A-A34E-42F2-8C59-F486247239EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94AE559A-A34E-42F2-8C59-F486247239EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94AE559A-A34E-42F2-8C59-F486247239EA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7937CDA8-8285-4E23-AD1A-FC0F04FEEFE6} = {91E3BDA2-0836-46C2-95F0-02513FD7F13F}
Expand Down