Exemplo n.º 1
0
    def test_observe(self):
        """Method observe() is virtual and should raise an exception if called."""

        n = Observer()

        with self.assertRaises(NotImplementedError, msg="Virtual method did not raise NotImplementedError exception when called."):
            n.observe()
Exemplo n.º 2
0
    def test_initialise_default(self):
        """Default initialisation."""

        n = Observer()
        self.assertEqual(n.parent, None, "Parent should be None.")
        self.assertEqual(
            n.root, n,
            "Observer should be it's own root as it is not attached to a parent."
        )
        self.assertEqual(len(n.children), 0, "Child list should be empty.")
        self.assertTransformAlmostEqual(
            n.transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            n._root_transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Root transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            n._root_transform_inverse,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Inverse root transform should be an identity matrix.")
        self.assertEqual(n.name, None, "Observer name should be None.")
Exemplo n.º 3
0
    def test_initialise_with_all_arguments(self):
        """Initialisation with all arguments."""

        a = Node()
        b = Observer(a, translate(1, 2, 3), "My New Observer")

        # node a
        self.assertEqual(a.parent, None, "Node a's parent should be None.")
        self.assertEqual(a.root, a, "Node a's root should be Node a.")
        self.assertEqual(a.children.count(b), 1,
                         "Node a's child list should contain Observer b.")
        self.assertTransformAlmostEqual(
            a.transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Node a's transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            a._root_transform,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Node a's root transform should be an identity matrix.")
        self.assertTransformAlmostEqual(
            a._root_transform_inverse,
            AffineMatrix3D(),
            delta=1e-14,
            msg="Node a's inverse root transform should be an identity matrix."
        )

        # node b
        self.assertEqual(b.parent, a, "Observer b's parent should be Node a.")
        self.assertEqual(b.root, a, "Observer b's root should be Node a.")
        self.assertEqual(len(b.children), 0,
                         "Observer b's child list should be empty.")
        self.assertTransformAlmostEqual(
            b.transform,
            translate(1, 2, 3),
            delta=1e-14,
            msg="Observer b's transform was not set correctly.")
        self.assertTransformAlmostEqual(
            b._root_transform,
            translate(1, 2, 3),
            delta=1e-14,
            msg="Observer b's root transform is incorrect.")
        self.assertTransformAlmostEqual(
            b._root_transform_inverse,
            translate(1, 2, 3).inverse(),
            delta=1e-14,
            msg="Observer b's inverse root transform is incorrect.")
        self.assertEqual(b.name, "My New Observer",
                         "Observer's name is incorrect.")