Esempio n. 1
0
 def setUp(self):
     super(TestMultiPointerTrack, self).setUp()
     self._mpt = ListMultiPointerTrack()
     self._a = DummyType(1)
     self._b = DummyType(2)
     self._c = DummyType(3)
Esempio n. 2
0
class TestMultiPointerTrack(IndicoTestCase):

    def setUp(self):
        super(TestMultiPointerTrack, self).setUp()
        self._mpt = ListMultiPointerTrack()
        self._a = DummyType(1)
        self._b = DummyType(2)
        self._c = DummyType(3)

    def _addSome(self):
        self._mpt.add(1, self._a)
        self._mpt.add(2, self._b)
        self._mpt.add(1, self._c)
        self._mpt.add(1, self._a)
        self._mpt.add(2, self._a)
        self._mpt.add(3, self._c)

    def testAdd(self):
        """
        adding several elements and checking the result
        """
        self._addSome()
        self.assertEqual(list(self._mpt[1]), [self._a, self._c, self._a])
        self.assertEqual(list(self._mpt[2]), [self._b, self._a])
        self.assertEqual(list(self._mpt[3]), [self._c])

    def testSlice(self):
        """
        adding several elements and checking the result
        """
        self._addSome()
        self.assertEqual(list(self._mpt[2:1]), [[self._b, self._a],
                                                [self._a, self._c, self._a]])
        self.assertEqual(list(self._mpt[:]),
                         [[self._c], [self._b, self._a], [self._a, self._c, self._a]])

    def testDel(self):
        """
        adding/deleting several elements and checking the result
        """

        self._mpt.add(1, self._a)
        self._mpt.add(2, self._b)
        self._mpt.add(1, self._c)
        del self._mpt[1]
        self.assertEqual(len(self._mpt), 1)
        del self._mpt[2]
        self.assertEqual(len(self._mpt), 0)

    def testLen(self):
        """
        adding/removing several elements and checking len()
        """
        self.assertEqual(len(self._mpt), 0)
        self._mpt.add(1, self._a)
        self.assertEqual(len(self._mpt), 1)
        self._mpt.add(2, self._b)
        self._mpt.add(1, self._c)
        self.assertEqual(len(self._mpt), 2)
        del self._mpt[1]
        self.assertEqual(len(self._mpt), 1)

    def test_track_empty(self):
        """
        checking that track is empty
        """
        self.assertEqual(self._mpt.is_empty(), True)
        self._addSome()
        self.assertEqual(self._mpt.is_empty(), False)

    def testMovePointer(self):
        """
        moving the pointer
        """
        self._addSome()
        self._mpt.addPointer('p1')
        self._mpt.addPointer('p2')
        self._mpt.movePointer('p2', 1)
        self._mpt.movePointer('p1', 1)
        self.assertEqual(list(self._mpt.pointerIterValues('p1')),
                         [self._c, self._b, self._a])

        self._mpt.movePointer('p1', 2)
        self.assertEqual(list(self._mpt.pointerIterValues('p2')),
                         [self._c, self._b, self._a])

        self.assertEqual(list(self._mpt.pointerIterValues('p1')), [self._c])

    def testAddPointerStartPos(self):
        """
        adding a pointer at a start position
        """
        self._addSome()

        # should be the minimum key
        self._mpt.addPointer('p1')
        self.assertEqual(self._mpt.getPointerTimestamp('p1'), None)

        self._mpt.addPointer('p2', 3 )
        self.assertEqual(self._mpt.getPointerTimestamp('p2'), 3 )

    def testMovePointerError(self):
        """
        exception thrown by movePointer()
        """

        # pointer doesn't exist
        self.assertRaises(KeyError, self._mpt.movePointer, self._a, 1 )