Skip to content

Commit

Permalink
Add Chapter 01 08.
Browse files Browse the repository at this point in the history
  • Loading branch information
eminencegrs committed Jan 21, 2024
1 parent 4bfaa2c commit 67d0e54
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/FPinFSharp.App/Chapter_01/Chapter_01_08.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace FPinFSharp.App.Chapter_01

// 1.8 Euclid’s algorithm (for computing the greatest common divisor of two natural numbers).
module Chapter_01_08 =

let rec gcd (m, n) =
match (m, n) with
| (0, n) -> n
| (m, n) -> gcd(n % m, m)
1 change: 1 addition & 0 deletions src/FPinFSharp.App/FPinFSharp.App.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Compile Include="Chapter_01\Chapter_01_04.fs" />
<Compile Include="Chapter_01\Chapter_01_05.fs" />
<Compile Include="Chapter_01\Chapter_01_06.fs" />
<Compile Include="Chapter_01\Chapter_01_08.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open Xunit
module Chapter_01_06_Tests =

[<Fact>]
let ``Should not throw an exception`` () =
let ``Should triple 10 to get 1000`` () =
let x = 10
let expectedResult = 1000
let actualResult = validFunction x
Expand Down
13 changes: 13 additions & 0 deletions tests/FPinFSharp.App.UnitTests/Chapter_01/Chapter_01_08_Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace FPinFSharp.App.UnitTests.Chapter_01

open FPinFSharp.App.Chapter_01.Chapter_01_08
open Xunit

module Chapter_01_08_Tests =

[<Theory>]
[<InlineData(12, 27, 3)>]
[<InlineData(36, 116, 4)>]
let ``Should get the greatest common divisor of two natural numbers`` (m, n, expectedResult) =
let actualResult = gcd(m, n)
Assert.Equal(expectedResult, actualResult)

Check warning on line 13 in tests/FPinFSharp.App.UnitTests/Chapter_01/Chapter_01_08_Tests.fs

View workflow job for this annotation

GitHub Actions / build

Main module of program is empty: nothing will happen when it is run

Check warning on line 13 in tests/FPinFSharp.App.UnitTests/Chapter_01/Chapter_01_08_Tests.fs

View workflow job for this annotation

GitHub Actions / build

Main module of program is empty: nothing will happen when it is run
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<Compile Include="Chapter_01\Chapter_01_04_Tests.fs" />
<Compile Include="Chapter_01\Chapter_01_05_Tests.fs" />
<Compile Include="Chapter_01\Chapter_01_06_Tests.fs" />
<Compile Include="Chapter_01\Chapter_01_08_Tests.fs" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 67d0e54

Please sign in to comment.