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

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

31 lines · 1283 bytes

3 symbols in this file
 1import Foundation
 2import Testing
 3@testable import DayByDay
 4
 5struct YearWheelTests {
 6    @Test func monthAtRotation() {
 7        #expect(YearWheel.month(atRotation: 0) == .january)
 8        #expect(YearWheel.month(atRotation: 30) == .december)
 9        #expect(YearWheel.month(atRotation: -30) == .february)
10        #expect(YearWheel.month(atRotation: 360 * 7 + 30) == .december)
11        #expect(YearWheel.month(atRotation: -360 * 5 - 60) == .march)
12        // Within half a wedge of a center still counts as that month.
13        #expect(YearWheel.month(atRotation: 14) == .january)
14        #expect(YearWheel.month(atRotation: 16) == .december)
15    }
16
17    @Test(arguments: MonthOfYear.allCases) func targetLandsOnMonth(_ m: MonthOfYear) {
18        for rotation in [0, 47.5, -800, 12345] {
19            let t = YearWheel.target(from: rotation, landingOn: m, turns: 3)
20            #expect(t >= rotation + 1080)
21            #expect(t < rotation + 1080 + 360)
22            #expect(YearWheel.month(atRotation: t) == m)
23            #expect(abs(t / 30 - (t / 30).rounded()) < 1e-9)
24        }
25    }
26
27    @Test func landingLine() {
28        #expect(YearWheel.line(for: .july) == "July! July is in summer.")
29        #expect(YearWheel.line(for: .december) == "December! December is in winter.")
30    }
31}