Sha256: 21348717a5802adebc30e8666d6c0f35872e5d513103165a8a2ad3bdcaaf4b67

Contents?: true

Size: 1.36 KB

Versions: 150

Compression:

Stored size: 1.36 KB

Contents

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

open OUnit2
open Binary_search
open Core

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 Int.to_string) 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

150 entries across 150 versions & 1 rubygems

Version Path
trackler-2.1.0.52 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.51 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.50 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.49 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.48 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.47 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.46 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.45 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.44 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.43 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.42 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.41 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.40 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.39 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.38 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.37 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.36 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.34 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.33 tracks/ocaml/exercises/binary-search/test.ml
trackler-2.1.0.32 tracks/ocaml/exercises/binary-search/test.ml