2024-12-17 06:14:34 +01:00
|
|
|
(defpackage :aoc/2024/17/tests
|
2024-12-17 15:55:20 +01:00
|
|
|
(:use :cl :aoc :aoc/tests :aoc/2024/tests :parachute :aoc/2024/17 :arrow-macros))
|
2024-12-17 06:14:34 +01:00
|
|
|
|
|
|
|
(in-package :aoc/2024/17/tests)
|
|
|
|
|
|
|
|
(define-test suite-2024-17
|
|
|
|
;:parent suite-2024
|
2024-12-17 15:55:20 +01:00
|
|
|
)
|
2024-12-17 06:14:34 +01:00
|
|
|
|
2024-12-17 15:55:20 +01:00
|
|
|
(define-test test-adv
|
|
|
|
:parent suite-2024-17
|
2024-12-17 06:14:34 +01:00
|
|
|
|
2024-12-17 15:55:20 +01:00
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :a 4 :mem #(0 1)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 2 (cpu-a cpu))
|
|
|
|
(is = 0 (cpu-b cpu))
|
|
|
|
(is = 0 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out)
|
|
|
|
)
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :a 256 :b 7 :mem #(0 5)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 2 (cpu-a cpu))
|
|
|
|
(is = 7 (cpu-b cpu))
|
|
|
|
(is = 0 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out)
|
|
|
|
)
|
|
|
|
)
|
2024-12-17 06:14:34 +01:00
|
|
|
|
2024-12-17 15:55:20 +01:00
|
|
|
(define-test test-bxl
|
|
|
|
:parent suite-2024-17
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :b 4 :mem #(1 7)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 0 (cpu-a cpu))
|
|
|
|
(is = 3 (cpu-b cpu))
|
|
|
|
(is = 0 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out)
|
|
|
|
))
|
2024-12-17 06:14:34 +01:00
|
|
|
|
2024-12-17 15:55:20 +01:00
|
|
|
(define-test test-bst
|
|
|
|
:parent suite-2024-17
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :b 4 :mem #(2 3)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 0 (cpu-a cpu))
|
|
|
|
(is = 3 (cpu-b cpu))
|
|
|
|
(is = 0 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out)
|
|
|
|
)
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :a 89 :b 4 :mem #(2 4)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 89 (cpu-a cpu))
|
|
|
|
(is = 1 (cpu-b cpu))
|
|
|
|
(is = 0 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out)
|
|
|
|
)
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :b 13 :mem #(2 5)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 0 (cpu-a cpu))
|
|
|
|
(is = 5 (cpu-b cpu))
|
|
|
|
(is = 0 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out)
|
|
|
|
)
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :b 4 :c 69 :mem #(2 6)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 0 (cpu-a cpu))
|
|
|
|
(is = 5 (cpu-b cpu))
|
|
|
|
(is = 69 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out)
|
|
|
|
)
|
|
|
|
)
|
2024-12-17 06:14:34 +01:00
|
|
|
|
2024-12-17 15:55:20 +01:00
|
|
|
(define-test test-jnz
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :b 4 :c 69 :mem #(3 69)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 0 (cpu-a cpu))
|
|
|
|
(is = 5 (cpu-b cpu))
|
|
|
|
(is = 69 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out)
|
|
|
|
)
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :b 4 :c 69 :mem #(2 6)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 0 (cpu-a cpu))
|
|
|
|
(is = 5 (cpu-b cpu))
|
|
|
|
(is = 69 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
(define-test test-bdv
|
|
|
|
:parent suite-2024-17
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :a 4 :mem #(6 1)) '())
|
|
|
|
(is = (cpu-ip cpu) 2)
|
|
|
|
(is = (cpu-a cpu) 4)
|
|
|
|
(is = (cpu-b cpu) 2)
|
|
|
|
(is = (cpu-c cpu) 0)
|
|
|
|
(is eq (cpu-state cpu) :running)
|
|
|
|
(is equal out '()))
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :a 256 :b 7 :mem #(6 5)) '())
|
|
|
|
(is = (cpu-ip cpu) 2)
|
|
|
|
(is = (cpu-a cpu) 256)
|
|
|
|
(is = 2 (cpu-b cpu))
|
|
|
|
(is = 0 (cpu-c cpu))
|
|
|
|
(is eq (cpu-state cpu) :running)
|
|
|
|
(is equal out '()))
|
|
|
|
)
|
|
|
|
|
|
|
|
(define-test tet-cdv
|
|
|
|
:parent suite-2024-17
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :a 4 :mem #(7 1)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 4 (cpu-a cpu))
|
|
|
|
(is = 0 (cpu-b cpu))
|
|
|
|
(is = 2 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out))
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(instruction-cycle (make-cpu :a 256 :b 7 :mem #(7 5)) '())
|
|
|
|
(is = 2 (cpu-ip cpu))
|
|
|
|
(is = 256 (cpu-a cpu))
|
|
|
|
(is = 7 (cpu-b cpu))
|
|
|
|
(is = 2 (cpu-c cpu))
|
|
|
|
(is eq :running (cpu-state cpu))
|
|
|
|
(is equal '() out))
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-test test-cpu
|
|
|
|
:parent suite-2024-17
|
|
|
|
;; If register C contains 9, the program 2,6 would set register B to 1.
|
|
|
|
(multiple-value-bind (cpu)
|
|
|
|
|
|
|
|
(instruction-cycle (make-cpu :c 9 :mem #(2 6)) '())
|
|
|
|
(is = 1 (cpu-b cpu)))
|
|
|
|
|
|
|
|
;; If register A contains 10, the program 5,0,5,1,5,4 would output 0,1,2
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(run-program (make-cpu :a 10 :mem #(5 0 5 1 5 4)))
|
|
|
|
(is equal :halted (cpu-state cpu))
|
|
|
|
(is equal '(0 1 2) out))
|
|
|
|
|
|
|
|
;; If register A contains 2024, the program 0,1,5,4,3,0 would output 4,2,5,6,7,7,7,7,3,1,0 and leave 0 in register A.
|
|
|
|
(multiple-value-bind (cpu out)
|
|
|
|
(run-program (make-cpu :a 2024 :mem #(0 1 5 4 3 0)))
|
|
|
|
(is = 0 (cpu-a cpu))
|
|
|
|
(is equal '(4 2 5 6 7 7 7 7 3 1 0) out))
|
|
|
|
|
|
|
|
;; If register B contains 29, the program 1,7 would set register B to 26.
|
|
|
|
(multiple-value-bind (cpu)
|
|
|
|
(run-program (make-cpu :b 29 :mem #(1 7)))
|
|
|
|
(is = 26 (cpu-b cpu)))
|
|
|
|
|
|
|
|
;; If register B contains 2024 and register C contains 43690, the program 4,0 would set register B to 44354.
|
|
|
|
(multiple-value-bind (cpu)
|
|
|
|
(run-program (make-cpu :b 2024 :c 43690 :mem #(4 0)))
|
|
|
|
(is = 44354 (cpu-b cpu))))
|
2024-12-17 06:14:34 +01:00
|
|
|
|
|
|
|
(define-test+run test-part1
|
2024-12-17 15:55:20 +01:00
|
|
|
:parent suite-2024-17
|
|
|
|
(is equal "4,6,3,5,6,3,5,2,1,0" (part1 sample-data)))
|
2024-12-17 06:14:34 +01:00
|
|
|
|
|
|
|
(define-test+run test-part2
|
|
|
|
:parent suite-2024-17
|
|
|
|
(is equal nil (part2 sample-data)))
|