add next/prev values to ordered-range-value building
put the previous value on the start boundaries and a the next value on the end boundaries
This commit is contained in:
@@ -64,22 +64,22 @@
|
||||
;; test against integer ranges for easy of expression and interpretation
|
||||
(deftest ordered-range-values
|
||||
(testing "ordered range values are sorted by value and then the range's start boundary before any end boundary"
|
||||
(is (= [{:value 1 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 2 :boundary-type :end :type :int-range-inclusive}
|
||||
{:value 4 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :boundary-type :end :type :int-range-inclusive}
|
||||
{:value 5 :boundary-type :end :type :int-range-inclusive}
|
||||
{:value 8 :boundary-type :end :type :int-range-inclusive}]
|
||||
(is (= [{:value 1 :prev-value 0 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 2 :next-value 3 :boundary-type :end :type :int-range-inclusive}
|
||||
{:value 4 :prev-value 3 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :prev-value 4 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :prev-value 4 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :next-value 6 :boundary-type :end :type :int-range-inclusive}
|
||||
{:value 5 :next-value 6 :boundary-type :end :type :int-range-inclusive}
|
||||
{:value 8 :next-value 9 :boundary-type :end :type :int-range-inclusive}]
|
||||
(#'range/ordered-range-values [(int-range-inclusive 1 2)
|
||||
(int-range-inclusive 4 5)
|
||||
(int-range-inclusive 5 8)
|
||||
(int-range-inclusive 5 5)])))
|
||||
(is (= [{:value 5 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :boundary-type :end :type :int-range-inclusive}
|
||||
{:value 5 :boundary-type :end :type :int-range-inclusive}]
|
||||
(is (= [{:value 5 :prev-value 4 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :prev-value 4 :boundary-type :start :type :int-range-inclusive}
|
||||
{:value 5 :next-value 6 :boundary-type :end :type :int-range-inclusive}
|
||||
{:value 5 :next-value 6 :boundary-type :end :type :int-range-inclusive}]
|
||||
(#'range/ordered-range-values [(int-range-inclusive 5 5)
|
||||
(int-range-inclusive 5 5)])))))
|
||||
|
||||
@@ -136,12 +136,10 @@
|
||||
:range-source-type :filter-range
|
||||
:value 1
|
||||
:prev-value 0
|
||||
:next-value 2
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :filter-range
|
||||
:value 4
|
||||
:prev-value 3
|
||||
:next-value 5
|
||||
:type :int-range-inclusive}]))))
|
||||
(testing "only source-ranges"
|
||||
@@ -149,28 +147,34 @@
|
||||
(range/walk-range-boundaries [{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 1
|
||||
:prev-value 0
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 5
|
||||
:next-value 6
|
||||
:type :int-range-inclusive}])))
|
||||
(is (= #{(int-range-inclusive 1 5)
|
||||
(int-range-inclusive 11 15)}
|
||||
(range/walk-range-boundaries [{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 1
|
||||
:next-value 2
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 5
|
||||
:prev-value 4
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 11
|
||||
:next-value 12
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 15
|
||||
:prev-value 14
|
||||
:type :int-range-inclusive}]))))
|
||||
(testing "filter-ranges before source-ranges"
|
||||
(is (= #{(int-range-inclusive 11 15)}
|
||||
@@ -178,41 +182,41 @@
|
||||
:range-source-type :filter-range
|
||||
:value 1
|
||||
:prev-value 0
|
||||
:next-value 2
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :filter-range
|
||||
:prev-value 4
|
||||
:value 5
|
||||
:next-value 6
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 11
|
||||
:prev-value 10
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 15
|
||||
:next-value 16
|
||||
:type :int-range-inclusive}]))))
|
||||
(testing "filter-ranges after source-ranges"
|
||||
(is (= #{(int-range-inclusive 1 5)}
|
||||
(range/walk-range-boundaries [{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 1
|
||||
:prev-value 0
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 5
|
||||
:next-value 6
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :start
|
||||
:range-source-type :filter-range
|
||||
:prev-value 10
|
||||
:value 11
|
||||
:next-value 12
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :filter-range
|
||||
:prev-value 14
|
||||
:value 15
|
||||
:next-value 16
|
||||
:type :int-range-inclusive}]))))
|
||||
@@ -222,22 +226,22 @@
|
||||
(range/walk-range-boundaries [{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 1
|
||||
:prev-value 0
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :start
|
||||
:range-source-type :filter-range
|
||||
:prev-value 5
|
||||
:value 6
|
||||
:next-value 7
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :filter-range
|
||||
:prev-value 10
|
||||
:value 10
|
||||
:next-value 11
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 20
|
||||
:next-value 21
|
||||
:type :int-range-inclusive}]))))
|
||||
(testing "multiple filter-ranges between source-range"
|
||||
(is (= #{(int-range-inclusive 1 5)
|
||||
@@ -246,16 +250,15 @@
|
||||
(range/walk-range-boundaries [{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 1
|
||||
:prev-value 0
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :start
|
||||
:range-source-type :filter-range
|
||||
:prev-value 5
|
||||
:value 6
|
||||
:next-value 7
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :filter-range
|
||||
:prev-value 10
|
||||
:value 10
|
||||
:next-value 11
|
||||
:type :int-range-inclusive}
|
||||
@@ -263,17 +266,16 @@
|
||||
:range-source-type :filter-range
|
||||
:prev-value 12
|
||||
:value 13
|
||||
:next-value 14
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :filter-range
|
||||
:prev-value 18
|
||||
:value 19
|
||||
:next-value 20
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 20
|
||||
:prev-value 19
|
||||
:type :int-range-inclusive}]))))
|
||||
(testing "source range between filter-range"
|
||||
(is (= #{}
|
||||
@@ -281,27 +283,29 @@
|
||||
:range-source-type :filter-range
|
||||
:prev-value 1
|
||||
:value 1
|
||||
:next-value 2
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 6
|
||||
:prev-value 5
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 10
|
||||
:next-value 11
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 13
|
||||
:prev-value 12
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 19
|
||||
:next-value 20
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :filter-range
|
||||
:prev-value 19
|
||||
:value 20
|
||||
:next-value 21
|
||||
:type :int-range-inclusive}]))))
|
||||
@@ -311,29 +315,31 @@
|
||||
(range/walk-range-boundaries [{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 1
|
||||
:prev-value 0
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :start
|
||||
:range-source-type :filter-range
|
||||
:prev-value 4
|
||||
:value 5
|
||||
:next-value 6
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 6
|
||||
:next-value 7
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :start
|
||||
:range-source-type :source-range
|
||||
:value 8
|
||||
:prev-value 7
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :filter-range
|
||||
:prev-value 9
|
||||
:value 10
|
||||
:next-value 11
|
||||
:type :int-range-inclusive}
|
||||
{:boundary-type :end
|
||||
:range-source-type :source-range
|
||||
:value 13
|
||||
:next-value 14
|
||||
:type :int-range-inclusive}])))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user