Sha256: c0cb639d853be2a50c4f82bf8b6776f0da359bdf4ce7b65d9c811f3f027c43a1

Contents?: true

Size: 1.49 KB

Versions: 68

Compression:

Stored size: 1.49 KB

Contents

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

open Base
open OUnit2
open Phone_number

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 Fn.id) exp got

let tests = [
  "cleans the number" >::
    ae (Some "2234567890") (number "(223) 456-7890");
  "cleans numbers with dots" >::
    ae (Some "2234567890") (number "223.456.7890");
  "cleans numbers with multiple spaces" >::
    ae (Some "2234567890") (number "223 456   7890   ");
  "invalid when 9 digits" >::
    ae None (number "123456789");
  "invalid when 11 digits does not start with a 1" >::
    ae None (number "22234567890");
  "valid when 11 digits and starting with 1" >::
    ae (Some "2234567890") (number "12234567890");
  "valid when 11 digits and starting with 1 even with punctuation" >::
    ae (Some "2234567890") (number "+1 (223) 456-7890");
  "invalid when more than 11 digits" >::
    ae None (number "321234567890");
  "invalid with letters" >::
    ae None (number "123-abc-7890");
  "invalid with punctuations" >::
    ae None (number "123-@:!-7890");
  "invalid if area code starts with 0" >::
    ae None (number "(023) 456-7890");
  "invalid if area code starts with 1" >::
    ae None (number "(123) 456-7890");
  "invalid if exchange code starts with 0" >::
    ae None (number "(223) 056-7890");
  "invalid if exchange code starts with 1" >::
    ae None (number "(223) 156-7890");
]

let () =
  run_test_tt_main ("phone-number tests" >::: tests)

Version data entries

68 entries across 68 versions & 1 rubygems

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