Sha256: 7ce7485239b7143662ae229a578d6b686f49f42531d3330defa6cf671cb19b86

Contents?: true

Size: 1.95 KB

Versions: 162

Compression:

Stored size: 1.95 KB

Contents

(* version 1.0.1 *)

use "perfect-numbers.sml";
use "testlib.sml";

infixr |>
fun x |> f = f x

val testsuite =
  describe "perfect-numbers" [
    describe "Perfect numbers" [
      test "Smallest perfect number is classified correctly"
        (fn _ => classify (6) |> Expect.equalTo Perfect),

      test "Medium perfect number is classified correctly"
        (fn _ => classify (28) |> Expect.equalTo Perfect),

      test "Large perfect number is classified correctly"
        (fn _ => classify (33550336) |> Expect.equalTo Perfect)
    ],

    describe "Abundant numbers" [
      test "Smallest abundant number is classified correctly"
        (fn _ => classify (12) |> Expect.equalTo Abundant),

      test "Medium abundant number is classified correctly"
        (fn _ => classify (30) |> Expect.equalTo Abundant),

      test "Large abundant number is classified correctly"
        (fn _ => classify (33550335) |> Expect.equalTo Abundant)
    ],

    describe "Deficient numbers" [
      test "Smallest prime deficient number is classified correctly"
        (fn _ => classify (2) |> Expect.equalTo Deficient),

      test "Smallest non-prime deficient number is classified correctly"
        (fn _ => classify (4) |> Expect.equalTo Deficient),

      test "Medium deficient number is classified correctly"
        (fn _ => classify (32) |> Expect.equalTo Deficient),

      test "Large deficient number is classified correctly"
        (fn _ => classify (33550337) |> Expect.equalTo Deficient),

      test "Edge case (no factors other than itself) is classified correctly"
        (fn _ => classify (1) |> Expect.equalTo Deficient)
    ],

    describe "Invalid inputs" [
      test "Zero is rejected (not a natural number)"
        (fn _ => (fn _ => classify (~1)) |> Expect.error NotAPositiveInteger),

      test "Negative integer is rejected (not a natural number)"
        (fn _ => (fn _ => classify (~1)) |> Expect.error NotAPositiveInteger)
    ]
  ]

val _ = Test.run testsuite

Version data entries

162 entries across 162 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.179 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.178 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.177 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.176 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.175 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.174 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.173 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.172 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.171 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.170 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.169 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.167 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.166 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.165 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.164 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.163 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.162 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.161 tracks/sml/exercises/perfect-numbers/test.sml
trackler-2.2.1.160 tracks/sml/exercises/perfect-numbers/test.sml