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

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

68 lines · 2660 bytes

10 symbols in this file
 1import Foundation
 2import Testing
 3@testable import DayByDay
 4
 5struct ProgressSummaryTests {
 6    let start = Date(timeIntervalSince1970: 1_800_000_000)
 7
 8    /// Each known item gets two right answers; each missed item one miss.
 9    func summary(_ category: DayByDay.Category, known: [Int] = [], missed: [Int] = [], extra: [AnswerFact] = []) -> ProgressSummary {
10        let items = category.quizItems
11        var facts = extra
12        for i in known {
13            facts += [AnswerFact(itemID: items[i].id, isCorrect: true, timestamp: start),
14                      AnswerFact(itemID: items[i].id, isCorrect: true, timestamp: start + 300)]
15        }
16        for i in missed {
17            facts.append(AnswerFact(itemID: items[i].id, isCorrect: false, timestamp: start + Double(i)))
18        }
19        return ProgressSummary(category: category, progress: ItemProgress(facts))
20    }
21
22    @Test func notPlayed() {
23        let s = summary(.food)
24        #expect(s.known == "Not played yet.")
25        #expect(s.missing == nil)
26    }
27
28    @Test func knowsAll() {
29        let s = summary(.seasons, known: [0, 1, 2, 3])
30        #expect(s.known == "Knows all 4 seasons.")
31        #expect(s.missing == nil)
32    }
33
34    @Test func knowsSome() {
35        #expect(summary(.days, known: [0, 1, 2, 3, 4]).known == "Knows 5 of 7 days.")
36        #expect(summary(.weather, known: [0]).known?.hasSuffix("kinds of weather.") == true)
37    }
38
39    @Test func mixingUpList() {
40        let s = summary(.months, known: [0], missed: [7, 5, 6])
41        #expect(s.known == "Knows 1 of 12 months.")
42        #expect(s.missing == "Still mixing up June, July and August.")
43        #expect(summary(.months, missed: [5]).known == nil)
44    }
45
46    @Test func twoItemsUseAnd() {
47        #expect(summary(.days, missed: [3, 4]).missing == "Still mixing up Wednesday and Thursday.")
48        #expect(summary(.days, missed: [4]).missing == "Still mixing up Thursday.")
49    }
50
51    @Test func longListTruncates() {
52        let s = summary(.alphabet, missed: [1, 3, 15, 16, 20, 21])
53        #expect(s.missing == "Still mixing up B, D, P, Q and 2 more.")
54    }
55
56    @Test func unknownIDsIgnored() {
57        let old = [AnswerFact(itemID: "lizard", isCorrect: false, timestamp: start)]
58        #expect(summary(.animals, extra: old).known == "Not played yet.")
59        #expect(summary(.animals, known: [0], extra: old).missing == nil)
60    }
61
62    @Test func justStarted() {
63        let once = [AnswerFact(itemID: DayByDay.Category.days.quizItems[1].id, isCorrect: true, timestamp: start)]
64        let s = summary(.days, extra: once)
65        #expect(s.known == "Just started.")
66        #expect(s.missing == nil)
67    }
68}