1
exercism fetch elixir perfect-numbers

perfect_numbers_test.exs

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
  Code.load_file("perfect_numbers.exs", __DIR__)
end

ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)

defmodule PerfectNumbersTest do
  use ExUnit.Case

  describe "Perfect numbers" do
    # @tag :pending
    test "Smallest perfect number is classified correctly" do
      assert PerfectNumbers.classify(6) == {:ok, :perfect}
    end

    @tag :pending
    test "Medium perfect number is classified correctly" do
      assert PerfectNumbers.classify(28) == {:ok, :perfect}
    end

    @tag :pending
    test "Large perfect number is classified correctly" do
      assert PerfectNumbers.classify(33_550_336) == {:ok, :perfect}
    end
  end

  describe "Abundant numbers" do
    @tag :pending
    test "Smallest abundant number is classified correctly" do
      assert PerfectNumbers.classify(12) == {:ok, :abundant}
    end

    @tag :pending
    test "Medium abundant number is classified correctly" do
      assert PerfectNumbers.classify(30) == {:ok, :abundant}
    end

    @tag :pending
    test "Large abundant number is classified correctly" do
      assert PerfectNumbers.classify(33_550_335) == {:ok, :abundant}
    end
  end

  describe "Deficient numbers" do
    @tag :pending
    test "Smallest prime deficient number is classified correctly" do
      assert PerfectNumbers.classify(2) == {:ok, :deficient}
    end

    @tag :pending
    test "Smallest non-prime deficient number is classified correctly" do
      assert PerfectNumbers.classify(4) == {:ok, :deficient}
    end

    @tag :pending
    test "Medium deficient number is classified correctly" do
      assert PerfectNumbers.classify(32) == {:ok, :deficient}
    end

    @tag :pending
    test "Large deficient number is classified correctly" do
      assert PerfectNumbers.classify(33_550_337) == {:ok, :deficient}
    end

    @tag :pending
    test "Edge case (no factors other than itself) is classified correctly" do
      assert PerfectNumbers.classify(1) == {:ok, :deficient}
    end
  end

  describe "Invalid inputs" do
    @tag :pending
    test "Zero is rejected (not a natural number)" do
      assert PerfectNumbers.classify(0) ==
               {:error, "Classification is only possible for natural numbers."}
    end

    @tag :pending
    test "Negative integer is rejected (not a natural number)" do
      assert PerfectNumbers.classify(-1) ==
               {:error, "Classification is only possible for natural numbers."}
    end
  end
end