add tests for day 6

This commit is contained in:
Peter Tillemans 2024-11-18 14:08:48 +01:00
parent c11655d2e1
commit eb85c317a6
3 changed files with 52 additions and 3 deletions

View file

@ -10,10 +10,12 @@
:source-control "https://forge.snamellit.com/pti/aoc-cl" :source-control "https://forge.snamellit.com/pti/aoc-cl"
:depends-on (#:dexador :depends-on (#:dexador
#:plump #:plump
#:lquery) #:lquery
#:fiveam)
:components ((:module "src" :components ((:module "src"
:components :components
((:file "main")))) ((:file "main")
(:file "2018/day06"))))
:description "Advent of Code challenges and solutions." :description "Advent of Code challenges and solutions."
:long-description "Solutions for the AOC challenges." :long-description "Solutions for the AOC challenges."
:in-order-to ((test-op (test-op "aoc/tests")))) :in-order-to ((test-op (test-op "aoc/tests"))))

44
src/2018/day06.lisp Normal file
View file

@ -0,0 +1,44 @@
(defpackage :aoc/2018/06
(:use :cl :aoc :fiveam))
(in-package :aoc/2018/06)
(defvar test-data (test-input 2018 6))
(defstruct point-2d
(x 0 :type fixnum)
(y 0 :type fixnum))
(defvar sample-data '((1 1)
(1 6)
(8 3)
(3 4)
(5 5)
(8 9)))
(defun make-points (data)
(map 'list (lambda (p) (make-point-2d :x (first p) :y (second p))) data))
(defvar sample-points (make-points sample-data))
(defun top-left (points)
(let ((x-min (apply #'min (map 'list #'point-2d-x points) ))
(y-min (apply #'min (map 'list #'point-2d-y points) )))
(make-point-2d :x x-min :y y-min)))
(defun bottom-right (points)
(let ((x-max (apply #'max (map 'list #'point-2d-x points) ))
(y-max (apply #'max (map 'list #'point-2d-y points) )))
(make-point-2d :x x-max :y y-max)))
(def-suite 2018-day-6)
(in-suite 2018-day-6)
(test find-top-left
(let ((result (top-left sample-points)))
(is (equalp (make-point-2d :x 1 :y 1) result))))
(test find-bottom-right
(let ((result (bottom-right sample-points)))
(is (equalp (make-point-2d :x 8 :y 9) result))))

View file

@ -1,5 +1,8 @@
(defpackage aoc (defpackage aoc
(:use :cl)) (:use :cl)
(:export
#:test-input))
(in-package :aoc) (in-package :aoc)
(defun load-ql-dependencies () (defun load-ql-dependencies ()