def test_boolean_spheres_no_overlap():
r"""Test to make sure that boolean objects (spheres, no overlap)
behave the way we expect.
Test non-overlapping spheres. This also checks that the original spheres
don't change as part of constructing the booleans.
"""
ds = fake_amr_ds()
sp1 = ds.sphere([0.25, 0.25, 0.25], 0.15)
sp2 = ds.sphere([0.75, 0.75, 0.75], 0.15)
# Store the original indices
i1 = sp1["index","morton_index"]
i1.sort()
i2 = sp2["index","morton_index"]
i2.sort()
ii = np.concatenate((i1, i2))
ii.sort()
# Make some booleans
bo1 = sp1 & sp2
bo2 = sp1 - sp2
bo3 = sp1 | sp2 # also works with +
bo4 = ds.union([sp1, sp2])
bo5 = ds.intersection([sp1, sp2])
# This makes sure the original containers didn't change.
new_i1 = sp1["index","morton_index"]
new_i1.sort()
new_i2 = sp2["index","morton_index"]
new_i2.sort()
assert_array_equal(new_i1, i1)
assert_array_equal(new_i2, i2)
# Now make sure the indices also behave as we expect.
empty = np.array([])
assert_array_equal(bo1["index","morton_index"], empty)
assert_array_equal(bo5["index","morton_index"], empty)
b2 = bo2["index","morton_index"]
b2.sort()
assert_array_equal(b2, i1)
b3 = bo3["index","morton_index"]
b3.sort()
assert_array_equal(b3, ii)
b4 = bo4["index","morton_index"]
b4.sort()
assert_array_equal(b4, ii)
bo6 = sp1 ^ sp2
b6 = bo6["index", "morton_index"]
b6.sort()
assert_array_equal(b6, np.setxor1d(i1, i2))
评论列表
文章目录