diff --git a/tests/linmath/test_lvector2.py b/tests/linmath/test_lvector2.py index fe37409f3e..6861ec2c96 100644 --- a/tests/linmath/test_lvector2.py +++ b/tests/linmath/test_lvector2.py @@ -88,3 +88,12 @@ def test_vec2_swizzle_mask(): def test_vec2_str(): assert str(Vec2F(2, 3)) == "LVector2f(2, 3)" assert str(Vec2D(2, 3)) == "LVector2d(2, 3)" + + +def test_vec2_compare(): + assert Vec2(1, 2).compare_to(Vec2(1, 2)) == 0 + + assert Vec2(1, 0).compare_to(Vec2(1, 0)) == 0 + assert Vec2(1, 0).compare_to(Vec2(0, 1)) == 1 + assert Vec2(0, 1).compare_to(Vec2(1, 0)) == -1 + assert Vec2(0, 1).compare_to(Vec2(0, 1)) == 0 diff --git a/tests/linmath/test_lvector3.py b/tests/linmath/test_lvector3.py index cbc8c51e9a..9b69262a3d 100644 --- a/tests/linmath/test_lvector3.py +++ b/tests/linmath/test_lvector3.py @@ -84,6 +84,7 @@ def test_vec3_power(): def test_vec3_len(): assert len(Vec3(2, -3, 10)) == 3 + def test_vec3_swizzle_mask(): original_vector = Vec3(3, 5, 1) @@ -94,3 +95,17 @@ def test_vec3_swizzle_mask(): def test_vec3_str(): assert str(Vec3F(2, 3, 1)) == "LVector3f(2, 3, 1)" assert str(Vec3D(2, 3, 1)) == "LVector3d(2, 3, 1)" + + +def test_vec3_compare(): + assert Vec3(1, 2, 3).compare_to(Vec3(1, 2, 3)) == 0 + + assert Vec3(1, 0, 0).compare_to(Vec3(1, 0, 0)) == 0 + assert Vec3(1, 0, 0).compare_to(Vec3(0, 1, 0)) == 1 + assert Vec3(1, 0, 0).compare_to(Vec3(0, 0, 1)) == 1 + assert Vec3(0, 1, 0).compare_to(Vec3(1, 0, 0)) == -1 + assert Vec3(0, 1, 0).compare_to(Vec3(0, 1, 0)) == 0 + assert Vec3(0, 1, 0).compare_to(Vec3(0, 0, 1)) == 1 + assert Vec3(0, 0, 1).compare_to(Vec3(1, 0, 0)) == -1 + assert Vec3(0, 0, 1).compare_to(Vec3(0, 1, 0)) == -1 + assert Vec3(0, 0, 1).compare_to(Vec3(0, 0, 1)) == 0 diff --git a/tests/linmath/test_lvector4.py b/tests/linmath/test_lvector4.py index a8ac1797c2..cca9da2866 100644 --- a/tests/linmath/test_lvector4.py +++ b/tests/linmath/test_lvector4.py @@ -104,3 +104,24 @@ def test_vec4_swizzle_mask(): def test_vec4_str(): assert str(Vec4F(2, 3, 1, 9)) == "LVector4f(2, 3, 1, 9)" assert str(Vec4D(2, 3, 1, 9)) == "LVector4d(2, 3, 1, 9)" + + +def test_vec4_compare(): + assert Vec4(1, 2, 3, 4).compare_to(Vec4(1, 2, 3, 4)) == 0 + + assert Vec4(1, 0, 0, 0).compare_to(Vec4(1, 0, 0, 0)) == 0 + assert Vec4(1, 0, 0, 0).compare_to(Vec4(0, 1, 0, 0)) == 1 + assert Vec4(1, 0, 0, 0).compare_to(Vec4(0, 0, 1, 0)) == 1 + assert Vec4(1, 0, 0, 0).compare_to(Vec4(0, 0, 0, 1)) == 1 + assert Vec4(0, 1, 0, 0).compare_to(Vec4(1, 0, 0, 0)) == -1 + assert Vec4(0, 1, 0, 0).compare_to(Vec4(0, 1, 0, 0)) == 0 + assert Vec4(0, 1, 0, 0).compare_to(Vec4(0, 0, 1, 0)) == 1 + assert Vec4(0, 1, 0, 0).compare_to(Vec4(0, 0, 0, 1)) == 1 + assert Vec4(0, 0, 1, 0).compare_to(Vec4(1, 0, 0, 0)) == -1 + assert Vec4(0, 0, 1, 0).compare_to(Vec4(0, 1, 0, 0)) == -1 + assert Vec4(0, 0, 1, 0).compare_to(Vec4(0, 0, 1, 0)) == 0 + assert Vec4(0, 0, 1, 0).compare_to(Vec4(0, 0, 0, 1)) == 1 + assert Vec4(0, 0, 0, 1).compare_to(Vec4(1, 0, 0, 0)) == -1 + assert Vec4(0, 0, 0, 1).compare_to(Vec4(0, 1, 0, 0)) == -1 + assert Vec4(0, 0, 0, 1).compare_to(Vec4(0, 0, 1, 0)) == -1 + assert Vec4(0, 0, 0, 1).compare_to(Vec4(0, 0, 0, 1)) == 0 diff --git a/tests/pgraph/test_lightattrib.py b/tests/pgraph/test_lightattrib.py index 752f4c2717..4222e200e9 100644 --- a/tests/pgraph/test_lightattrib.py +++ b/tests/pgraph/test_lightattrib.py @@ -72,3 +72,38 @@ def test_lightattrib_compose_alloff(): assert lattr3.get_num_on_lights() == 0 assert lattr3.get_num_off_lights() == 0 assert lattr3.has_all_off() + + +def test_lightattrib_compare(): + lattr1 = core.LightAttrib.make() + lattr2 = core.LightAttrib.make() + assert lattr1.compare_to(lattr2) == 0 + + # All-off should not compare equal to empty + lattr2 = core.LightAttrib.make_all_off() + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) + + # If both have the same light, they are equal + lattr1 = core.LightAttrib.make() + lattr1 = lattr1.add_on_light(spot) + lattr2 = core.LightAttrib.make() + lattr2 = lattr2.add_on_light(spot) + assert lattr1.compare_to(lattr2) == 0 + assert lattr2.compare_to(lattr1) == 0 + + # Adding an extra light makes it unequal + lattr2 = lattr2.add_on_light(point) + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) + + # Different lights altogether is of course unequal + lattr1 = core.LightAttrib.make() + lattr1 = lattr1.add_on_light(point) + lattr2 = core.LightAttrib.make() + lattr2 = lattr2.add_on_light(spot) + assert lattr1.compare_to(lattr2) != 0 + assert lattr2.compare_to(lattr1) != 0 + assert lattr2.compare_to(lattr1) == -lattr1.compare_to(lattr2) diff --git a/tests/pgraph/test_materialattrib.py b/tests/pgraph/test_materialattrib.py new file mode 100644 index 0000000000..562c51dcca --- /dev/null +++ b/tests/pgraph/test_materialattrib.py @@ -0,0 +1,34 @@ +from panda3d import core + + +def test_materialattrib_compare(): + mat1 = core.Material() + mat2 = core.Material() + + # Two empty attribs + mattr1 = core.MaterialAttrib.make_off() + mattr2 = core.MaterialAttrib.make_off() + assert mattr1.compare_to(mattr2) == 0 + assert mattr2.compare_to(mattr1) == 0 + + # One empty attrib, one with a material + mattr1 = core.MaterialAttrib.make_off() + mattr2 = core.MaterialAttrib.make(mat1) + assert mattr1 != mattr2 + assert mattr1.compare_to(mattr2) != 0 + assert mattr2.compare_to(mattr1) != 0 + assert mattr1.compare_to(mattr2) == -mattr2.compare_to(mattr1) + + # Two attribs with same material + mattr1 = core.MaterialAttrib.make(mat1) + mattr2 = core.MaterialAttrib.make(mat1) + assert mattr1.compare_to(mattr2) == 0 + assert mattr2.compare_to(mattr1) == 0 + + # Two different materials + mattr1 = core.MaterialAttrib.make(mat1) + mattr2 = core.MaterialAttrib.make(mat2) + assert mattr1 != mattr2 + assert mattr1.compare_to(mattr2) != 0 + assert mattr2.compare_to(mattr1) != 0 + assert mattr1.compare_to(mattr2) == -mattr2.compare_to(mattr1) diff --git a/tests/pgraph/test_nodepath.py b/tests/pgraph/test_nodepath.py index 7dcbd2662b..bea44d982c 100644 --- a/tests/pgraph/test_nodepath.py +++ b/tests/pgraph/test_nodepath.py @@ -109,6 +109,49 @@ def test_nodepath_transform_composition(): assert np1.get_transform(np2) == relative_transform +def test_nodepath_comparison(): + from panda3d.core import NodePath, PandaNode + + path = NodePath("node") + + # Empty NodePath equals itself + assert NodePath() == NodePath() + assert not (NodePath() != NodePath()) + assert not (NodePath() > NodePath()) + assert not (NodePath() < NodePath()) + assert NodePath().compare_to(NodePath()) == 0 + + # Empty NodePath does not equal non-empty NodePath + assert NodePath() != path + assert not (NodePath() == path) + assert NodePath().compare_to(path) != 0 + assert path != NodePath() + assert not (path == NodePath()) + assert path.compare_to(NodePath()) != 0 + + # Copy of NodePath equals original + path2 = NodePath(path) + assert path == path2 + assert path2 == path + assert not (path != path2) + assert not (path2 != path) + assert not (path > path2) + assert not (path < path2) + assert path.compare_to(path2) == 0 + assert path2.compare_to(path) == 0 + + # NodePath pointing to copy of node is not the same + path2 = NodePath(path.node().make_copy()) + assert path != path2 + assert path2 != path + assert not (path == path2) + assert not (path2 == path) + assert (path2 > path) or (path > path2) + assert (path2 < path) or (path < path2) + assert path.compare_to(path2) != 0 + assert path2.compare_to(path) != 0 + + def test_weak_nodepath_comparison(): from panda3d.core import NodePath, WeakNodePath diff --git a/tests/pgraph/test_shaderattrib.py b/tests/pgraph/test_shaderattrib.py index 890fd26fb7..1bf6908084 100644 --- a/tests/pgraph/test_shaderattrib.py +++ b/tests/pgraph/test_shaderattrib.py @@ -40,3 +40,18 @@ def test_shaderattrib_flags(): # Set group to false shattr = shattr.set_flag(core.ShaderAttrib.F_hardware_skinning | core.ShaderAttrib.F_subsume_alpha_test, False) assert not shattr.get_flag(core.ShaderAttrib.F_hardware_skinning | core.ShaderAttrib.F_subsume_alpha_test) + + +def test_shaderattrib_compare(): + shattr1 = core.ShaderAttrib.make() + shattr2 = core.ShaderAttrib.make() + assert shattr1.compare_to(shattr2) == 0 + assert shattr2.compare_to(shattr1) == 0 + + shattr2 = core.ShaderAttrib.make().set_flag(core.ShaderAttrib.F_subsume_alpha_test, True) + assert shattr1.compare_to(shattr2) != 0 + assert shattr2.compare_to(shattr1) != 0 + + shattr1 = core.ShaderAttrib.make().set_flag(core.ShaderAttrib.F_subsume_alpha_test, False) + assert shattr1.compare_to(shattr2) != 0 + assert shattr2.compare_to(shattr1) != 0 diff --git a/tests/pgraph/test_textureattrib.py b/tests/pgraph/test_textureattrib.py new file mode 100644 index 0000000000..868f3f4b07 --- /dev/null +++ b/tests/pgraph/test_textureattrib.py @@ -0,0 +1,112 @@ +from panda3d import core + +# Some dummy textures we can use for our texture attributes. +stage1 = core.TextureStage("stage1") +stage2 = core.TextureStage("stage2") +stage3 = core.TextureStage("stage3") +tex1 = core.Texture("tex1") +tex2 = core.Texture("tex2") +tex3 = core.Texture("tex3") + + +def test_textureattrib_compose_add(): + # Tests a case in which a child node adds another texture. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage2, tex2) + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 2 + + assert stage1 in tattr3.on_stages + assert stage2 in tattr3.on_stages + + +def test_textureattrib_compose_subtract(): + # Tests a case in which a child node disables a texture. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr1 = tattr1.add_on_stage(stage2, tex2) + + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_off_stage(stage3) + tattr2 = tattr2.add_off_stage(stage2) + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 1 + + assert stage1 in tattr3.on_stages + assert stage2 not in tattr3.on_stages + assert stage3 not in tattr3.on_stages + + +def test_textureattrib_compose_both(): + # Tests a case in which a child node both enables and disables a texture. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr1 = tattr1.add_on_stage(stage2, tex2) + + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage3, tex3) + tattr2 = tattr2.add_on_stage(stage1, tex1) + tattr2 = tattr2.add_off_stage(stage2) + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 2 + + assert stage1 in tattr3.on_stages + assert stage2 not in tattr3.on_stages + assert stage3 in tattr3.on_stages + + +def test_textureattrib_compose_alloff(): + # Tests a case in which a child node disables all textures. + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr1 = tattr1.add_on_stage(stage2, tex2) + assert tattr1.get_num_on_stages() == 2 + + tattr2 = core.TextureAttrib.make_all_off() + assert tattr2.has_all_off() + + tattr3 = tattr1.compose(tattr2) + assert tattr3.get_num_on_stages() == 0 + assert tattr3.get_num_off_stages() == 0 + assert tattr3.has_all_off() + + +def test_textureattrib_compare(): + tattr1 = core.TextureAttrib.make() + tattr2 = core.TextureAttrib.make() + assert tattr1.compare_to(tattr2) == 0 + + # All-off should not compare equal to empty + tattr2 = core.TextureAttrib.make_all_off() + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) + + # If both have the same texture, they are equal + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage1, tex1) + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage1, tex1) + assert tattr1.compare_to(tattr2) == 0 + assert tattr2.compare_to(tattr1) == 0 + + # Adding an extra texture makes it unequal + tattr2 = tattr2.add_on_stage(stage2, tex2) + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) + + # Different textures altogether is of course unequal + tattr1 = core.TextureAttrib.make() + tattr1 = tattr1.add_on_stage(stage2, tex2) + tattr2 = core.TextureAttrib.make() + tattr2 = tattr2.add_on_stage(stage1, tex1) + assert tattr1.compare_to(tattr2) != 0 + assert tattr2.compare_to(tattr1) != 0 + assert tattr2.compare_to(tattr1) == -tattr1.compare_to(tattr2) diff --git a/tests/putil/test_bamcache.py b/tests/putil/test_bamcache.py new file mode 100644 index 0000000000..b6f65aed5a --- /dev/null +++ b/tests/putil/test_bamcache.py @@ -0,0 +1,8 @@ +from panda3d import core + + +def test_bamcache_flush_index(): + # We really only have this unit test so that this method is being hit + # consistently, and not intermittently, to avoid a noisy coverage report. + cache = core.BamCache() + cache.flush_index() diff --git a/tests/putil/test_bitarray.py b/tests/putil/test_bitarray.py index 15b851c0d8..6c258dfd37 100644 --- a/tests/putil/test_bitarray.py +++ b/tests/putil/test_bitarray.py @@ -42,8 +42,8 @@ def test_bitarray_getstate(): assert BitArray(100).__getstate__() == 100 assert BitArray(9870000000000000000).__getstate__() == 9870000000000000000 assert BitArray.all_on().__getstate__() == -1 - assert ~BitArray(100).__getstate__() == ~100 - assert ~BitArray(812000000000000000).__getstate__() == ~812000000000000000 + assert (~BitArray(100).__getstate__()) == ~100 + assert (~BitArray(812000000000000000).__getstate__()) == ~812000000000000000 def test_bitarray_pickle(): @@ -58,3 +58,6 @@ def test_bitarray_pickle(): ba = BitArray(94187049178237918273981729127381723) assert ba == pickle.loads(pickle.dumps(ba, -1)) + + ba = ~BitArray(94187049178237918273981729127381723) + assert ba == pickle.loads(pickle.dumps(ba, -1))