Skip to content
Merged
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
34 changes: 34 additions & 0 deletions demo-repository/exercises/demo/descr.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,52 @@ <h2>The task</h2>
integer-arithmetic functions.
</p>

<p>
You are also asked to write test suites for these functions. A test
suite is specified as a list of input/expected output pairs. These
tests will be run against some buggy programs to test their coverage.
</p>

<ol>
<li>
Write a function <code>plus</code> of type <code>int -> int -> int</code>.
<ul>
<li>
Write some test cases for this function in the variable
<code>plus_tests</code>. Your test cases should be pairs of type
<code>(int * int) * int</code>.
</li>
</ul>
</li>
<li>
Write a function <code>minus</code> of type <code>int -> int -> int</code>.
<ul>
<li>
Write some test cases for this function in the variable
<code>minus_tests</code>. Your test cases should be pairs of type
<code>(int * int) * int</code>.
</li>
</ul>
</li>
<li>
Write a function <code>times</code> of type <code>int -> int -> int</code>.
<ul>
<li>
Write some test cases for this function in the variable
<code>times_tests</code>. Your test cases should be pairs of type
<code>(int * int) * int</code>.
</li>
</ul>
</li>
<li>
Write a function <code>divide</code> of type <code>int -> int -> int</code>.
<ul>
<li>
Write some test cases for this function in the variable
<code>divide_tests</code>. Your test cases should be pairs of type
<code>(int * int) * int</code>.
</li>
</ul>
</li>
</ol>

Expand Down
7 changes: 7 additions & 0 deletions demo-repository/exercises/demo/solution.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
let plus = (+)
let plus_tests = [((1, 1), 2)]

let times = ( * )
let times_tests = [((2, 2), 4)]

let minus = ( - )
let minus_tests = [((1, 1), 0)]

let divide = ( / )
let divide_tests = [((2, 2), 1)]
7 changes: 7 additions & 0 deletions demo-repository/exercises/demo/template.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@

let plus x y = x + y ;;
let plus_tests = [
((1, 1), 2);
((1, 0), 1)
];;

let minus x y = y - x ;;
let minus_tests = [
((1, 2), 1)
];;

let times x y = x *
55 changes: 43 additions & 12 deletions demo-repository/exercises/demo/test.ml
Original file line number Diff line number Diff line change
@@ -1,26 +1,57 @@
open Test_lib
open Report

module Mutation_test = Mutation_test.Make (Test_lib)
open Mutation_test

let test_plus () =
test_function_2_against_solution
[%ty : int -> int -> int ] "plus"
[ (1, 1) ; (2, 2) ; (10, -10) ]
@
test_unit_tests_2
[%ty : int -> int -> int ] "plus"
[ ("Subtracts instead of adding", 1, fun x y -> x - y) ]

let test_minus () =
test_function_2_against_solution
[%ty : int -> int -> int ] "minus"
[ (1, 1) ; (4, -2) ; (0, 10) ]
@
test_unit_tests_2
[%ty : int -> int -> int ] "minus"
[ ("Adds instead of subtracting", 1, fun x y -> x + y) ]

let test_times () =
test_function_2_against_solution
[%ty : int -> int -> int ] "times"
[ (1, 3) ; (2, 4) ; (3, 0) ]
@
test_unit_tests_2
[%ty: int -> int -> int ] "times"
[ ("Divides instead of multiplying", 1, fun x y -> x / y) ]

let test_divide () =
test_function_2_against_solution
[%ty : int -> int -> int ] "divide"
[ (12, 4) ; (12, 5) ; (3, 0) ]
@
test_unit_tests_2
[%ty : int -> int -> int ] "divide"
[ ("Multiplies instead of dividing", 1, fun x y -> x * y) ]

let () =
set_result @@
ast_sanity_check code_ast @@ fun () ->
[ Section
([ Text "Function:" ; Code "plus" ],
test_function_2_against_solution
[%ty : int -> int -> int ] "plus"
[ (1, 1) ; (2, 2) ; (10, -10) ]) ;
test_plus ()) ;
Section
([ Text "Function:" ; Code "minus" ],
test_function_2_against_solution
[%ty : int -> int -> int ] "minus"
[ (1, 1) ; (4, -2) ; (0, 10) ]) ;
test_minus ()) ;
Section
([ Text "Function:" ; Code "times" ],
test_function_2_against_solution
[%ty : int -> int -> int ] "times"
[ (1, 3) ; (2, 4) ; (3, 0) ]) ;
test_times ()) ;
Section
([ Text "Function:" ; Code "divide" ],
test_function_2_against_solution
[%ty : int -> int -> int ] "divide"
[ (12, 4) ; (12, 5) ; (3, 0) ]) ]
test_divide ()) ]
6 changes: 4 additions & 2 deletions src/grader/dune
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
learnocaml_repository)
(modules Introspection_intf
Introspection
Test_lib)
Test_lib
Mutation_test)
(modules_without_implementation Introspection_intf)
(preprocess (pps learnocaml_ppx_metaquot))
)
Expand Down Expand Up @@ -106,7 +107,8 @@
../ppx-metaquot/.ty.objs/ty.cmi
.testing.objs/introspection_intf.cmi
.learnocaml_report.objs/learnocaml_report.cmi
.testing.objs/test_lib.cmi))
.testing.objs/test_lib.cmi
.testing.objs/mutation_test.cmi))
(action (with-stdout-to %{targets}
(run ocp-ocamlres -format ocamlres %{compiler-cmis} %{generated-cmis})))
)
Expand Down
Loading