Sha256: 0dc63eebd02c501407978d6f67450a4e5fc6dca9e041a8ef02349f9fa1c4b542

Contents?: true

Size: 1.49 KB

Versions: 29

Compression:

Stored size: 1.49 KB

Contents

open Core.Std
open OUnit2

let format_board strings =
  let width = match strings with
    | [] -> 0
    | (s::_) -> String.length s in
  let border_line = "+" ^ String.make width '-' ^ "+\n" in
  let line s = "|" ^ s ^ "|\n" in
  "\n" ^ border_line ^ String.concat (List.map strings ~f:line) ^ border_line

(* Assert Equals *)
let ae exp got =
  assert_equal exp got ~cmp:(List.equal ~equal:String.equal) ~printer:format_board

let clean strings =
  List.map strings ~f:(String.map ~f:(function '*' -> '*' | _ -> ' '))

let tests =
  ["zero size board">::(fun _ ->
    ae [] (Minesweeper.annotate []));
   "empty board">::(fun _ ->
    let b = ["   ";
             "   ";
             "   "] in
    ae b (Minesweeper.annotate b));
   "board full of mines">::(fun _ ->
    let b = ["***";
             "***";
             "***"] in
    ae b (Minesweeper.annotate b));
   "surrounded">::(fun _ ->
    let b = ["***";
             "*8*";
             "***"] in
    ae b (Minesweeper.annotate (clean b)));
   "horizontal line">::(fun _ ->
    let b = ["1*2*1"] in
    ae b (Minesweeper.annotate (clean b)));
   "vertical line">::(fun _ ->
     let b = ["1";
              "*";
              "2";
              "*";
              "1"] in
    ae b (Minesweeper.annotate (clean b)));
   "cross">::(fun _ ->
    let b = [" 2*2 ";
             "25*52";
             "*****";
             "25*52";
             " 2*2 "] in
    ae b (Minesweeper.annotate (clean b)));
  ]

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

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
trackler-2.0.3.3 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.3.2 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.3.1 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.3.0 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.2.0 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.1.2 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.1.1 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.1.0 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.10 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.9 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.8 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.7 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.6 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.5 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.4 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.3 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.2 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.1 tracks/ocaml/exercises/minesweeper/test.ml
trackler-2.0.0.0 tracks/ocaml/exercises/minesweeper/test.ml
trackler-1.0.4.1 tracks/ocaml/exercises/minesweeper/test.ml