diff options
| author | Jake Zerrer <him@jakezerrer.com> | 2025-11-26 15:10:20 -0500 |
|---|---|---|
| committer | Jake Zerrer <him@jakezerrer.com> | 2025-12-09 18:10:02 -0500 |
| commit | 02dce7d08f92b1d255e3afca33034f481d1371a7 (patch) | |
| tree | 18cebc9ab1ee73642ae1294b1c50173b977e29dc /test/unheard/cycles_test.clj | |
| parent | 34bdba657919a38d26f698024f37d649931ac368 (diff) | |
Diffstat (limited to 'test/unheard/cycles_test.clj')
| -rw-r--r-- | test/unheard/cycles_test.clj | 238 |
1 files changed, 60 insertions, 178 deletions
diff --git a/test/unheard/cycles_test.clj b/test/unheard/cycles_test.clj index c395755..552b6e9 100644 --- a/test/unheard/cycles_test.clj +++ b/test/unheard/cycles_test.clj @@ -3,278 +3,160 @@ [unheard.cycles :refer [l f p rate elongate rep paste unfold]])) (deftest unfold-tests - (testing "single scalar" - (is (= [[0 1 :a]] - (unfold 1 :a)))) - + (testing "single scalar" (is (= [[0 1 :a]] (unfold 1 :a)))) (testing "simple list - time subdivision" - (is (= [[0 1/3 :a] [1/3 2/3 :b] [2/3 1 :c]] - (unfold 1 (l :a :b :c))))) - + (is (= [[0 1/3 :a] [1/3 2/3 :b] [2/3 1 :c]] (unfold 1 (l :a :b :c))))) (testing "simple fork - cycles through children" - (is (= [[0 1 :a] - [1 2 :b] - [2 3 :c]] - (unfold 1 (f :a :b :c))))) - + (is (= [[0 1 :a] [1 2 :b] [2 3 :c]] (unfold 1 (f :a :b :c))))) (testing "list with fork - fork gets time slice" - (is (= [[0 1/2 :1] [1/2 1 :2] - [1 3/2 :1] [3/2 2 :3]] + (is (= [[0 1/2 :1] [1/2 1 :2] [1 3/2 :1] [3/2 2 :3]] (unfold 1 (l :1 (f :2 :3)))))) - (testing "fork with list - each child subdivides its cycle" - (is (= [[0 1/2 :a] [1/2 1 :b] - [1 2 :c]] - (unfold 1 (f (l :a :b) :c))))) - + (is (= [[0 1/2 :a] [1/2 1 :b] [1 2 :c]] (unfold 1 (f (l :a :b) :c))))) (testing "nested lists" - (is (= [[0 1/2 :a] [1/2 3/4 :b] [3/4 1 :c]] - (unfold 1 (l :a (l :b :c)))))) - + (is (= [[0 1/2 :a] [1/2 3/4 :b] [3/4 1 :c]] (unfold 1 (l :a (l :b :c)))))) (testing "nested forks" - (is (= [[0 1 :a] - [1 2 :b] - [2 3 :c] - [3 4 :d] - [4 5 :a] - [5 6 :e] - [6 7 :c] + (is (= [[0 1 :a] [1 2 :b] [2 3 :c] [3 4 :d] [4 5 :a] [5 6 :e] [6 7 :c] [7 8 :d]] (unfold 1 (f :a (f :b :e) :c :d))))) - (testing "complex nested structure from example" - (is (= [[0 1/2 :1] [1/2 3/4 :2] [3/4 1 :9] [1 3/2 :6] [3/2 2 :7] - [2 5/2 :1] [5/2 3 :3] [3 7/2 :6] [7/2 4 :8] - [4 9/2 :1] [9/2 5 :4] [5 11/2 :6] [11/2 6 :7] - [6 13/2 :1] [13/2 27/4 :2] [27/4 7 :9] [7 15/2 :6] [15/2 8 :8] - [8 17/2 :1] [17/2 9 :3] [9 19/2 :6] [19/2 10 :7] + (is (= [[0 1/2 :1] [1/2 3/4 :2] [3/4 1 :9] [1 3/2 :6] [3/2 2 :7] [2 5/2 :1] + [5/2 3 :3] [3 7/2 :6] [7/2 4 :8] [4 9/2 :1] [9/2 5 :4] [5 11/2 :6] + [11/2 6 :7] [6 13/2 :1] [13/2 27/4 :2] [27/4 7 :9] [7 15/2 :6] + [15/2 8 :8] [8 17/2 :1] [17/2 9 :3] [9 19/2 :6] [19/2 10 :7] [10 21/2 :1] [21/2 11 :5] [11 23/2 :6] [23/2 12 :8]] (unfold 2 (l :1 (f (l :2 :9) :3 (f :4 :5)) :6 (f :7 :8)))))) - (testing "different cycle lengths" - (is (= [[0 1/2 :a] [1/2 1 :b]] - (unfold 1 (l :a :b)))) - (is (= [[0 1 :a] [1 2 :b]] - (unfold 2 (l :a :b)))) - (is (= [[0 5/2 :a] [5/2 5 :b]] - (unfold 5 (l :a :b))))) - + (is (= [[0 1/2 :a] [1/2 1 :b]] (unfold 1 (l :a :b)))) + (is (= [[0 1 :a] [1 2 :b]] (unfold 2 (l :a :b)))) + (is (= [[0 5/2 :a] [5/2 5 :b]] (unfold 5 (l :a :b))))) (testing "fork with nested list subdivides correctly" - (is (= [[0 1/3 :a] [1/3 2/3 :b] [2/3 1 :c] - [1 2 :x]] + (is (= [[0 1/3 :a] [1/3 2/3 :b] [2/3 1 :c] [1 2 :x]] (unfold 1 (f (l :a :b :c) :x))))) - (testing "simple parallel - all children at same time" - (is (= [[0 1 :a] [0 1 :b] [0 1 :c]] - (unfold 1 (p :a :b :c))))) - + (is (= [[0 1 :a] [0 1 :b] [0 1 :c]] (unfold 1 (p :a :b :c))))) (testing "parallel with list - children subdivide in parallel" - (is (= [[0 1/2 :a] [1/2 1 :b] - [0 1/2 :c] [1/2 1 :d]] + (is (= [[0 1/2 :a] [1/2 1 :b] [0 1/2 :c] [1/2 1 :d]] (unfold 1 (p (l :a :b) (l :c :d)))))) - (testing "parallel with fork - forks extend together" - (is (= [[0 1 :a] [0 1 :c] - [1 2 :b] [1 2 :d]] + (is (= [[0 1 :a] [0 1 :c] [1 2 :b] [1 2 :d]] (unfold 1 (p (f :a :b) (f :c :d)))))) - (testing "list containing parallel" - (is (= [[0 1/2 :x] [0 1/2 :y] - [1/2 1 :z]] - (unfold 1 (l (p :x :y) :z))))) - + (is (= [[0 1/2 :x] [0 1/2 :y] [1/2 1 :z]] (unfold 1 (l (p :x :y) :z))))) (testing "parallel with different cycle lengths" - (is (= [[0 1 :a] [0 1 :b] - [1 2 :a] [1 2 :c]] - (unfold 1 (p :a (f :b :c)))))) - + (is (= [[0 1 :a] [0 1 :b] [1 2 :a] [1 2 :c]] (unfold 1 (p :a (f :b :c)))))) (testing "rate 2 - doubles speed of scalar" - (is (= [[0 1/2 :a] [1/2 1 :a]] - (unfold 1 (rate 2 :a))))) - + (is (= [[0 1/2 :a] [1/2 1 :a]] (unfold 1 (rate 2 :a))))) (testing "rate 1/2 - halves speed of scalar" - (is (= [[0 2 :a]] - (unfold 1 (rate 1/2 :a))))) - + (is (= [[0 2 :a]] (unfold 1 (rate 1/2 :a))))) (testing "rate 2 - doubles speed of list" - (is (= [[0 1/6 :a] [1/6 1/3 :b] [1/3 1/2 :c] - [1/2 2/3 :a] [2/3 5/6 :b] [5/6 1 :c]] + (is (= [[0 1/6 :a] [1/6 1/3 :b] [1/3 1/2 :c] [1/2 2/3 :a] [2/3 5/6 :b] + [5/6 1 :c]] (unfold 1 (rate 2 (l :a :b :c)))))) - (testing "rate 1/2 - halves speed of list" - (is (= [[0 1 :a] [1 2 :b]] - (unfold 1 (rate 1/2 (l :a :b)))))) - + (is (= [[0 1 :a] [1 2 :b]] (unfold 1 (rate 1/2 (l :a :b)))))) (testing "rate 2 - doubles speed of fork" - ;; Fork has 3 children, cycle count is 3 - ;; rate 2 makes it repeat 2x, so 6 total cycles - (is (= [[0 1/6 :a] [1/6 1/3 :b] [1/3 1/2 :c] - [1/2 2/3 :a] [2/3 5/6 :b] [5/6 1 :c] - [1 7/6 :a] [7/6 4/3 :b] [4/3 3/2 :c] - [3/2 5/3 :a] [5/3 11/6 :b] [11/6 2 :c] - [2 13/6 :a] [13/6 7/3 :b] [7/3 5/2 :c] + ;; Fork has 3 children, cycle count is 3 rate 2 makes it repeat 2x, so + ;; 6 total cycles + (is (= [[0 1/6 :a] [1/6 1/3 :b] [1/3 1/2 :c] [1/2 2/3 :a] [2/3 5/6 :b] + [5/6 1 :c] [1 7/6 :a] [7/6 4/3 :b] [4/3 3/2 :c] [3/2 5/3 :a] + [5/3 11/6 :b] [11/6 2 :c] [2 13/6 :a] [13/6 7/3 :b] [7/3 5/2 :c] [5/2 8/3 :a] [8/3 17/6 :b] [17/6 3 :c]] (unfold 1 (rate 2 (f :a :b :c)))))) - (testing "rate with parallel" ;; Parallel has cycle 1, rate 2 repeats it twice - (is (= [[0 1/2 :a] [0 1/2 :b] - [1/2 1 :a] [1/2 1 :b]] + (is (= [[0 1/2 :a] [0 1/2 :b] [1/2 1 :a] [1/2 1 :b]] (unfold 1 (rate 2 (p :a :b)))))) - (testing "rate inside list" - (is (= [[0 1/2 :x] [1/2 3/4 :y] [3/4 1 :y]] - (unfold 1 (l :x (rate 2 :y)))))) - + (is (= [[0 1/2 :x] [1/2 3/4 :y] [3/4 1 :y]] (unfold 1 (l :x (rate 2 :y)))))) (testing "nested rates" (is (= [[0 1/4 :a] [1/4 1/2 :a] [1/2 3/4 :a] [3/4 1 :a]] (unfold 1 (rate 2 (rate 2 :a)))))) - (testing "elongate 2 - element takes twice as long" (is (= [[0 1/2 :a] [1/2 3/4 :b] [3/4 1 :c]] (unfold 1 (l (elongate 2 :a) :b :c))))) - (testing "elongate 3 - element takes three times as long" (is (= [[0 3/5 :a] [3/5 4/5 :b] [4/5 1 :c]] (unfold 1 (l (elongate 3 :a) :b :c))))) - (testing "multiple elongations" (is (= [[0 2/5 :a] [2/5 4/5 :b] [4/5 1 :c]] (unfold 1 (l (elongate 2 :a) (elongate 2 :b) :c))))) - (testing "elongate with fork" - (is (= [[0 1 :a] [1 2 :b]] - (unfold 1 (f (elongate 2 :a) :b))))) - + (is (= [[0 1 :a] [1 2 :b]] (unfold 1 (f (elongate 2 :a) :b))))) (testing "elongate inside parallel" - (is (= [[0 1 :a] [0 1 :b]] - (unfold 1 (p (elongate 2 :a) :b))))) - + (is (= [[0 1 :a] [0 1 :b]] (unfold 1 (p (elongate 2 :a) :b))))) (testing "elongate with rate" - (is (= [[0 1/2 :a] [1/2 1 :a]] - (unfold 1 (elongate 2 (rate 2 :a)))))) - + (is (= [[0 1/2 :a] [1/2 1 :a]] (unfold 1 (elongate 2 (rate 2 :a)))))) (testing "rate with elongate inside list" - (is (= [[0 1/4 :a] [1/4 3/8 :b] [3/8 1/2 :c] - [1/2 3/4 :a] [3/4 7/8 :b] [7/8 1 :c]] + (is (= [[0 1/4 :a] [1/4 3/8 :b] [3/8 1/2 :c] [1/2 3/4 :a] [3/4 7/8 :b] + [7/8 1 :c]] (unfold 1 (rate 2 (l (elongate 2 :a) :b :c)))))) - (testing "rep 2 - element repeats twice" - (is (= [[0 1/2 :a] [1/2 1 :a]] - (unfold 1 (rep 2 :a))))) - + (is (= [[0 1/2 :a] [1/2 1 :a]] (unfold 1 (rep 2 :a))))) (testing "rep 3 - element repeats three times" - (is (= [[0 1/3 :a] [1/3 2/3 :a] [2/3 1 :a]] - (unfold 1 (rep 3 :a))))) - + (is (= [[0 1/3 :a] [1/3 2/3 :a] [2/3 1 :a]] (unfold 1 (rep 3 :a))))) (testing "rep in list - subdivides its time slot" - (is (= [[0 1/6 :a] [1/6 1/3 :a] [1/3 1/2 :a] - [1/2 1 :b]] + (is (= [[0 1/6 :a] [1/6 1/3 :a] [1/3 1/2 :a] [1/2 1 :b]] (unfold 1 (l (rep 3 :a) :b))))) - (testing "rep with three elements in list" - (is (= [[0 1/6 :x] [1/6 1/3 :x] - [1/3 2/3 :y] - [2/3 1 :z]] + (is (= [[0 1/6 :x] [1/6 1/3 :x] [1/3 2/3 :y] [2/3 1 :z]] (unfold 1 (l (rep 2 :x) :y :z))))) - (testing "multiple reps in list" - (is (= [[0 1/6 :a] [1/6 1/3 :a] - [1/3 1/2 :b] [1/2 2/3 :b] - [2/3 1 :c]] + (is (= [[0 1/6 :a] [1/6 1/3 :a] [1/3 1/2 :b] [1/2 2/3 :b] [2/3 1 :c]] (unfold 1 (l (rep 2 :a) (rep 2 :b) :c))))) - (testing "rep with fork" - (is (= [[0 1/2 :a] [1/2 1 :a] - [1 2 :b]] - (unfold 1 (f (rep 2 :a) :b))))) - + (is (= [[0 1/2 :a] [1/2 1 :a] [1 2 :b]] (unfold 1 (f (rep 2 :a) :b))))) (testing "rep inside parallel" - (is (= [[0 1/2 :a] [1/2 1 :a] - [0 1 :b]] - (unfold 1 (p (rep 2 :a) :b))))) - + (is (= [[0 1/2 :a] [1/2 1 :a] [0 1 :b]] (unfold 1 (p (rep 2 :a) :b))))) (testing "rep with rate" - (is (= [[0 1/4 :a] [1/4 1/2 :a] - [1/2 3/4 :a] [3/4 1 :a]] + (is (= [[0 1/4 :a] [1/4 1/2 :a] [1/2 3/4 :a] [3/4 1 :a]] (unfold 1 (rep 2 (rate 2 :a)))))) - (testing "rate with rep inside" - (is (= [[0 1/4 :a] [1/4 1/2 :a] - [1/2 3/4 :a] [3/4 1 :a]] + (is (= [[0 1/4 :a] [1/4 1/2 :a] [1/2 3/4 :a] [3/4 1 :a]] (unfold 1 (rate 2 (rep 2 :a)))))) - (testing "rep in list without elongate" - (is (= [[0 1/6 :a] [1/6 1/3 :a] - [1/3 2/3 :b] - [2/3 1 :c]] + (is (= [[0 1/6 :a] [1/6 1/3 :a] [1/3 2/3 :b] [2/3 1 :c]] (unfold 1 (l (rep 2 :a) :b :c))))) - (testing "elongate and rep together" - (is (= [[0 1/6 :a] [1/6 1/3 :a] - [1/3 2/3 :b] - [2/3 1 :c]] + (is (= [[0 1/6 :a] [1/6 1/3 :a] [1/3 2/3 :b] [2/3 1 :c]] (unfold 1 (l (rep 2 (elongate 2 :a)) :b :c))))) - (testing "rep of list" - (is (= [[0 1/4 :a] [1/4 1/2 :b] - [1/2 3/4 :a] [3/4 1 :b]] + (is (= [[0 1/4 :a] [1/4 1/2 :b] [1/2 3/4 :a] [3/4 1 :b]] (unfold 1 (rep 2 (l :a :b)))))) - (testing "paste - simple replacement in list" - (is (= (l :a :b :c) - (paste (l :_ :_ :_) :a :b :c)))) - + (is (= (l :a :b :c) (paste (l :_ :_ :_) :a :b :c)))) (testing "paste - simple replacement in fork" (is (= (f :c (f :e :g) :b :d) (paste (f :_ (f :_ :_) :_ :_) :c :e :g :b :d)))) - (testing "paste - with nil preserves original" (is (= (f :c (f :e :_) :b :d) (paste (f :_ (f :_ :_) :_ :_) :c :e nil :b :d)))) - (testing "paste - multiple nils" (is (= (f :_ (f :e :_) :b :_) (paste (f :_ (f :_ :_) :_ :_) nil :e nil :b nil)))) - (testing "paste - with numbers as template" - (is (= (l :a :b :c) - (paste (l 1 2 1) :a :b :c)))) - + (is (= (l :a :b :c) (paste (l 1 2 1) :a :b :c)))) (testing "paste - nested structures" - (is (= (l :x (l :y :z) :w) - (paste (l :_ (l :_ :_) :_) :x :y :z :w)))) - + (is (= (l :x (l :y :z) :w) (paste (l :_ (l :_ :_) :_) :x :y :z :w)))) (testing "paste - with parallel" - (is (= (p :a :b :c) - (paste (p :_ :_ :_) :a :b :c)))) - + (is (= (p :a :b :c) (paste (p :_ :_ :_) :a :b :c)))) (testing "paste - complex nested with parallel" - (is (= (l :a (p :b :c) :d) - (paste (l :_ (p :_ :_) :_) :a :b :c :d)))) - + (is (= (l :a (p :b :c) :d) (paste (l :_ (p :_ :_) :_) :a :b :c :d)))) (testing "paste - with modifiers preserved" - (is (= (l (rate 2 :a) :b) - (paste (l (rate 2 :_) :_) :a :b)))) - + (is (= (l (rate 2 :a) :b) (paste (l (rate 2 :_) :_) :a :b)))) (testing "paste - with elongate" (is (= (l (elongate 2 :x) :y :z) (paste (l (elongate 2 :_) :_ :_) :x :y :z)))) - (testing "paste - with rep" - (is (= (l (rep 3 :a) :b) - (paste (l (rep 3 :_) :_) :a :b)))) - + (is (= (l (rep 3 :a) :b) (paste (l (rep 3 :_) :_) :a :b)))) (testing "paste - unfolds correctly" (is (= [[0 1/3 :c] [1/3 2/3 :e] [2/3 1 :g]] (unfold 1 (paste (l :_ :_ :_) :c :e :g))))) - (testing "paste - complex rhythm unfolds correctly" - (is (= [[0 1 :c] [1 2 :e] [2 3 :b] [3 4 :d] - [4 5 :c] [5 6 :g] [6 7 :b] [7 8 :d]] + (is (= [[0 1 :c] [1 2 :e] [2 3 :b] [3 4 :d] [4 5 :c] [5 6 :g] [6 7 :b] + [7 8 :d]] (unfold 1 (paste (f :_ (f :_ :_) :_ :_) :c :e :g :b :d))))) - (testing "paste - with nil unfolds correctly" - (is (= [[0 1 :c] [1 2 :e] [2 3 :b] [3 4 :d] - [4 5 :c] [5 6 :_] [6 7 :b] [7 8 :d]] + (is (= [[0 1 :c] [1 2 :e] [2 3 :b] [3 4 :d] [4 5 :c] [5 6 :_] [6 7 :b] + [7 8 :d]] (unfold 1 (paste (f :_ (f :_ :_) :_ :_) :c :e nil :b :d)))))) |
