diff --git a/cyaron/query.py b/cyaron/query.py index 5a93958..2eed967 100644 --- a/cyaron/query.py +++ b/cyaron/query.py @@ -70,8 +70,10 @@ def get_one_query( cur_range = position_range[i] if cur_range[0] > cur_range[1]: - raise ValueError("upper-bound should be larger than lower-bound") - if mode == RangeQueryRandomMode.less and cur_range[0] == cur_range[1]: + raise ValueError( + "upper-bound should be larger than lower-bound") + if mode == RangeQueryRandomMode.less and cur_range[0] == cur_range[ + 1]: raise ValueError( "mode is set to less but upper-bound is equal to lower-bound" ) diff --git a/cyaron/tests/range_query_test.py b/cyaron/tests/range_query_test.py index 8f91f7d..98db57a 100644 --- a/cyaron/tests/range_query_test.py +++ b/cyaron/tests/range_query_test.py @@ -24,6 +24,7 @@ def valid_query(l, r, mode: RangeQueryRandomMode, limits) -> bool: class TestRangeQuery(unittest.TestCase): + def test_allow_equal_v1(self): dimension = random.randint(1, 10) limits = Vector.random(dimension, [1000]) # n1, n2 ... @@ -31,8 +32,8 @@ def test_allow_equal_v1(self): self.assertEqual(len(Q), 10**5) for i in range(10**5): self.assertTrue( - valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.allow_equal, limits) - ) + valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.allow_equal, + limits)) def test_allow_equal_v2_throw(self): dimension = random.randint(1, 10) @@ -46,10 +47,8 @@ def test_allow_equal_v2_throw(self): self.assertEqual(len(Q), 10**5) for i in range(10**5): self.assertTrue( - valid_query( - Q[i][0], Q[i][1], RangeQueryRandomMode.allow_equal, limits - ) - ) + valid_query(Q[i][0], Q[i][1], + RangeQueryRandomMode.allow_equal, limits)) except: throw = True @@ -65,8 +64,8 @@ def test_allow_equal_v2_no_throw(self): self.assertEqual(len(Q), 10**5) for i in range(10**5): self.assertTrue( - valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.allow_equal, limits) - ) + valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.allow_equal, + limits)) def test_less_v1(self): dimension = random.randint(1, 10) @@ -75,8 +74,8 @@ def test_less_v1(self): self.assertEqual(len(Q), 10**5) for i in range(10**5): self.assertTrue( - valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.less, limits) - ) + valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.less, + limits)) def test_less_v2_throw(self): dimension = random.randint(1, 10) @@ -90,8 +89,8 @@ def test_less_v2_throw(self): self.assertEqual(len(Q), 10**5) for i in range(10**5): self.assertTrue( - valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.less, limits) - ) + valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.less, + limits)) except: throw = True @@ -110,5 +109,5 @@ def test_less_v2_no_throw(self): self.assertEqual(len(Q), 10**5) for i in range(10**5): self.assertTrue( - valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.less, limits) - ) + valid_query(Q[i][0], Q[i][1], RangeQueryRandomMode.less, + limits))