DayByDayTests/MascotMotionTests.swift
48 lines · 2118 bytes
4 symbols in this file
1import Testing
2@testable import DayByDay
3
4struct MascotMotionTests {
5 @Test func blinksOncePerCycle() {
6 #expect(MascotMotion.pose(.idle, at: 1.0).eyeOpen == 1)
7 #expect(MascotMotion.pose(.idle, at: 3.75).eyeOpen == 0.1)
8 #expect(MascotMotion.pose(.idle, at: 3.85).eyeOpen == 1)
9 #expect(MascotMotion.pose(.idle, at: 7.55).eyeOpen == 0.1)
10 }
11
12 @Test func cheerHopsThenRests() {
13 #expect(MascotMotion.pose(.cheering, at: 0.2).hop < 0)
14 #expect(MascotMotion.pose(.cheering, at: 2.0).hop == 0)
15 #expect(MascotMotion.pose(.cheering, at: 4.2).hop < 0)
16 #expect(MascotMotion.pose(.cheering, at: 0.2).wing == 130)
17 }
18
19 @Test func waveSwingsThenHolds() {
20 let swings = [0.1, 0.3, 0.5].map { MascotMotion.pose(.waving, at: $0).wing }
21 #expect(Set(swings).count == 3)
22 #expect(MascotMotion.pose(.waving, at: 3.0).wing == 135)
23 #expect(MascotMotion.pose(.idle, at: 0.3).wing == 0)
24 }
25
26 @Test(arguments: MascotMood.allCases) func stillPosesDoNotMove(_ mood: MascotMood) {
27 let pose = MascotMotion.still(mood)
28 #expect(pose.bob == 0)
29 #expect(pose.hop == 0)
30 #expect(pose.eyeOpen == 1)
31 #expect(pose.beakOpen == (mood == .asking ? 1 : 0))
32 #expect(pose.wing == [.cheering: 130, .waving: 135][mood, default: 0])
33 #expect(pose.tilt == [.asking: 4, .puzzled: -10][mood, default: 0])
34 }
35
36 @Test(arguments: MascotMood.allCases) func poseValuesInRange(_ mood: MascotMood) {
37 for t in [-5, 0, 0.37, 1e6] {
38 let pose = MascotMotion.pose(mood, at: t)
39 #expect((0...1).contains(pose.eyeOpen), "\(mood) \(t)")
40 #expect((0...1).contains(pose.beakOpen), "\(mood) \(t)")
41 #expect((-0.06...0).contains(pose.hop), "\(mood) \(t)")
42 #expect((-0.012...0).contains(pose.bob), "\(mood) \(t)")
43 #expect((0...150).contains(pose.wing), "\(mood) \(t)")
44 if mood == .waving { #expect(pose.wing >= 120, "\(t)") }
45 }
46 #expect(MascotMotion.pose(mood, at: -5) == MascotMotion.pose(mood, at: 0))
47 }
48}