|
| 1 | +import Foundation |
| 2 | +import Testing |
| 3 | + |
| 4 | +@testable import SpiralMatrix |
| 5 | + |
| 6 | +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false |
| 7 | + |
| 8 | +@Suite struct SpiralMatrixTests { |
| 9 | + |
| 10 | + @Test("empty spiral") |
| 11 | + func testEmptySpiral() { |
| 12 | + #expect(spiralMatrix(size: 0) == []) |
| 13 | + } |
| 14 | + |
| 15 | + @Test("trivial spiral", .enabled(if: RUNALL)) |
| 16 | + func testTrivialSpiral() { |
| 17 | + #expect(spiralMatrix(size: 1) == [[1]]) |
| 18 | + } |
| 19 | + |
| 20 | + @Test("spiral of size 2", .enabled(if: RUNALL)) |
| 21 | + func testSpiralOfSize2() { |
| 22 | + #expect(spiralMatrix(size: 2) == [[1, 2], [4, 3]]) |
| 23 | + } |
| 24 | + |
| 25 | + @Test("spiral of size 3", .enabled(if: RUNALL)) |
| 26 | + func testSpiralOfSize3() { |
| 27 | + #expect(spiralMatrix(size: 3) == [[1, 2, 3], [8, 9, 4], [7, 6, 5]]) |
| 28 | + } |
| 29 | + |
| 30 | + @Test("spiral of size 4", .enabled(if: RUNALL)) |
| 31 | + func testSpiralOfSize4() { |
| 32 | + #expect( |
| 33 | + spiralMatrix(size: 4) == [[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]]) |
| 34 | + } |
| 35 | + |
| 36 | + @Test("spiral of size 5", .enabled(if: RUNALL)) |
| 37 | + func testSpiralOfSize5() { |
| 38 | + #expect( |
| 39 | + spiralMatrix(size: 5) == [ |
| 40 | + [1, 2, 3, 4, 5], [16, 17, 18, 19, 6], [15, 24, 25, 20, 7], [14, 23, 22, 21, 8], |
| 41 | + [13, 12, 11, 10, 9], |
| 42 | + ]) |
| 43 | + } |
| 44 | +} |
0 commit comments