From 2d1418040bac7bec0ebac8b9c6d89ced3af7faeb Mon Sep 17 00:00:00 2001 From: Jake Zerrer Date: Mon, 1 Dec 2025 15:38:37 -0500 Subject: Add replicate function --- test/unheard/cycles_test.clj | 66 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unheard/cycles_test.clj b/test/unheard/cycles_test.clj index 242b6fc..e2e1889 100644 --- a/test/unheard/cycles_test.clj +++ b/test/unheard/cycles_test.clj @@ -1,6 +1,6 @@ (ns unheard.cycles-test (:require [clojure.test :refer [deftest is testing]] - [unheard.cycles :refer [l f p rate elongate unfold]])) + [unheard.cycles :refer [l f p rate elongate rep unfold]])) (deftest unfold-tests (testing "single scalar" @@ -157,4 +157,66 @@ (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]] - (unfold 1 (rate 2 (l (elongate 2 :a) :b :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))))) + + (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))))) + + (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]] + (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]] + (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]] + (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))))) + + (testing "rep inside parallel" + (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]] + (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]] + (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]] + (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]] + (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]] + (unfold 1 (rep 2 (l :a :b))))))) -- cgit v1.2.3