Sha256: 711302a0c492e9bc323ea72830e7a12dd5912fc07a988835e24d3df791629bfe

Contents?: true

Size: 1.77 KB

Versions: 54

Compression:

Stored size: 1.77 KB

Contents

use "nth-prime.sml";

val test_cases = [
  {
    description = "The first prime is 2",
    input = 1,
    expected = 2
  },
  {
    description = "The second prime is 3",
    input = 2,
    expected = 3
  },
  {
    description = "The ninth prime is 23",
    input = 9,
    expected = 23
  },
  {
    description = "The one-hundredth prime is 541",
    input = 100,
    expected = 541
  },
  {
    description = "The three-thousand and first prime is 27457",
    input = 3001,
    expected = 27457
  }
];

val error_test_cases = [
  {
    description = "The 0th prime is not defined",
    input = 0,
    expected = Domain
  },
  {
    description = "The -1st prime is not defined",
    input = ~1,
    expected = Domain
  }
];

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

fun evaluateGoodTestCase f { description, input, expected } =
  { description = description, is_correct = (f input) = expected }

fun evaluateErrorTestCase f { description, input, expected } =
  { description = description, is_correct = (f input handle expected => 1) = 1 }

val testResults = run_tests nthPrime (List.map (evaluateGoodTestCase nthPrime) test_cases)
  @ run_tests nthPrime (List.map (evaluateErrorTestCase nthPrime) error_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.44 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.43 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.42 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.41 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.40 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.39 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.38 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.37 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.36 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.35 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.34 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.33 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.32 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.31 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.30 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.29 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.28 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.27 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.26 tracks/sml/exercises/nth-prime/test.sml
trackler-2.2.1.25 tracks/sml/exercises/nth-prime/test.sml