Skip to content

Commit

Permalink
Make interval/concur handle three or more adjecent intervals
Browse files Browse the repository at this point in the history
The tests for interval/concur had no case with three
or more arguments. Therefore the case where two adjecent
intervals returns nil that is sent to (relation x y)
in the next iteration was missed.

remove redundant test
  • Loading branch information
Henrik Almegren committed Nov 22, 2023
1 parent 1d0b7f1 commit 3f587fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/tick/alpha/interval.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,14 @@
representing the interval of time the given intervals are
concurrent."
([x y]
(case (relation x y)
:overlaps (slice x (t/beginning y) (t/end x))
:overlapped-by (slice x (t/beginning x) (t/end y))
(:starts :finishes :during :equals) x
(:started-by :finished-by :contains) (slice x (t/beginning y) (t/end y))
nil))
(if (or (nil? x) (nil? y))
nil
(case (relation x y)
:overlaps (slice x (t/beginning y) (t/end x))
:overlapped-by (slice x (t/beginning x) (t/end y))
(:starts :finishes :during :equals) x
(:started-by :finished-by :contains) (slice x (t/beginning y) (t/end y))
nil)))
([x y & args]
(reduce concur (concur x y) args)))

Expand Down
24 changes: 23 additions & 1 deletion test/tick/alpha/interval_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,29 @@
(ti/new-interval (instants 1) (instants 3))
(ti/concur
(ti/new-interval (instants 1) (instants 3))
(ti/new-interval (instants 0) (instants 3))))))
(ti/new-interval (instants 0) (instants 3)))))

(is
(=
(ti/new-interval (instants 1) (instants 2))
(ti/concur
(ti/new-interval (instants 1) (instants 3))
(ti/new-interval (instants 1) (instants 2))
(ti/new-interval (instants 0) (instants 2)))))

(is
(nil?
(ti/concur
(ti/new-interval (instants 1) (instants 2))
(ti/new-interval (instants 2) (instants 3))
(ti/new-interval (instants 0) (instants 2)))))

(is
(nil?
(ti/concur
(ti/new-interval (instants 0) (instants 1))
(ti/new-interval (instants 1) (instants 2))
(ti/new-interval (instants 2) (instants 3))))))

;; Sequence tests

Expand Down

0 comments on commit 3f587fa

Please sign in to comment.