-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathPerfectNumbersTests.swift
78 lines (62 loc) · 2.83 KB
/
PerfectNumbersTests.swift
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
import Foundation
import Testing
@testable import PerfectNumbers
let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false
@Suite struct PerfectNumbersTests {
@Test("Smallest perfect number is classified correctly")
func testSmallestPerfectNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 6) == .perfect)
}
@Test("Medium perfect number is classified correctly", .enabled(if: RUNALL))
func testMediumPerfectNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 28) == .perfect)
}
@Test("Large perfect number is classified correctly", .enabled(if: RUNALL))
func testLargePerfectNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 33_550_336) == .perfect)
}
@Test("Smallest abundant number is classified correctly", .enabled(if: RUNALL))
func testSmallestAbundantNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 12) == .abundant)
}
@Test("Medium abundant number is classified correctly", .enabled(if: RUNALL))
func testMediumAbundantNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 30) == .abundant)
}
@Test("Large abundant number is classified correctly", .enabled(if: RUNALL))
func testLargeAbundantNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 33_550_335) == .abundant)
}
@Test("Smallest prime deficient number is classified correctly", .enabled(if: RUNALL))
func testSmallestPrimeDeficientNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 2) == .deficient)
}
@Test("Smallest non-prime deficient number is classified correctly", .enabled(if: RUNALL))
func testSmallestNonPrimeDeficientNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 4) == .deficient)
}
@Test("Medium deficient number is classified correctly", .enabled(if: RUNALL))
func testMediumDeficientNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 32) == .deficient)
}
@Test("Large deficient number is classified correctly", .enabled(if: RUNALL))
func testLargeDeficientNumberIsClassifiedCorrectly() {
#expect(try! classify(number: 33_550_337) == .deficient)
}
@Test("Edge case (no factors other than itself) is classified correctly", .enabled(if: RUNALL))
func testEdgeCaseNoFactorsOtherThanItselfIsClassifiedCorrectly() {
#expect(try! classify(number: 1) == .deficient)
}
@Test("Zero is rejected (as it is not a positive integer)", .enabled(if: RUNALL))
func testZeroIsRejectedAsItIsNotAPositiveInteger() {
#expect(throws: ClassificationError.invalidInput) {
try classify(number: 0)
}
}
@Test("Negative integer is rejected (as it is not a positive integer)", .enabled(if: RUNALL))
func testNegativeIntegerIsRejectedAsItIsNotAPositiveInteger() {
#expect(throws: ClassificationError.invalidInput) {
try classify(number: -1)
}
}
}