Exemplo n.º 1
0
    def test_mult(self):

        with pytest.raises(TypeError):
            # Multiplication of two vertices
            v1 = pbm.Vertex(0, 0, 0)
            v2 = pbm.Vertex(1, 0, 0)
            self.assertEqual(v1 * v2, pbm.Vertex(0, 0, 0))

        # Multiplication of number with vertex
        v1 = pbm.Vertex(1, 0, 0)
        v2 = 5
        self.assertEqual(v1 * v2, pbm.Vertex(5, 0, 0))
        self.assertEqual(v2 * v1, pbm.Vertex(5, 0, 0))
        with pytest.raises(AssertionError):
            # Multiplication of np.array to vertex
            import numpy as np
            v2 = np.array([1, 0, 0])
            self.assertEqual(v1 * v2, pbm.Vertex(1, 0, 0))

        with pytest.warns(UserWarning):
            import numpy as np
            v2 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
            self.assertEqual(v1 * v2, pbm.Vertex(1, 0, 0))

        with pytest.raises(TypeError):
            v2 = "Hello there! General Kenobi"
            self.assertEqual(v1 * v2, None)

        import numpy as np
        v2 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        self.assertEqual(v2 * v1, pbm.Vertex(1, 0, 0))
Exemplo n.º 2
0
 def test_del(self):
     v1 = pbm.Vertex(0, 0, 0)
     v1["name"] = "Henry"
     v1["name"] = "Elizabeth"
     v1.__delitem__("name")
     with pytest.raises(KeyError):
         self.assertEqual(v1["name"], "Elizabeth")
Exemplo n.º 3
0
 def test_repr(self):
     v1 = pbm.Vertex(0, 0, 0)
     self.assertEqual(str(v1), "(0 0 0)")
Exemplo n.º 4
0
 def test_len(self):
     v1 = pbm.Vertex(0, 0, 0)
     self.assertEqual(len(v1), 3)
Exemplo n.º 5
0
 def test_iter(self):
     v1 = pbm.Vertex(1, 1, 1)
     import numpy as np
     for i in v1:
         self.assertEqual(i, np.int64(1))