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
16 changes: 13 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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%
1 change: 1 addition & 0 deletions semester4/Workflows/Workflows.Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Program = let [<EntryPoint>] main _ = 0
68 changes: 68 additions & 0 deletions semester4/Workflows/Workflows.Tests/RoundWorkflowTest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module Workflows.Tests

open NUnit.Framework
open FsUnit
open RoundWorkflow



[<Test>]
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

[<Test>]
let ``one digit accuracy test `` () =
let workflow = RoundResultBuilder(1)
workflow {
let! a = 2.5 * 5.0
return a
} |> should equal 12.5

[<Test>]
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ниже equalWithin, а тут почему-то вещественные числа точно сравниваются


[<Test>]
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

[<Test>]
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

[<Test>]
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
72 changes: 72 additions & 0 deletions semester4/Workflows/Workflows.Tests/StringWorkflowTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module StringWorkflowTests

open NUnit.Framework
open FsUnit
open StringWorkflow

let workflow = StringBuilder()

[<Test>]
let ``simple plus test`` () =
workflow {
let! a = "5"
let! b = "2"
let c = a + b
return c
} |> should equal (Some(7))

[<Test>]
let ``simple multiply test`` ()=
workflow {
let! a = "3"
let! b = "15"
let c = b * a
return c
} |> should equal (Some(45))

[<Test>]
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))

[<Test>]
let ``simple subtraction test`` () =
workflow {
let! a = "3"
let! b = "15"
let c = b - a
return c
} |> should equal (Some(12))

[<Test>]
let ``simple division test`` () =
workflow {
let! a = "3"
let! b = "15"
let c = b / a
return c
} |> should equal (Some(5))

[<Test>]
let ``one word test`` () =
workflow {
let! a = "3"
let! b = "isword"
let c = a + b
return c
} |> should equal None

[<Test>]
let ``two words test`` () =
workflow {
let! a = "mmhmhmh"
let! b = "isword"
let c = a / b
return c
} |> should equal None
27 changes: 27 additions & 0 deletions semester4/Workflows/Workflows.Tests/Workflows.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

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

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

<ItemGroup>
<PackageReference Include="FsUnit" Version="4.0.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
</ItemGroup>

<ItemGroup>
<Compile Include="RoundWorkflowTest.fs" />
<Compile Include="StringWorkflowTests.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

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

</Project>
22 changes: 22 additions & 0 deletions semester4/Workflows/Workflows.sln
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions semester4/Workflows/Workflows/RoundWorkflow.fs
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions semester4/Workflows/Workflows/StringWorkflow.fs
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions semester4/Workflows/Workflows/Workflows.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<Compile Include="RoundWorkflow.fs" />
<Compile Include="StringWorkflow.fs" />
</ItemGroup>

</Project>