Sha256: 1d20d0c25a64cc6b9c2141c5e5d2f204a491c80550225b0f94b2aa37361e3344

Contents?: true

Size: 1.26 KB

Versions: 19

Compression:

Stored size: 1.26 KB

Contents

open Core.Std
open OUnit2
open Dominoes

let print_dominoe (d1, d2) = sprintf "(%d,%d)" d1 d2

let option_printer = function
  | None -> "None"
  | Some xs -> "Some [" ^ String.concat ~sep:";" (List.map xs ~f:print_dominoe) ^ "]"

let drop_1_right xs = List.rev xs |> List.tl_exn |> List.rev

let check_chain (chained: dominoe list) = 
  let assert_dominoes_match d1 d2 =
    if snd d1 <> fst d2 then failwith @@ sprintf "%s and %s cannot be chained together" (print_dominoe d1) (print_dominoe d2) else () in
  let consecutives = List.zip_exn (drop_1_right chained) (List.tl_exn chained) in
  List.iter consecutives ~f:(fun (d1, d2) -> assert_dominoes_match d1 d2)

let assert_empty c = if List.is_empty c then () else failwith "Expected 0 length chain"

let assert_valid_chain input _ctxt =
  match chain input with
  | None -> failwith "Expecting a chain"
  | Some(c) -> (if List.is_empty input then assert_empty else check_chain) c  

let assert_no_chain input _ctxt =
  assert_equal None (chain input) ~printer:option_printer

let assert_chain input hasChain =
  if hasChain then assert_valid_chain input else assert_no_chain input

let tests = [
(* TEST
  "$description" >::
    assert_chain $input $expected;
END TEST *)
]

let () =
  run_test_tt_main ("dominoes tests" >::: tests)

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
trackler-2.0.6.19 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.18 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.17 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.16 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.15 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.14 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.13 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.12 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.11 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.10 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.9 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.8 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.7 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.6 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.5 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.4 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.3 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.2 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml
trackler-2.0.6.1 tracks/ocaml/tools/test-generator/templates/dominoes/template.ml