DayByDayTests/MascotStateTests.swift
50 lines · 1414 bytes
6 symbols in this file
1import Testing
2@testable import DayByDay
3
4struct MascotStateTests {
5 @Test func eventsMapToMoods() {
6 var s = MascotState()
7 #expect(s.mood == .idle)
8 s.handle(.prompt("Find it!"))
9 #expect(s.mood == .asking)
10 s.handle(.correct)
11 #expect(s.mood == .cheering)
12 s.handle(.wrong)
13 #expect(s.mood == .puzzled)
14 s.handle(.greet)
15 #expect(s.mood == .waving)
16 }
17
18 @Test func promptHoldCoversDelayAndWords() {
19 #expect(abs(MascotState.hold(for: .prompt("Can you find Monday?", after: 1.0)) - 3.3) < 1e-9)
20 #expect(MascotState.hold(for: .correct) == 1.8)
21 #expect(MascotState.hold(for: .wrong) == 1.6)
22 #expect(MascotState.hold(for: .greet) == 2.4)
23 }
24
25 @Test func emptyPromptSettles() {
26 var s = MascotState()
27 s.handle(.prompt(""))
28 #expect(s.hold == 0.5)
29 s.settle(s.ticket)
30 #expect(s.mood == .idle)
31 }
32
33 @Test func settleReturnsToIdle() {
34 var s = MascotState()
35 s.handle(.wrong)
36 #expect(s.hold == 1.6)
37 s.settle(s.ticket)
38 #expect(s.mood == .idle)
39 }
40
41 @Test func newerEventWins() {
42 var s = MascotState()
43 s.handle(.correct)
44 let first = s.ticket
45 s.handle(.prompt("Can you find Monday?"))
46 s.settle(first)
47 #expect(s.mood == .asking)
48 #expect(s.ticket != first)
49 }
50}