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/SpokenLinesTests.swift

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

118 lines · 5340 bytes

9 symbols in this file
  1import Foundation
  2import Testing
  3@testable import DayByDay
  4
  5struct SpokenLinesTests {
  6    typealias Topic = DayByDay.Category
  7    static let all = SpokenLines.all
  8
  9    func covered(_ text: String) -> Bool {
 10        SpokenText.sentences(text).allSatisfy { Self.all.contains($0) }
 11    }
 12
 13    @Test func onlyListedNamesAreSpoken() {
 14        #expect(Set(Self.all.filter { $0.hasPrefix("Hi, ") }) == Set(Lines.spokenNames.map { "Hi, \($0)!" }))
 15        #expect(Lines.spokenNames.count == 17)
 16        #expect(Self.all.contains(Lines.greeting))
 17    }
 18
 19    @Test func catalogSize() {
 20        #expect((2_000...4_000).contains(Self.all.count), "\(Self.all.count)")
 21    }
 22
 23    /// Seeds the catalog did not use: every prompt and correction a game produces is covered.
 24    @Test func roundGamesAreCovered() {
 25        var rng = SeededGenerator(seed: 900)
 26        for c in Topic.gridCases {
 27            for game in c.games where game.usesRound {
 28                let source = c.questionSource(for: game)
 29                var previous: QuizItem?
 30                for i in 0..<2_000 {
 31                    let q = source.next(correctCount: i % 5, excluding: previous, using: &rng)
 32                    #expect(covered(q.prompt), "\(c) \(game): \(q.prompt)")
 33                    for choice in q.choices where choice != q.answer {
 34                        #expect(covered(q.correction(for: choice)), "\(c) \(game): \(q.correction(for: choice))")
 35                    }
 36                    previous = q.answer
 37                }
 38            }
 39        }
 40    }
 41
 42    @Test func routineIsCovered() {
 43        var calendar = Calendar(identifier: .gregorian)
 44        calendar.timeZone = TimeZone(identifier: "UTC")!
 45        var rng = SeededGenerator(seed: 901)
 46        var day = calendar.date(from: DateComponents(year: 2027, month: 1, day: 1, hour: 9))!
 47        for _ in 0..<365 {
 48            let birthday = (month: Int.random(in: 1...12, using: &rng), day: Int.random(in: 1...28, using: &rng))
 49            let picture = DayPictureKind.allCases.randomElement(using: &rng)
 50            for line in RoutineScript(date: day, calendar: calendar, name: "Maya", birthday: birthday, picture: picture).lines {
 51                #expect(covered(line.spoken), "\(line.spoken)")
 52            }
 53            day = calendar.date(byAdding: .day, value: 1, to: day)!
 54        }
 55        for w in TodayRoutineView.weathers { #expect(covered(Lines.sticker(w))) }
 56        #expect(covered(Lines.weatherQuestion))
 57    }
 58
 59    @Test func otherGamesAreCovered() {
 60        var rng = SeededGenerator(seed: 902)
 61        var train = SequencePuzzle.weekTrain(using: &rng)
 62        while let step = train.current {
 63            #expect(covered(step.prompt)); #expect(covered(train.correction()))
 64            _ = train.place(step.answer)
 65        }
 66        #expect(covered(train.summary))
 67        for today in DayOfWeek.allCases {
 68            var p = SequencePuzzle.yesterdayTomorrow(today: today, using: &rng)
 69            while let step = p.current {
 70                #expect(covered(step.prompt)); #expect(covered(p.correction()))
 71                _ = p.place(step.answer)
 72            }
 73            #expect(covered(p.summary))
 74        }
 75        for food in LearnFood.allCases {
 76            #expect(covered(SortRound.question(for: food)))
 77            #expect(covered("\(SortRound.fact(for: food)) Try again!"))
 78        }
 79        for part in LearnBodyPart.allCases { #expect(covered(part.command)) }
 80        for thing in CountingRound.things {
 81            #expect(covered(Lines.countPrompt(thing)))
 82            for n in 1...10 {
 83                let r = CountingRound(target: n, thing: thing, using: &rng)
 84                #expect(covered(r.summary()))
 85                #expect(covered(LearnNumber(rawValue: n)!.name))
 86            }
 87        }
 88        for item in Topic.shapes.quizItems + Topic.alphabet.quizItems {
 89            #expect(covered(Lines.tracePrompt(item)))
 90            #expect(covered(Lines.traceSuccess(item)))
 91            #expect(covered(Lines.traceMiss(item)))
 92        }
 93        for m in MonthOfYear.allCases { #expect(covered(YearWheel.line(for: m))) }
 94        #expect(covered(Lines.spinPrompt))
 95        for p in PraisePhrases.all { #expect(covered(p)) }
 96        for g in Game.allCases { #expect(covered(g.title)) }
 97        for line in [Lines.lookAndListen, Lines.whoIsPlaying, Lines.youDidIt, Lines.itsRaining] {
 98            #expect(covered(line))
 99        }
100    }
101
102    @Test func cardsAndCalendarAreCovered() {
103        for animal in LearnAnimal.allCases { #expect(covered(animal.cardLine)) }
104        for letter in LearnLetter.allCases { #expect(covered(letter.cardLine)) }
105        for day in DayOfWeek.allCases {
106            #expect(covered(Lines.dayCard(day, picture: nil)))
107            for kind in DayPictureKind.allCases { #expect(covered(Lines.dayCard(day, picture: kind))) }
108        }
109        for c in Topic.gridCases { for item in c.quizItems { #expect(covered(item.name)) } }
110        for color in LearnColor.allCases { #expect(covered(color.name)) }
111        for (i, month) in MonthOfYear.allCases.enumerated() {
112            for day in 1...ProfileStore.daysInMonth[i] {
113                #expect(covered(Lines.calendarDay(month, day, weather: nil)))
114                for w in TodayRoutineView.weathers { #expect(covered(Lines.calendarDay(month, day, weather: w))) }
115            }
116        }
117    }
118}