|
| 1 | +import Foundation |
| 2 | +import Testing |
| 3 | + |
| 4 | +@testable import HighScores |
| 5 | + |
| 6 | +let RUNALL = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false |
| 7 | + |
| 8 | +@Suite struct HighScoresTests { |
| 9 | + |
| 10 | + @Test("List of scores") |
| 11 | + func testListOfScores() { |
| 12 | + #expect(HighScores(scores: [30, 50, 20, 70]).scores == [30, 50, 20, 70]) |
| 13 | + } |
| 14 | + |
| 15 | + @Test("Latest score", .enabled(if: RUNALL)) |
| 16 | + func testLatestScore() { |
| 17 | + #expect(HighScores(scores: [100, 0, 90, 30]).latest == 30) |
| 18 | + } |
| 19 | + |
| 20 | + @Test("Personal best", .enabled(if: RUNALL)) |
| 21 | + func testPersonalBest() { |
| 22 | + #expect(HighScores(scores: [40, 100, 70]).personalBest == 100) |
| 23 | + } |
| 24 | + |
| 25 | + @Test("Personal top three from a list of scores", .enabled(if: RUNALL)) |
| 26 | + func testPersonalTopThreeFromAListOfScores() { |
| 27 | + var hs = HighScores(scores: [10, 30, 90, 30, 100, 20, 10, 0, 30, 40, 40, 70, 70]) |
| 28 | + #expect(hs.topThree == [100, 90, 70]) |
| 29 | + } |
| 30 | + |
| 31 | + @Test("Personal top highest to lowest", .enabled(if: RUNALL)) |
| 32 | + func testPersonalTopHighestToLowest() { |
| 33 | + var hs = HighScores(scores: [20, 10, 30]) |
| 34 | + #expect(hs.topThree == [30, 20, 10]) |
| 35 | + } |
| 36 | + |
| 37 | + @Test("Personal top when there is a tie", .enabled(if: RUNALL)) |
| 38 | + func testPersonalTopWhenThereIsATie() { |
| 39 | + var hs = HighScores(scores: [40, 20, 40, 30]) |
| 40 | + #expect(hs.topThree == [40, 40, 30]) |
| 41 | + } |
| 42 | + |
| 43 | + @Test("Personal top when there are less than 3", .enabled(if: RUNALL)) |
| 44 | + func testPersonalTopWhenThereAreLessThan3() { |
| 45 | + var hs = HighScores(scores: [30, 70]) |
| 46 | + #expect(hs.topThree == [70, 30]) |
| 47 | + } |
| 48 | + |
| 49 | + @Test("Personal top when there is only one", .enabled(if: RUNALL)) |
| 50 | + func testPersonalTopWhenThereIsOnlyOne() { |
| 51 | + var hs = HighScores(scores: [40]) |
| 52 | + #expect(hs.topThree == [40]) |
| 53 | + } |
| 54 | + |
| 55 | + @Test("Latest score after personal top scores", .enabled(if: RUNALL)) |
| 56 | + func testLatestScoreAfterPersonalTopScores() { |
| 57 | + var hs = HighScores(scores: [70, 50, 20, 30]) |
| 58 | + hs.topThree |
| 59 | + #expect(hs.latest == 30) |
| 60 | + } |
| 61 | + |
| 62 | + @Test("Scores after personal top scores", .enabled(if: RUNALL)) |
| 63 | + func testScoresAfterPersonalTopScores() { |
| 64 | + var hs = HighScores(scores: [30, 50, 20, 70]) |
| 65 | + hs.topThree |
| 66 | + #expect(hs.scores == [30, 50, 20, 70]) |
| 67 | + } |
| 68 | + |
| 69 | + @Test("Latest score after personal best", .enabled(if: RUNALL)) |
| 70 | + func testLatestScoreAfterPersonalBest() { |
| 71 | + var hs = HighScores(scores: [20, 70, 15, 25, 30]) |
| 72 | + hs.personalBest |
| 73 | + #expect(hs.latest == 30) |
| 74 | + } |
| 75 | + |
| 76 | + @Test("Scores after personal best", .enabled(if: RUNALL)) |
| 77 | + func testScoresAfterPersonalBest() { |
| 78 | + var hs = HighScores(scores: [20, 70, 15, 25, 30]) |
| 79 | + hs.personalBest |
| 80 | + #expect(hs.scores == [20, 70, 15, 25, 30]) |
| 81 | + } |
| 82 | + |
| 83 | +} |
0 commit comments