Ejemplo n.º 1
0
    def test_scope_datastructure_PointVector(self):
        pv = PySI.PointVector()
        self.assertEqual(len(pv), 0)

        pv = PySI.PointVector([[1, 1]])
        self.assertEqual(len(pv), 1)

        pv = PySI.PointVector([[1, 1], [2, 2], [3, 3], [4, 4]])
        self.assertEqual(len(pv), 4)

        # get
        self.assertEqual(pv[0].x, PySI.Point2(1, 1).x)
        self.assertEqual(pv[0].y, PySI.Point2(1, 1).y)

        # get_slice
        self.assertEqual(len(pv[:2]), 2)
        self.assertEqual(len(pv[::2]), 2)

        self.assertEqual(pv[0].x, PySI.Point2(1, 1).x)
        self.assertEqual(pv[0].y, PySI.Point2(1, 1).y)

        qv = pv[::2]
        self.assertEqual(qv[1].x, PySI.Point2(3, 3).x)
        self.assertEqual(qv[1].y, PySI.Point2(3, 3).y)
        self.assertEqual(qv[0].x, PySI.Point2(1, 1).x)
        self.assertEqual(qv[0].y, PySI.Point2(1, 1).y)

        # set
        qv[1] = [1337, 69]
        self.assertEqual(qv[1].x, PySI.Point2(1337, 69).x)
        self.assertEqual(qv[1].y, PySI.Point2(1337, 69).y)

        # del
        self.assertEqual(len(pv), 4)
        del pv[1]
        self.assertEqual(len(pv), 3)

        self.assertEqual(pv[1].x, PySI.Point2(3, 3).x)
        self.assertEqual(pv[1].y, PySI.Point2(3, 3).y)

        # add
        self.assertEqual(len(pv), 3)

        pv.append([1337, 69])
        self.assertEqual(len(pv), 4)

        self.assertEqual(pv[3].x, PySI.Point2(1337, 69).x)
        self.assertEqual(pv[3].y, PySI.Point2(1337, 69).y)

        # in
        for p in qv:
            self.assertNotEqual(p, None)
            self.assertTrue((p.x == 1 or p.x == 1337) and (p.y == 1 or p.y == 69))

        self.assertTrue(PySI.Point3(1337, 69, 1) in qv)

        # index
        self.assertEqual(qv.index(qv[1]), 1)
        self.assertEqual(qv.index(PySI.Point3(1337, 69, 1)), 1)
        self.assertEqual(qv.index(PySI.Point3(1, 1, 1)), 0)
Ejemplo n.º 2
0
    def test_scope_datastructure_Point3(self):
        p = PySI.Point3(1337, 69, 1)

        self.assertEqual(p.x, 1337)
        self.assertEqual(p.y, 69)
        self.assertEqual(p.z, 1)