Skip to content

Commit d01a870

Browse files
committed
add tests and cleanup code
1 parent 53778a9 commit d01a870

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

Sources/Day11.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Algorithms
33
struct Day11: AdventDay {
44
var data: String
55

6-
func getStones(data: String) -> [Int: Int] {
6+
static func getStones(data: String) -> [Int: Int] {
77
var stones = [Int: Int]()
88
data.trimmed().integers().forEach { stone in
99
stones[stone, default: 0] += 1
@@ -12,7 +12,7 @@ struct Day11: AdventDay {
1212
}
1313

1414
func stoneMe(blinks: Int) -> Int {
15-
var stones = getStones(data: data)
15+
var stones = Self.getStones(data: data)
1616
for _ in 0..<blinks {
1717
var newStones = [Int: Int]()
1818
for (stone, count) in stones {

Tests/Day11.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ import Testing
55
@Suite("Day11")
66
struct Day11Tests {
77

8+
let testData = """
9+
125 17
10+
"""
11+
12+
@Test("Get stones")
13+
func testGetStones() async throws {
14+
#expect(Day11.getStones(data: testData) == [125: 1, 17: 1])
15+
}
16+
817
@Test("part1")
918
func testPart1() async throws {
1019
let challenge = Day11(
11-
data: """
12-
125 17
13-
"""
20+
data: testData
1421
)
1522
#expect(challenge.part1() == 55312)
1623
}

0 commit comments

Comments
 (0)