Skip to content

Commit 0ffdfee

Browse files
authored
Merge pull request #1 from kahgoh/bnandras/add-darts
Template for darts exercise
2 parents 1ce642d + a6c8f16 commit 0ffdfee

File tree

5 files changed

+49
-28
lines changed

5 files changed

+49
-28
lines changed

exercises/practice/darts/.meta/config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"authors": [
33
"BNAndras"
44
],
5+
"contributors": [
6+
"kahgoh"
7+
],
58
"files": {
69
"solution": [
710
"darts.ml"

exercises/practice/darts/test.ml

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,32 @@ let ae exp got _test_ctxt =
88

99
let tests = [
1010
"Missed target" >::
11-
ae 0 (score (-9.0) (9.0));
12-
11+
ae 0 (score (-9.0) (9.0));
1312
"On the outer circle" >::
14-
ae 1 (score (0.0) (10.0));
15-
13+
ae 1 (score (0.0) (10.0));
1614
"On the middle circle" >::
17-
ae 5 (score (-5.0) (0.0));
18-
15+
ae 5 (score (-5.0) (0.0));
1916
"On the inner circle" >::
20-
ae 10 (score (0.0) (-1.0));
21-
22-
"Exactly on center" >::
23-
ae 10 (score (0.0) (0.0));
24-
25-
"Near the center" >::
26-
ae 10 (score (-0.1) (-0.1));
27-
17+
ae 10 (score (0.0) (-1.0));
18+
"Exactly on centre" >::
19+
ae 10 (score (0.0) (0.0));
20+
"Near the centre" >::
21+
ae 10 (score (-0.1) (-0.1));
2822
"Just within the inner circle" >::
29-
ae 10 (score (0.7) (0.7));
30-
23+
ae 10 (score (0.7) (0.7));
3124
"Just outside the inner circle" >::
32-
ae 5 (score (0.8) (-0.8));
33-
25+
ae 5 (score (0.8) (-0.8));
3426
"Just within the middle circle" >::
35-
ae 5 (score (-3.5) (3.5));
36-
27+
ae 5 (score (-3.5) (3.5));
3728
"Just outside the middle circle" >::
38-
ae 1 (score (-3.6) (-3.6));
39-
29+
ae 1 (score (-3.6) (-3.6));
4030
"Just within the outer circle" >::
41-
ae 1 (score (-7.0) (7.0));
42-
31+
ae 1 (score (-7.) (7.));
4332
"Just outside the outer circle" >::
44-
ae 0 (score (7.1) (-7.1));
45-
33+
ae 0 (score (7.1) (-7.1));
4634
"Asymmetric position between the inner and middle circles" >::
47-
ae 5 (score (0.5) (-4.0));
35+
ae 5 (score (0.5) (-4.0));
4836
]
4937

5038
let () =
51-
run_test_tt_main ("darts tests" >::: tests)
39+
run_test_tt_main ("darts tests" >::: tests)

templates/darts/dune-project.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 1.1)

templates/darts/test.ml.tpl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
open Base
2+
open OUnit2
3+
open Darts
4+
5+
let ae exp got _test_ctxt =
6+
let printer = Int.to_string in
7+
assert_equal exp got ~printer
8+
9+
let tests = [
10+
{{#cases}}
11+
"{{description}}" >::
12+
ae {{#input}}{{expected}} ({{property}} ({{x}}) ({{y}})){{/input}};
13+
{{/cases}}
14+
]
15+
16+
let () =
17+
run_test_tt_main ("darts tests" >::: tests)

test-generator/lib_generator/special_cases.ml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,17 @@ let edit_change (ps: (string * json) list): (string * string) list =
231231
| (k, v) -> (k, json_to_string v) in
232232
ps |> List.map ~f:edit
233233

234+
let edit_darts (ps: (string * json) list): (string * string) list =
235+
let edit_float = function
236+
| v -> match (String.contains v '.') with
237+
| true -> v
238+
| false -> v ^ ".0" in
239+
let edit = function
240+
| ("x", v) -> ("x", (edit_float (json_to_string v)))
241+
| ("y", v) -> ("y", (edit_float (json_to_string v)))
242+
| (k, v) -> (k, json_to_string v) in
243+
ps |> List.map ~f:edit
244+
234245
let edit_rectangles (ps: (string * json) list): (string * string) list =
235246
let format_field l =
236247
let sep = if List.length l > 1 then ";\n" else "" in
@@ -323,6 +334,7 @@ let edit_parameters ~(slug: string) (parameters: (string * json) list) = match (
323334
| ("bowling", ps) -> edit_bowling ps |> Option.return
324335
| ("connect", ps) -> edit_connect ps |> Option.return
325336
| ("change", ps) -> edit_change ps |> Option.return
337+
| ("darts", ps) -> edit_darts ps |> Option.return
326338
| ("dominoes", ps) -> edit_dominoes ps |> Option.return
327339
| ("etl", ps) -> edit_etl ps |> Option.return
328340
| ("forth", ps) -> edit_expected ~f:edit_forth_expected ps |> Option.return

0 commit comments

Comments
 (0)