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

062549ad26607ce9e973ed2a9a7ef6f853885f83
daybyday/DayByDayTests/DressUpTests.swift history · blame · raw

48 lines · 2090 bytes

4 symbols in this file
 1import Testing
 2import UIKit
 3@testable import DayByDay
 4
 5struct DressUpTests {
 6    @Test func onlyOneSuitableChoice() {
 7        var rng = SeededGenerator(seed: 81)
 8        var previous: QuizItem?
 9        var weathers = Set<LearnWeather>()
10        for i in 0..<300 {
11            let q = DressUp().next(correctCount: i % 5, excluding: previous, using: &rng)
12            let weather = q.shown[0].value(LearnWeather.self)!
13            weathers.insert(weather)
14            let suitable = q.choices.filter { Clothing.from($0)!.suits.contains(weather) }
15            #expect(suitable == [q.answer])
16            #expect((3...4).contains(q.choices.count))
17            #expect(q.answer != previous)
18            previous = q.answer
19        }
20        #expect(weathers == [.sunny, .rainy, .snowy, .windy])
21    }
22
23    @Test func promptShownAndFacts() {
24        var rng = SeededGenerator(seed: 82)
25        let q = DressUp().next(correctCount: 0, excluding: nil, using: &rng)
26        let weather = q.shown[0].value(LearnWeather.self)!
27        #expect(q.prompt == "It's \(weather.name.lowercased())! What should we wear?")
28        let wrong = q.choices.first { $0 != q.answer }!
29        #expect(q.correction(for: wrong) == "\(Clothing.from(wrong)!.fact) Try again!")
30        #expect(Clothing.umbrella.fact == "An umbrella is for rainy days.")
31        // Coat and jacket look alike, so neither is ever the wrong one beside the other.
32        #expect(Clothing.coat.suits == Clothing.jacket.suits)
33        // A coat is fine in the rain too, so it is never a wrong answer there.
34        #expect(Clothing.coat.suits.contains(.rainy))
35    }
36
37    @Test(arguments: Clothing.allCases) func symbolExists(_ c: Clothing) {
38        #expect(UIImage(systemName: c.symbol) != nil, "\(c.symbol)")
39    }
40
41    @Test func idsPinned() {
42        #expect(Clothing.allCases.map(\.item.id) == [
43            "clothing.sunglasses", "clothing.sunHat", "clothing.tshirt", "clothing.umbrella",
44            "clothing.coat", "clothing.jacket",
45        ])
46        #expect(Clothing.allCases.allSatisfy { Clothing.from($0.item) == $0 })
47    }
48}