-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turned exercise 033 into practice (#2220)
- Loading branch information
1 parent
90761bb
commit e8b6937
Showing
9 changed files
with
42 additions
and
0 deletions.
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,4 @@ | ||
let rec gcd a b = | ||
if b = 0 then a else gcd b (a mod b) | ||
|
||
let coprime a b = gcd a b = 1 |
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,2 @@ | ||
(include_subdirs no) | ||
(test (name run) (libraries ounit2 ex)) |
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,3 @@ | ||
module Test = Ex.Make(Ex.Answer) | ||
|
||
let () = OUnit2.run_test_tt_main Test.v |
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,2 @@ | ||
(include_subdirs qualified) | ||
(library (name ex) (libraries ounit2)) |
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 @@ | ||
(lang dune 3.7) |
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,21 @@ | ||
open OUnit2 | ||
|
||
module type Testable = sig | ||
val coprime : int -> int -> bool | ||
end | ||
|
||
module Make(Tested: Testable) : sig val v : test end = struct | ||
let tests = "coprime" >::: [ | ||
"coprime numbers" >:: (fun _ -> | ||
assert_bool "13 and 27 should be coprime" (Tested.coprime 13 27)); | ||
"not coprime numbers" >:: (fun _ -> | ||
assert_bool "20536 and 7826 should not be coprime" (not (Tested.coprime 20536 7826))); | ||
] | ||
|
||
let v = "Coprime Tests" >::: [ | ||
tests | ||
] | ||
end | ||
|
||
module Work : Testable = Work.Impl | ||
module Answer : Testable = Answer.Impl |
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,4 @@ | ||
let rec gcd a b = | ||
if b = 0 then a else gcd b (a mod b) | ||
|
||
let coprime _ _ = failwith "Not yet implemented" |
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,2 @@ | ||
(include_subdirs no) | ||
(test (name run) (libraries ounit2 ex)) |
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,3 @@ | ||
module Test = Ex.Make(Ex.Work) | ||
|
||
let () = OUnit2.run_test_tt_main Test.v |