DayByDayTests/QuizItemTests.swift
77 lines · 3062 bytes
12 symbols in this file
1import Testing
2@testable import DayByDay
3
4struct QuizItemTests {
5 @Test func everyGridCategoryHasItems() {
6 for category in Category.gridCases {
7 #expect(!category.quizItems.isEmpty)
8 }
9 }
10
11 @Test func gridExcludesToday() {
12 #expect(!Category.gridCases.contains(.today))
13 #expect(Category.gridCases.count == 11)
14 }
15
16 @Test func idsAreUniqueAndStable() {
17 let all = Category.gridCases.flatMap(\.quizItems)
18 #expect(Set(all.map(\.id)).count == all.count)
19 #expect(Category.days.quizItems[2] == QuizItem(id: "days.tuesday", name: "Tuesday", category: .days))
20 }
21
22 @Test func lettersUseSpokenName() {
23 #expect(Category.alphabet.quizItems.first?.name == "a")
24 }
25}
26
27struct ItemSetTests {
28 static let pinned: [DayByDay.Category: String] = [
29 .days: "sunday monday tuesday wednesday thursday friday saturday",
30 .months: "january february march april may june july august september october november december",
31 .seasons: "spring summer fall winter",
32 .numbers: "one two three four five six seven eight nine ten",
33 .colors: "red orange yellow green blue purple pink brown black white",
34 .shapes: "circle square triangle star heart oval diamond rectangle",
35 .animals: "cat dog bird fish rabbit turtle ladybug cow duck sheep pig",
36 .alphabet: "a b c d e f g h i j k l m n o p q r s t u v w x y z",
37 .weather: "sunny cloudy rainy snowy windy stormy foggy rainbow",
38 .bodyParts: "head eyes ears nose mouth hands fingers arms legs feet heart belly",
39 .food: "apple banana carrot strawberry grapes lemon broccoli watermelon cherry orange corn pear",
40 ]
41
42 /// Answer history is keyed by these IDs; renaming a case orphans it.
43 @Test(arguments: DayByDay.Category.gridCases) func idsArePinned(_ c: DayByDay.Category) {
44 let names = Self.pinned[c]!.split(separator: " ")
45 #expect(c.quizItems.map(\.id) == names.map { "\(c.key).\($0)" })
46 }
47
48 @Test func itemAndValueRoundTrip() {
49 let cow = DayByDay.Category.animals.item(LearnAnimal.cow)
50 #expect(cow.name == "Cow")
51 #expect(cow.value(LearnAnimal.self) == .cow)
52 #expect(cow.value(LearnFood.self) == nil)
53 }
54
55 @Test func flyers() {
56 #expect(LearnAnimal.allCases.filter(\.canFly) == [.bird, .ladybug, .duck])
57 }
58
59 @Test func vegetables() {
60 #expect(LearnFood.allCases.filter { !$0.isFruit } == [.carrot, .broccoli, .corn])
61 }
62
63 @Test func roundShapes() {
64 #expect(LearnShape.allCases.filter { $0.hasCorners == false } == [.circle, .oval])
65 #expect(LearnShape.heart.hasCorners == nil)
66 }
67
68 @Test func exampleWordsStartWithTheirLetter() {
69 for letter in LearnLetter.allCases where letter != .x {
70 #expect(letter.exampleWord.first == letter.spokenName.first, "\(letter)")
71 }
72 }
73
74 @Test func drawnAnimalsHaveNoSymbol() {
75 #expect(LearnAnimal.allCases.filter { $0.symbol == nil } == [.cow, .duck, .sheep, .pig])
76 }
77}