|
1 | | -import XCTest |
| 1 | +import Foundation |
| 2 | +import Testing |
2 | 3 |
|
3 | 4 | @testable import PrimeFactors |
4 | 5 |
|
5 | | -class PrimeFactorsTests: XCTestCase { |
6 | | - let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false |
| 6 | +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false |
7 | 7 |
|
| 8 | +@Suite struct PrimeFactorsTests { |
| 9 | + |
| 10 | + @Test("no factors") |
8 | 11 | func testNoFactors() { |
9 | | - XCTAssertEqual(primeFactors(1), []) |
| 12 | + #expect(primeFactors(1) == []) |
10 | 13 | } |
11 | 14 |
|
12 | | - func testPrimeNumber() throws { |
13 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
14 | | - XCTAssertEqual(primeFactors(2), [2]) |
| 15 | + @Test("prime number", .enabled(if: RUNALL)) |
| 16 | + func testPrimeNumber() { |
| 17 | + #expect(primeFactors(2) == [2]) |
15 | 18 | } |
16 | 19 |
|
17 | | - func testAnotherPrimeNumber() throws { |
18 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
19 | | - XCTAssertEqual(primeFactors(3), [3]) |
| 20 | + @Test("another prime number", .enabled(if: RUNALL)) |
| 21 | + func testAnotherPrimeNumber() { |
| 22 | + #expect(primeFactors(3) == [3]) |
20 | 23 | } |
21 | 24 |
|
22 | | - func testSquareOfAPrime() throws { |
23 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
24 | | - XCTAssertEqual(primeFactors(9), [3, 3]) |
| 25 | + @Test("square of a prime", .enabled(if: RUNALL)) |
| 26 | + func testSquareOfAPrime() { |
| 27 | + #expect(primeFactors(9) == [3, 3]) |
25 | 28 | } |
26 | 29 |
|
27 | | - func testProductOfFirstPrime() throws { |
28 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
29 | | - XCTAssertEqual(primeFactors(4), [2, 2]) |
| 30 | + @Test("product of first prime", .enabled(if: RUNALL)) |
| 31 | + func testProductOfFirstPrime() { |
| 32 | + #expect(primeFactors(4) == [2, 2]) |
30 | 33 | } |
31 | 34 |
|
32 | | - func testCubeOfAPrime() throws { |
33 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
34 | | - XCTAssertEqual(primeFactors(8), [2, 2, 2]) |
| 35 | + @Test("cube of a prime", .enabled(if: RUNALL)) |
| 36 | + func testCubeOfAPrime() { |
| 37 | + #expect(primeFactors(8) == [2, 2, 2]) |
35 | 38 | } |
36 | 39 |
|
37 | | - func testProductOfSecondPrime() throws { |
38 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
39 | | - XCTAssertEqual(primeFactors(27), [3, 3, 3]) |
| 40 | + @Test("product of second prime", .enabled(if: RUNALL)) |
| 41 | + func testProductOfSecondPrime() { |
| 42 | + #expect(primeFactors(27) == [3, 3, 3]) |
40 | 43 | } |
41 | 44 |
|
42 | | - func testProductOfThirdPrime() throws { |
43 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
44 | | - XCTAssertEqual(primeFactors(625), [5, 5, 5, 5]) |
| 45 | + @Test("product of third prime", .enabled(if: RUNALL)) |
| 46 | + func testProductOfThirdPrime() { |
| 47 | + #expect(primeFactors(625) == [5, 5, 5, 5]) |
45 | 48 | } |
46 | 49 |
|
47 | | - func testProductOfFirstAndSecondPrime() throws { |
48 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
49 | | - XCTAssertEqual(primeFactors(6), [2, 3]) |
| 50 | + @Test("product of first and second prime", .enabled(if: RUNALL)) |
| 51 | + func testProductOfFirstAndSecondPrime() { |
| 52 | + #expect(primeFactors(6) == [2, 3]) |
50 | 53 | } |
51 | 54 |
|
52 | | - func testProductOfPrimesAndNonPrimes() throws { |
53 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
54 | | - XCTAssertEqual(primeFactors(12), [2, 2, 3]) |
| 55 | + @Test("product of primes and non-primes", .enabled(if: RUNALL)) |
| 56 | + func testProductOfPrimesAndNonPrimes() { |
| 57 | + #expect(primeFactors(12) == [2, 2, 3]) |
55 | 58 | } |
56 | 59 |
|
57 | | - func testProductOfPrimes() throws { |
58 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
59 | | - XCTAssertEqual(primeFactors(901255), [5, 17, 23, 461]) |
| 60 | + @Test("product of primes", .enabled(if: RUNALL)) |
| 61 | + func testProductOfPrimes() { |
| 62 | + #expect(primeFactors(901255) == [5, 17, 23, 461]) |
60 | 63 | } |
61 | 64 |
|
62 | | - func testFactorsIncludeALargePrime() throws { |
63 | | - try XCTSkipIf(true && !runAll) // change true to false to run this test |
64 | | - XCTAssertEqual(primeFactors(93_819_012_551), [11, 9539, 894119]) |
| 65 | + @Test("factors include a large prime", .enabled(if: RUNALL)) |
| 66 | + func testFactorsIncludeALargePrime() { |
| 67 | + #expect(primeFactors(93_819_012_551) == [11, 9539, 894119]) |
65 | 68 | } |
66 | 69 | } |
0 commit comments