Sha256: 06322cbffb06067c181ca3ce7aa379d5bac985e8b1360c6550b825e448d1c86f

Contents?: true

Size: 1.35 KB

Versions: 68

Compression:

Stored size: 1.35 KB

Contents

(* Test/exercise version: "1.1.0" *)

open OUnit2
open Binary_search

let option_to_string f = function
  | None   -> "None"
  | Some x -> "Some " ^ f x

let ae exp got _test_ctxt =
  assert_equal ~printer:(option_to_string string_of_int) exp got

let tests = [
  "finds a value in an array with one element" >::
    ae (Some 0) (find [|6|] 6);
  "finds a value in the middle of an array" >::
    ae (Some 3) (find [|1; 3; 4; 6; 8; 9; 11|] 6);
  "finds a value at the beginning of an array" >::
    ae (Some 0) (find [|1; 3; 4; 6; 8; 9; 11|] 1);
  "finds a value at the end of an array" >::
    ae (Some 6) (find [|1; 3; 4; 6; 8; 9; 11|] 11);
  "finds a value in an array of odd length" >::
    ae (Some 9) (find [|1; 3; 5; 8; 13; 21; 34; 55; 89; 144; 233; 377; 634|] 144);
  "finds a value in an array of even length" >::
    ae (Some 5) (find [|1; 3; 5; 8; 13; 21; 34; 55; 89; 144; 233; 377|] 21);
  "identifies that a value is not included in the array" >::
    ae None (find [|1; 3; 4; 6; 8; 9; 11|] 7);
  "a value smaller than the array's smallest value is not included" >::
    ae None (find [|1; 3; 4; 6; 8; 9; 11|] 0);
  "a value larger than the array's largest value is not included" >::
    ae None (find [|1; 3; 4; 6; 8; 9; 11|] 13);
  "nothing is included in an empty array" >::
    ae None (find [||] 1);
]

let () =
  run_test_tt_main ("binary-search tests" >::: tests)

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.138 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.137 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.136 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.135 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.134 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.133 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.132 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.131 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.130 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.129 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.128 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.127 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.126 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.125 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.124 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.123 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.122 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.121 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.2.1.120 tracks/ocaml/exercises/binary-search/test.ml