|
| 1 | +import Testing |
| 2 | + |
| 3 | +@testable import aoc |
| 4 | + |
| 5 | +@Suite("Day17") |
| 6 | +struct Day17Tests { |
| 7 | + let testData = """ |
| 8 | + Register A: 729 |
| 9 | + Register B: 0 |
| 10 | + Register C: 0 |
| 11 | +
|
| 12 | + Program: 0,1,5,4,3,0 |
| 13 | + """ |
| 14 | + |
| 15 | + @Test("parsing") |
| 16 | + func testParsing() async throws { |
| 17 | + let c = Day17(data: testData).initialize() |
| 18 | + let computer = Computer(instructions: c.instructions, registers: c.registers) |
| 19 | + |
| 20 | + #expect(computer.registers.A == 729) |
| 21 | + #expect(computer.registers.B == 0) |
| 22 | + #expect(computer.registers.C == 0) |
| 23 | + #expect(computer.instructions == [0, 1, 5, 4, 3, 0]) |
| 24 | + |
| 25 | + } |
| 26 | + |
| 27 | + @Test("Common operations") |
| 28 | + func testOperations() async throws { |
| 29 | + var c1 = Computer( |
| 30 | + instructions: [2, 6], registers: Registers(A: 0, B: 0, C: 9) |
| 31 | + ) |
| 32 | + #expect(c1.execute() == "") |
| 33 | + #expect( |
| 34 | + c1.registers.B == 1) |
| 35 | + |
| 36 | + var c2 = Computer( |
| 37 | + instructions: [5, 0, 5, 1, 5, 4], registers: Registers(A: 10, B: 0, C: 0) |
| 38 | + ) |
| 39 | + #expect(c2.execute() == "0,1,2") |
| 40 | + |
| 41 | + var c3 = Computer( |
| 42 | + instructions: [0, 1, 5, 4, 3, 0], registers: Registers(A: 2024, B: 0, C: 0) |
| 43 | + ) |
| 44 | + #expect(c3.execute() == "4,2,5,6,7,7,7,7,3,1,0") |
| 45 | + #expect(c3.registers.A == 0) |
| 46 | + |
| 47 | + var c4 = Computer( |
| 48 | + instructions: [1, 7], registers: Registers(A: 0, B: 29, C: 0) |
| 49 | + ) |
| 50 | + #expect(c4.execute() == "") |
| 51 | + #expect(c4.registers.B == 26) |
| 52 | + |
| 53 | + var c5 = Computer( |
| 54 | + instructions: [4, 0], registers: Registers(A: 0, B: 2024, C: 43690) |
| 55 | + ) |
| 56 | + #expect(c5.execute() == "") |
| 57 | + #expect(c5.registers.B == 44354) |
| 58 | + } |
| 59 | + |
| 60 | + @Test("part1") |
| 61 | + func testPart1() async throws { |
| 62 | + let challenge = Day17(data: testData) |
| 63 | + #expect(challenge.part1() == "4,6,3,5,6,3,5,2,1,0") |
| 64 | + } |
| 65 | + |
| 66 | + @Test("part2") |
| 67 | + func testPart2() async throws { |
| 68 | + let challenge = Day17(data: testData) |
| 69 | + #expect(challenge.part2() == 0) |
| 70 | + } |
| 71 | +} |
0 commit comments