DayByDayTests/CardLineTests.swift
32 lines · 1204 bytes
5 symbols in this file
1import Testing
2@testable import DayByDay
3
4struct CardLineTests {
5 @Test func animalLines() {
6 #expect(LearnAnimal.cow.cardLine == "Cow! Cows say moo.")
7 #expect(LearnAnimal.fish.cardLine == "Fish! Fish swim in water.")
8 #expect(LearnAnimal.allCases.allSatisfy { $0.cardLine.hasPrefix("\($0.name)! ") && $0.fact.hasSuffix(".") })
9 }
10
11 @Test func letterLines() {
12 #expect(LearnLetter.b.cardLine == "b. b is for ball.")
13 #expect(LearnLetter.allCases.allSatisfy { $0.cardLine.contains($0.exampleWord) })
14 }
15
16 @Test func lineQueueKeepsOnlyLatest() {
17 var q = LineQueue()
18 let first = q.next()
19 let second = q.next()
20 #expect(!q.isCurrent(first))
21 #expect(q.isCurrent(second))
22 q.cancel()
23 #expect(!q.isCurrent(second))
24 }
25
26 /// A card's line waits for whichever sound is still playing, its own or an earlier card's.
27 @Test func lineWaitsForEarlierSound() {
28 #expect(abs(CardVoice.delay(newSound: 0, earlierSound: 1.1) - 1.3) < 1e-9)
29 #expect(abs(CardVoice.delay(newSound: 0.9, earlierSound: 0.4) - 1.1) < 1e-9)
30 #expect(CardVoice.delay(newSound: 0, earlierSound: 0) == 0)
31 }
32}