1
exercism fetch scala perfect-numbers

src/test/scala/PerfectNumbersTest.scala

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import org.scalatest.{Matchers, FunSuite}

/** @version 1.0.1 */
class PerfectNumbersTest extends FunSuite with Matchers {

  test("Smallest perfect number is classified correctly") {
    PerfectNumbers.classify(6) should be (Right(NumberType.Perfect))
  }

  test("Medium perfect number is classified correctly") {
    pending
    PerfectNumbers.classify(28) should be (Right(NumberType.Perfect))
  }

  test("Large perfect number is classified correctly") {
    pending
    PerfectNumbers.classify(33550336) should be (Right(NumberType.Perfect))
  }

  test("Smallest abundant number is classified correctly") {
    pending
    PerfectNumbers.classify(12) should be (Right(NumberType.Abundant))
  }

  test("Medium abundant number is classified correctly") {
    pending
    PerfectNumbers.classify(30) should be (Right(NumberType.Abundant))
  }

  test("Large abundant number is classified correctly") {
    pending
    PerfectNumbers.classify(33550335) should be (Right(NumberType.Abundant))
  }

  test("Smallest prime deficient number is classified correctly") {
    pending
    PerfectNumbers.classify(2) should be (Right(NumberType.Deficient))
  }

  test("Smallest non-prime deficient number is classified correctly") {
    pending
    PerfectNumbers.classify(4) should be (Right(NumberType.Deficient))
  }

  test("Medium deficient number is classified correctly") {
    pending
    PerfectNumbers.classify(32) should be (Right(NumberType.Deficient))
  }

  test("Large deficient number is classified correctly") {
    pending
    PerfectNumbers.classify(33550337) should be (Right(NumberType.Deficient))
  }

  test("Edge case (no factors other than itself) is classified correctly") {
    pending
    PerfectNumbers.classify(1) should be (Right(NumberType.Deficient))
  }

  test("Zero is rejected (not a natural number)") {
    pending
    PerfectNumbers.classify(0) should be (Left("Classification is only possible for natural numbers."))
  }

  test("Negative integer is rejected (not a natural number)") {
    pending
    PerfectNumbers.classify(-1) should be (Left("Classification is only possible for natural numbers."))
  }
}