Sha256: 39b0c36b2116ce13bd6339214bd246d175d1bf6460e16f79315cf8ec04cd7493

Contents?: true

Size: 1.33 KB

Versions: 54

Compression:

Stored size: 1.33 KB

Contents

use "flatten-array.sml";

val test_cases = [
  {
    description = "[1, [2, [], 3, [4, 5]]] flattens to [1,2,3,4,5]",
    input = List [
        Elem 1,
        List [
          Elem 2,
          List [],
          Elem 3,
          List [Elem 4, Elem 5]
        ]
    ],
    expected = [1, 2, 3, 4, 5]
  },
  {
    description = "[1,2,3,4,5] flattens to [1,2,3,4,5]",
    input = List [
        Elem 1,
        Elem 2,
        Elem 3,
        Elem 4,
        Elem 5
    ],
    expected = [1, 2, 3, 4, 5]
  },
  {
    description = "[] flattens to []",
    input = List [],
    expected = []
  }
];

fun run_tests _ [] = []
  | run_tests f (x :: xs) =
      let
        fun aux { description, input, expected } =
          let
            val output = f input
            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 flatten 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

54 entries across 54 versions & 1 rubygems

Version Path
trackler-2.2.1.4 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.1.3 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.1.2 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.1.1 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.1.0 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.0.6 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.0.5 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.0.4 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.0.3 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.0.2 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.0.1 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.2.0.0 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.1.0.55 tracks/sml/exercises/flatten-array/test_flatten_array.sml
trackler-2.1.0.54 tracks/sml/exercises/flatten-array/test_flatten_array.sml