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

Turn exercise 003 into practice #2187

Closed
wants to merge 4 commits into from
Closed
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
18 changes: 0 additions & 18 deletions .gitignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should not modify this file in this PR

This file was deleted.

4 changes: 4 additions & 0 deletions practice/003/answer/impl.ml
mnaibei marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# let rec at k = function
| [] -> None
| h :: t -> if k = 0 then Some h else at (k - 1) t;;
val at : int -> 'a list -> 'a option = <fun>
2 changes: 2 additions & 0 deletions practice/003/answer/test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(include_subdirs no)
(test (name run) (libraries ounit2 ex))
3 changes: 3 additions & 0 deletions practice/003/answer/test/run.ml
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
2 changes: 2 additions & 0 deletions practice/003/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(include_subdirs qualified)
(library (name ex) (libraries ounit2))
1 change: 1 addition & 0 deletions practice/003/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.7)
16 changes: 16 additions & 0 deletions practice/003/ex.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

open OUnit2

module type Testable = sig
val last : 'a list -> 'a option
end

module Make(Tested: Testable) : sig val v : test end = struct
let v = "last" >::: [
"nil" >:: (fun _ -> assert_equal None (Tested.last []));
"cons" >:: (fun _ -> assert_equal (Some "d") (Tested.last ["a"; "b"; "c"; "d"]));
]
end

module Work : Testable = Work.Impl
module Answer : Testable = Answer.Impl
1 change: 1 addition & 0 deletions practice/003/work/impl.ml
mnaibei marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let last_three _ = failwith "Not yet implemented"
2 changes: 2 additions & 0 deletions practice/003/work/test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(include_subdirs no)
(test (name run) (libraries ounit2 ex))
3 changes: 3 additions & 0 deletions practice/003/work/test/run.ml
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