-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bfaa2c
commit 67d0e54
Showing
5 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tests/FPinFSharp.App.UnitTests/Chapter_01/Chapter_01_08_Tests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / build
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters