Sha256: e5331e6cf547d2ea9fefc17ef1b7f147e306ea4f1b6848948fb06c2af36f801c

Contents?: true

Size: 1.52 KB

Versions: 50

Compression:

Stored size: 1.52 KB

Contents

use "anagram.sml";

val test_cases = [
  {
    description = "The empty string is not an anagram of anything",
    input = "",
    candidates = ["enlists", "google", "inlets", "banana"],
    expected = []
  },
  {
    description = "A starting word with no candidates returns an empty array",
    input = "listen",
    candidates = [],
    expected = []
  },
  {
    description = "'listen' is an anagram of 'inlets'",
    input = "listen",
    candidates = ["enlists", "google", "inlets", "banana"],
    expected = ["inlets"]
  },
  {
    description = "'hatreds' is an anagram of 'dearths', 'hardest', and 'threads'",
    input = "hatreds",
    candidates = ["dearths","hardest","salmon","devilish", "threads"],
    expected = ["dearths","hardest","threads"]
  }
];

fun run_tests _ [] = []
  | run_tests f (x :: xs) =
      let
        fun aux { description, input, candidates, expected } =
          let
            val output = f input candidates
            val is_correct = output = expected
            val expl = description ^ ": " ^
              (if is_correct then "PASSED" else "FAILED") ^ "\n"
          in
            (print (expl); is_correct)
          end
      in
        (aux x) :: run_tests f xs
      end

val testResults = run_tests anagram test_cases;
val passedTests = List.filter (fn x => x) testResults;
val failedTests = List.filter (fn x => not x) testResults;

if (List.length testResults) = (List.length passedTests)
then (print "ALL TESTS PASSED")
else (print (Int.toString (List.length failedTests) ^ " TEST(S) FAILED"));


Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
trackler-2.2.1.40 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.39 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.38 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.37 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.36 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.35 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.34 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.33 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.32 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.31 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.30 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.29 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.28 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.27 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.26 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.25 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.24 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.23 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.22 tracks/sml/exercises/anagram/test.sml
trackler-2.2.1.21 tracks/sml/exercises/anagram/test.sml