Skip to content

Commit 9026e12

Browse files
committed
add code coverage
1 parent 6dcaccf commit 9026e12

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

Sources/Day05.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ struct Day05: AdventDay {
1212
let parts = data.split(separator: "\n\n")
1313
rules = [Int: [Int]]()
1414
for line in parts[0].lines() {
15-
let parts = line.split(separator: "|")
16-
let before = Int(parts[0]) ?? 0
17-
let after = Int(parts[1]) ?? 0
15+
let parts = line.integers(separator: "|")
16+
let before = parts[0]
17+
let after = parts[1]
1818
rules[after, default: [Int]()].append(before)
1919
}
2020
updates = parts[1].lines().map { $0.integers(separator: ",") }

Sources/Day06.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,25 @@ struct Day06: AdventDay {
9999
if wrappedOffset == 0 {
100100
if c[c.startIndex].x > c[c.endIndex - 1].x {
101101
let coord = Coord(x: c[c.startIndex].x - 1, y: c[c.endIndex - 1].y)
102-
print("yes 0", coord)
103102
return coord
104103
}
105104
}
106105
if wrappedOffset == 1 {
107106
if c[c.startIndex].y > c[c.endIndex - 1].y {
108107
let coord = Coord(x: c[c.startIndex].x, y: c[c.startIndex].y - 1)
109-
print("yes 1", coord)
110108
return coord
111109
}
112110
}
113111
if wrappedOffset == 2 {
114112

115113
if c[c.startIndex].x < c[c.endIndex - 1].x {
116114
let coord = Coord(x: c[c.endIndex - 1].x + 1, y: c[c.startIndex].y)
117-
print("yes 2", coord)
118115
return coord
119116
}
120117
}
121118
if wrappedOffset == 3 {
122119
if c[c.startIndex].y < c[c.endIndex - 1].y {
123120
let coord = Coord(x: c[c.endIndex - 1].x, y: c[c.startIndex].y + 1)
124-
print("yes 3", coord)
125121
return coord
126122
}
127123
}
@@ -143,22 +139,19 @@ struct Day06: AdventDay {
143139
if offset > 4 {
144140

145141
// TODO: this is not right
146-
for (idx, elem) in obstacles[0...offset].enumerated() {
147-
print("trying", idx, elem)
142+
for (_, elem) in obstacles[0...offset].enumerated() {
148143
let wrappedOffset = offset % 4
149144
c[3] = elem
150145
if let coord = isAValidLoop(wrappedOffset: wrappedOffset, c: c) {
151146
if steps.contains(coord) {
152147
count += 1
153148
newObstacles.append(coord)
154-
print(c)
155149
}
156150
}
157151
}
158152

159153
}
160154
}
161-
print(newObstacles)
162155

163156
// 115 -> too low
164157
return count

Sources/Day07.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ struct Day07: AdventDay {
4141
res *= value
4242
}
4343
}
44-
// print(calibration, "->", res)
4544
if res == calibration.result {
4645

4746
// early from the loop
@@ -81,9 +80,7 @@ struct Day07: AdventDay {
8180
res = Int(String(res) + String(value)) ?? 0
8281
}
8382
}
84-
// print(calibration, "->", res)
8583
if res == calibration.result {
86-
8784
// early from the loop
8885
return true
8986
}

Sources/Day09.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ struct Day09: AdventDay {
9595
// increment the pointer
9696
pointer += file.capacity
9797
if disk.count == 0 {
98-
print("we are done here !")
9998
break
10099
}
101100
continue

Tests/Extensions/String+Parsing.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ struct StringExtensions {
3131
#expect("a 1 toto 1.3".doubles() == [1.0, 1.3])
3232
#expect("1 2 3 4".integers() == [1, 2, 3, 4])
3333
}
34+
35+
@Test func testCharacterGrid() async throws {
36+
#expect(
37+
"""
38+
abc
39+
def
40+
""".toCharacterGrid() == [["a", "b", "c"], ["d", "e", "f"]])
41+
}
3442
}

Tests/Helpers/Coord.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Testing
2+
3+
@testable import aoc
4+
5+
@Suite("Coord")
6+
struct CoordTest {
7+
@Test("Initialize Coord")
8+
func testInit() async throws {
9+
let coord = Coord(rawValue: "0,0")
10+
#expect(coord?.x == 0)
11+
#expect(coord?.y == 0)
12+
}
13+
14+
@Test("Description")
15+
func testDescription() async throws {
16+
let coord = Coord(x: 2, y: 3)
17+
#expect("\(coord)" == "2,3")
18+
}
19+
20+
@Test func testDivision() async throws {
21+
#expect(Coord(x: 2, y: 4) / 2 == Coord(x: 1, y: 2))
22+
}
23+
}

0 commit comments

Comments
 (0)