(ns edition2022.day9-test
(:require [clojure.test :refer :all]
[edition2022.day9 :refer :all]))
(deftest rope-movement
(testing "vertical movement"
(is (=
(move-rope [[0 0] [0 0]] [0 1])
[[0 1] [0 0]]))
(is (=
(move-rope [[0 1] [0 0]] [0 1])
[[0 2] [0 1]]))
(is (=
(move-rope [[0 1] [0 0]] [0 -1])
[[0 0] [0 0]]))
(is (=
(move-rope [[0 0] [0 0]] [0 -1])
[[0 -1] [0 0]]))
(is (=
(move-rope [[0 -1] [0 0]] [0 -1])
[[0 -2] [0 -1]])))
(testing "horizontal movement"
(is (=
(move-rope [[0 0] [0 0]] [1 0])
[[1 0] [0 0]]))
(is (=
(move-rope [[1 0] [0 0]] [1 0])
[[2 0] [1 0]]))
(is (=
(move-rope [[1 0] [0 0]] [-1 0])
[[0 0] [0 0]]))
(is (=
(move-rope [[0 0] [0 0]] [-1 0])
[[-1 0] [0 0]]))
(is (=
(move-rope [[-1 0] [0 0]] [-1 0])
[[-2 0] [-1 0]])))
(testing "movement that ends up in diagonal"
(testing "vertical"
(is (=
(move-rope [[1 0] [0 0]] [0 1])
[[1 1] [0 0]]))
(is (=
(move-rope [[-1 0] [0 0]] [0 1])
[[-1 1] [0 0]]))
(is (=
(move-rope [[1 0] [0 0]] [0 -1])
[[1 -1] [0 0]]))
(is (=
(move-rope [[-1 0] [0 0]] [0 -1])
[[-1 -1] [0 0]])))
(testing "horizontal"
(is (=
(move-rope [[0 1] [0 0]] [1 0])
[[1 1] [0 0]]))
(is (=
(move-rope [[0 -1] [0 0]] [1 0])
[[1 -1] [0 0]]))
(is (=
(move-rope [[0 1] [0 0]] [-1 0])
[[-1 1] [0 0]]))
(is (=
(move-rope [[0 -1] [0 0]] [-1 0])
[[-1 -1] [0 0]])))
)
(testing "diagonal movements"
(is (=
(move-rope [[1 1] [0 0]] [0 1])
[[1 2] [1 1]]))
(is (=
(move-rope [[1 1] [0 0]] [1 0])
[[2 1] [1 1]]))
(is (=
(move-rope [[-1 1] [0 0]] [0 1])
[[-1 2] [-1 1]]))
(is (=
(move-rope [[-1 1] [0 0]] [-1 0])
[[-2 1] [-1 1]]))
(is (=
(move-rope [[1 -1] [0 0]] [0 -1])
[[1 -2] [1 -1]]))
(is (=
(move-rope [[1 -1] [0 0]] [1 0])
[[2 -1] [1 -1]]))
(is (=
(move-rope [[-1 -1] [0 0]] [0 -1])
[[-1 -2] [-1 -1]]))
(is (=
(move-rope [[-1 -1] [0 0]] [-1 0])
[[-2 -1] [-1 -1]]))
)
)