Skip to content

Commit

Permalink
Formatted code according to yapf_style.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
AlfredChester committed Dec 15, 2024
1 parent 9c78fe4 commit 6d972fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
6 changes: 4 additions & 2 deletions cyaron/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
27 changes: 13 additions & 14 deletions cyaron/tests/range_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ 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 ...
Q = RangeQuery.random(10**5, limits)
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)
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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))

0 comments on commit 6d972fc

Please sign in to comment.