Skip to content

Commit

Permalink
Closes #3665: add multi-dim support to arkouda.testing module
Browse files Browse the repository at this point in the history
  • Loading branch information
ajpotts committed Sep 18, 2024
1 parent e5723b3 commit 5c88fbb
Showing 1 changed file with 75 additions and 2 deletions.
77 changes: 75 additions & 2 deletions tests/testing/asserters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,38 @@ def test_assert_almost_equal(self, size, left_as_arkouda, right_as_arkouda):
assert_almost_equal(df, df3, atol=atol, rtol=rtol)
assert_almost_equivalent(convert_left(df), convert_right(df3), atol=atol, rtol=rtol)

@pytest.mark.skip_if_max_rank_less_than(3)
@pytest.mark.parametrize("size", pytest.prob_size)
@pytest.mark.parametrize("left_as_arkouda", [True, False])
@pytest.mark.parametrize("right_as_arkouda", [True, False])
def test_assert_almost_equal_multi_dim(self, size, left_as_arkouda, right_as_arkouda):

both_ak = left_as_arkouda and right_as_arkouda
convert_left = self.get_converter(left_as_arkouda)
convert_right = self.get_converter(right_as_arkouda)

shape = (2, 2, size)

rng = ak.random.default_rng()
atol = 0.001
rtol = 0.001
a = ak.arange(size * 4, dtype="float64")
a2 = self.perturb(a, atol=atol, rtol=rtol, rng=rng)
a3 = a + rtol + atol

a = a.reshape(shape)
a2 = a2.reshape(shape)
a3 = a3.reshape(shape)

if both_ak:
assert_almost_equal(a, a2, atol=atol, rtol=rtol)
assert_almost_equivalent(convert_left(a), convert_right(a2), atol=atol, rtol=rtol)
if both_ak:
with pytest.raises(AssertionError):
assert_almost_equal(a, a3, atol=atol, rtol=rtol)
with pytest.raises(AssertionError):
assert_almost_equivalent(convert_left(a), convert_right(a3), atol=atol, rtol=rtol)

def test_assert_almost_equal_scalars(self):
atol = 0.001
rtol = 0.001
Expand Down Expand Up @@ -847,7 +879,6 @@ def test_assert_equal(self, size, left_as_arkouda, right_as_arkouda):
convert_left = self.get_converter(left_as_arkouda)
convert_right = self.get_converter(right_as_arkouda)

size = 10
a = ak.arange(size)
a2 = a + 1
idx = Index(a)
Expand Down Expand Up @@ -889,6 +920,28 @@ def test_assert_equal(self, size, left_as_arkouda, right_as_arkouda):
assert_equal(df, df2)
assert_equivalent(convert_left(df), convert_right(df2))

@pytest.mark.skip_if_max_rank_less_than(2)
@pytest.mark.parametrize("size", pytest.prob_size)
@pytest.mark.parametrize("left_as_arkouda", [True, False])
@pytest.mark.parametrize("right_as_arkouda", [True, False])
def test_assert_equal_multi_dim(self, size, left_as_arkouda, right_as_arkouda):
both_ak = left_as_arkouda and right_as_arkouda
convert_left = self.get_converter(left_as_arkouda)
convert_right = self.get_converter(right_as_arkouda)

shape = (2, 2, size)
a = ak.arange(4 * size).reshape(shape)
a2 = a + 1

if both_ak:
assert_equal(a, a)
assert_equivalent(convert_left(a), convert_right(a))
if both_ak:
with pytest.raises(AssertionError):
assert_equal(a, a2)
with pytest.raises(AssertionError):
assert_equivalent(convert_left(a), convert_right(a2))

def test_assert_equal_scalars(self):

st = "string1"
Expand Down Expand Up @@ -940,7 +993,6 @@ def test_assert_arkouda_array_equal(self, size, left_as_arkouda, right_as_arkoud
convert_left = self.get_converter(left_as_arkouda)
convert_right = self.get_converter(right_as_arkouda)

size = 10
a = ak.arange(size)
a2 = a + 1
if both_ak:
Expand Down Expand Up @@ -981,6 +1033,27 @@ def test_assert_arkouda_array_equal(self, size, left_as_arkouda, right_as_arkoud
assert_arkouda_array_equal(s, c)
assert_arkouda_array_equivalent(convert_left(s), convert_right(c))

@pytest.mark.skip_if_max_rank_less_than(2)
@pytest.mark.parametrize("size", pytest.prob_size)
@pytest.mark.parametrize("left_as_arkouda", [True, False])
@pytest.mark.parametrize("right_as_arkouda", [True, False])
def test_assert_arkouda_array_equal_multi_dim(self, size, left_as_arkouda, right_as_arkouda):
both_ak = left_as_arkouda and right_as_arkouda
convert_left = self.get_converter(left_as_arkouda)
convert_right = self.get_converter(right_as_arkouda)

shape = (2, 2, size)
a = ak.arange(4 * size).reshape(shape)
a2 = a + 1
if both_ak:
assert_arkouda_array_equal(a, a)
assert_arkouda_array_equivalent(convert_left(a), convert_right(a))
if both_ak:
with pytest.raises(AssertionError):
assert_arkouda_array_equal(a, a2)
with pytest.raises(AssertionError):
assert_arkouda_array_equivalent(convert_left(a), convert_right(a2))

def test_assert_arkouda_segarray_equal(self):

seg = ak.SegArray(ak.array([0, 3, 9]), ak.arange(10))
Expand Down

0 comments on commit 5c88fbb

Please sign in to comment.