Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round builder is ready #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
31 changes: 31 additions & 0 deletions hw6/WorkflowRound/WorkflowRound.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}") = "WorkflowRound", "WorkflowRound\WorkflowRound.fsproj", "{BE5C910B-3CC9-409D-8AD1-12327D6A27D2}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "WorkflowRoundTests", "WorkflowRoundTests\WorkflowRoundTests.fsproj", "{FBBDBE16-C1E7-481F-B57F-2C5CA2EB3159}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BE5C910B-3CC9-409D-8AD1-12327D6A27D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE5C910B-3CC9-409D-8AD1-12327D6A27D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE5C910B-3CC9-409D-8AD1-12327D6A27D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE5C910B-3CC9-409D-8AD1-12327D6A27D2}.Release|Any CPU.Build.0 = Release|Any CPU
{FBBDBE16-C1E7-481F-B57F-2C5CA2EB3159}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FBBDBE16-C1E7-481F-B57F-2C5CA2EB3159}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FBBDBE16-C1E7-481F-B57F-2C5CA2EB3159}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FBBDBE16-C1E7-481F-B57F-2C5CA2EB3159}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {83ED9AA1-D785-45F8-BE71-2D0864C18522}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions hw6/WorkflowRound/WorkflowRound/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


[<EntryPoint>]
let main argv =

0 // return an integer exit code
10 changes: 10 additions & 0 deletions hw6/WorkflowRound/WorkflowRound/Rounding.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Rounding

open System

/// Rounds float numbers result.
type RoundBuilder(roundTo : int) =
let round = roundTo

Choose a reason for hiding this comment

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

Это не нужно, roundTo "попадает в замыкание" объекта и вполне себе доступен всё время его жизни

member this.Bind(x : float, f) =
f <| Math.Round(x, round)
member this.Return(x : float) = Math.Round(x, round)
13 changes: 13 additions & 0 deletions hw6/WorkflowRound/WorkflowRound/WorkflowRound.fsproj
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="Rounding.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
29 changes: 29 additions & 0 deletions hw6/WorkflowRound/WorkflowRoundTests/RoundingTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module WorkflowRoundTests

open NUnit.Framework
open Rounding
open FsUnit

let testCaseData1 =
[
2.0, 12.0, 3.5, 3, 0.048
2.0, 12.0, 3.5, 2, 0.05
1.0, 1.0, 1.0, 1, 1.0
1.0, 3.0, 1.0, 1, 0.3
1.0, 3.0, 1.0, 2, 0.33
] |> List.map (fun (op1, op2, op3, roundTo, result) -> TestCaseData(op1, op2, op3, roundTo, result))

let rounding roundTo = new RoundBuilder(roundTo)

let calcRound op1 op2 op3 round =
rounding round {
let! a = op1 / op2
let! b = op3
return a / b
}

[<Test>]
[<TestCaseSource("testCaseData1")>]
let ``Rounding works correctly tests`` op1 op2 op3 roundTo result =
calcRound op1 op2 op3 roundTo |> should (equalWithin 0.01) result

32 changes: 32 additions & 0 deletions hw6/WorkflowRound/WorkflowRoundTests/WorkflowRoundTests.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<IsPackable>false</IsPackable>
<GenerateProgramFile>true</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="RoundingTests.fs" />
</ItemGroup>

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

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

</Project>