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
3 changes: 3 additions & 0 deletions exercises/practice/darts/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"authors": [
"BNAndras"
],
"contributors": [
"kahgoh"
],
"files": {
"solution": [
"darts.ml"
Expand Down
44 changes: 16 additions & 28 deletions exercises/practice/darts/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,32 @@ let ae exp got _test_ctxt =

let tests = [
"Missed target" >::
ae 0 (score (-9.0) (9.0));

ae 0 (score (-9.0) (9.0));
"On the outer circle" >::
ae 1 (score (0.0) (10.0));

ae 1 (score (0.0) (10.0));
"On the middle circle" >::
ae 5 (score (-5.0) (0.0));

ae 5 (score (-5.0) (0.0));
"On the inner circle" >::
ae 10 (score (0.0) (-1.0));

"Exactly on center" >::
ae 10 (score (0.0) (0.0));

"Near the center" >::
ae 10 (score (-0.1) (-0.1));

ae 10 (score (0.0) (-1.0));
"Exactly on centre" >::
ae 10 (score (0.0) (0.0));
"Near the centre" >::
ae 10 (score (-0.1) (-0.1));
"Just within the inner circle" >::
ae 10 (score (0.7) (0.7));

ae 10 (score (0.7) (0.7));
"Just outside the inner circle" >::
ae 5 (score (0.8) (-0.8));

ae 5 (score (0.8) (-0.8));
"Just within the middle circle" >::
ae 5 (score (-3.5) (3.5));

ae 5 (score (-3.5) (3.5));
"Just outside the middle circle" >::
ae 1 (score (-3.6) (-3.6));

ae 1 (score (-3.6) (-3.6));
"Just within the outer circle" >::
ae 1 (score (-7.0) (7.0));

ae 1 (score (-7.) (7.));
"Just outside the outer circle" >::
ae 0 (score (7.1) (-7.1));

ae 0 (score (7.1) (-7.1));
"Asymmetric position between the inner and middle circles" >::
ae 5 (score (0.5) (-4.0));
ae 5 (score (0.5) (-4.0));
]

let () =
run_test_tt_main ("darts tests" >::: tests)
run_test_tt_main ("darts tests" >::: tests)
1 change: 1 addition & 0 deletions templates/darts/dune-project.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.1)
17 changes: 17 additions & 0 deletions templates/darts/test.ml.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
open Base
open OUnit2
open Darts

let ae exp got _test_ctxt =
let printer = Int.to_string in
assert_equal exp got ~printer

let tests = [
{{#cases}}
"{{description}}" >::
ae {{#input}}{{expected}} ({{property}} ({{x}}) ({{y}})){{/input}};
{{/cases}}
]

let () =
run_test_tt_main ("darts tests" >::: tests)
12 changes: 12 additions & 0 deletions test-generator/lib_generator/special_cases.ml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ let edit_change (ps: (string * json) list): (string * string) list =
| (k, v) -> (k, json_to_string v) in
ps |> List.map ~f:edit

let edit_darts (ps: (string * json) list): (string * string) list =
let edit_float = function
| v -> match (String.contains v '.') with
| true -> v
| false -> v ^ ".0" in
let edit = function
| ("x", v) -> ("x", (edit_float (json_to_string v)))
| ("y", v) -> ("y", (edit_float (json_to_string v)))
| (k, v) -> (k, json_to_string v) in
ps |> List.map ~f:edit

let edit_rectangles (ps: (string * json) list): (string * string) list =
let format_field l =
let sep = if List.length l > 1 then ";\n" else "" in
Expand Down Expand Up @@ -323,6 +334,7 @@ let edit_parameters ~(slug: string) (parameters: (string * json) list) = match (
| ("bowling", ps) -> edit_bowling ps |> Option.return
| ("connect", ps) -> edit_connect ps |> Option.return
| ("change", ps) -> edit_change ps |> Option.return
| ("darts", ps) -> edit_darts ps |> Option.return
| ("dominoes", ps) -> edit_dominoes ps |> Option.return
| ("etl", ps) -> edit_etl ps |> Option.return
| ("forth", ps) -> edit_expected ~f:edit_forth_expected ps |> Option.return
Expand Down