krz/daybyday

iOS learning games for young children: days, months, seasons, numbers, letters, animals and more. education ios kids swift https://krz.sh/apps/daybyday/

DayByDayTests/SequencePuzzleTests.swift

main
daybyday/DayByDayTests/SequencePuzzleTests.swift history · blame · raw

88 lines · 3316 bytes

10 symbols in this file
 1import Testing
 2@testable import DayByDay
 3
 4struct SequencePuzzleTests {
 5    let days = DayByDay.Category.days
 6
 7    func day(_ d: DayOfWeek) -> QuizItem { days.item(d) }
 8
 9    func train(seed: UInt64 = 41) -> SequencePuzzle {
10        var rng = SeededGenerator(seed: seed)
11        return .weekTrain(using: &rng)
12    }
13
14    @Test func trainOrder() {
15        let p = train()
16        #expect(p.steps.map(\.answer) == DayOfWeek.allCases.map(day))
17        #expect(Set(p.pool) == Set(DayOfWeek.allCases.map(day)))
18        #expect(p.pool.count == 7)
19        #expect(p.steps[0].prompt == "Which day comes first?")
20        #expect(p.slotLabels == nil)
21    }
22
23    @Test(arguments: DayOfWeek.allCases) func yesterdayTomorrowWraps(_ today: DayOfWeek) {
24        var rng = SeededGenerator(seed: 42)
25        let p = SequencePuzzle.yesterdayTomorrow(today: today, using: &rng)
26        let i = today.rawValue
27        let expected = [(i + 6) % 7, i, (i + 1) % 7].map { day(DayOfWeek(rawValue: $0)!) }
28        #expect(p.steps.map(\.answer) == expected)
29        #expect(p.pool.count == 4)
30        #expect(Set(p.pool).count == 4)
31        #expect(Set(expected).isSubset(of: Set(p.pool)))
32        #expect(p.slotLabels == ["Yesterday", "Today", "Tomorrow"])
33        #expect(p.steps.map(\.prompt) == ["Which day was yesterday?", "Which day is today?", "Which day will it be tomorrow?"])
34    }
35
36    @Test func correctPlacementAdvances() {
37        var p = train()
38        #expect(p.place(day(.sunday)) == .correct)
39        #expect(p.placed == [day(.sunday)])
40        #expect(p.current?.prompt == "What comes after Sunday?")
41    }
42
43    @Test func wrongPlacementWaits() {
44        var p = train()
45        #expect(p.place(day(.tuesday)) == .incorrect(correctName: "Sunday"))
46        #expect(p.place(day(.sunday)) == .ignored)
47        p.resume()
48        #expect(p.place(day(.sunday)) == .correct)
49    }
50
51    @Test func placedCardIgnored() {
52        var p = train()
53        _ = p.place(day(.sunday))
54        #expect(p.place(day(.sunday)) == .ignored)
55        #expect(p.placed.count == 1)
56    }
57
58    @Test func solvedIgnoresInput() {
59        var p = train()
60        for d in DayOfWeek.allCases { #expect(p.place(day(d)) == .correct) }
61        #expect(p.isSolved)
62        #expect(p.current == nil)
63        #expect(p.place(day(.monday)) == .ignored)
64    }
65
66    @Test func corrections() {
67        var rng = SeededGenerator(seed: 43)
68        var p = SequencePuzzle.yesterdayTomorrow(today: .friday, using: &rng)
69        let wrong = p.pool.first { $0 != day(.thursday) }!
70        _ = p.place(wrong)
71        #expect(p.correction() == "Yesterday was Thursday. Try again!")
72        p.resume()
73        _ = p.place(day(.thursday))
74        #expect(p.correction() == "Today is Friday. Try again!")
75
76        var t = train()
77        #expect(t.correction() == "Sunday comes first. Try again!")
78        _ = t.place(day(.sunday))
79        #expect(t.correction() == "Monday comes next. Try again!")
80    }
81
82    @Test func solvedSummary() {
83        var rng = SeededGenerator(seed: 44)
84        #expect(SequencePuzzle.yesterdayTomorrow(today: .friday, using: &rng).summary
85                == "Yesterday was Thursday, today is Friday, and tomorrow will be Saturday!")
86        #expect(train().summary == "Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday!")
87    }
88}