예제 #1
0
파일: tests.py 프로젝트: uamhforever/libzmx
class ClientSurfaceLabels(unittest.TestCase):
    def setUp(self):
        self.z = Connection()
        self.n = self.z.GetSystem()[0]+1

        self.z.NewLens()
        for i in range(self.n):
            self.z.SetLabel(i, 0)

    def setlabel(self, surf, label):
        self.assertNotEqual(self.z.GetLabel(surf), label)
        self.z.SetLabel(surf, label)
        self.assertEqual(self.z.GetLabel(surf), label)
        self.assertEqual(self.z.FindLabel(label), surf, str(label))

    def testAll(self):
        for exp in [2, 16, 31]:
            i = 2**exp-1
            self.setlabel(1, i)
            self.setlabel(1, -i)

    def testSurfaceSequence(self):
        self.setlabel(1, SurfaceSequence.max_surf_id)
예제 #2
0
파일: tests.py 프로젝트: uamhforever/libzmx
class ClientInsertSurface(unittest.TestCase):
    """Check that we understand the semantics of the InsertSurface method

    Insert 0 => No effect
    Insert 1 => Adds surface after object
    Insert n-1 => Adds surface before image
    Insert i (where i>=n) => As Insert n-1
    """
    def setUp(self):
        self.z = Connection()
        self.z.NewLens()
        # self.model = SurfaceSequence(self.z)
        self.n = self.get_len()
        self.original_label = 1
        self.new_label = 2

        for i in range(self.n):
            self.z.SetLabel(i, self.original_label)

    def get_len(self):
        response = self.z.GetSystem()
        return response[0]+1

    def mark_new_surfaces(self):
        for i in range(self.n):
            if not self.z.GetLabel(i) == self.original_label:
                self.z.SetLabel(i, self.new_label)

    def testAllLabels(self):
        z = self.z
        n = self.n

        for i in range(n):
            self.assertEqual(z.GetLabel(i), self.original_label)
        self.mark_new_surfaces()
        for i in range(n):
            self.assertEqual(z.GetLabel(i), self.original_label)

    def testInsertAtZero(self):
        z = self.z
        n = self.n

        # Insert at zero does nothing
        z.InsertSurface(0)

        self.assertEqual(n, self.get_len())

    def testInsertAtOne(self):
        z = self.z
        n = self.n

        # Insert at 1 adds after object surface
        z.InsertSurface(1)

        self.assertEqual(n+1, self.get_len())
        self.mark_new_surfaces()
        self.assertEqual(z.GetLabel(1), self.new_label)

    def testInsertAtNminus1(self):
        z = self.z
        n = self.n

        # Insert at n-1 adds before image surface
        z.InsertSurface(n-1)

        self.assertEqual(n+1, self.get_len())
        self.mark_new_surfaces()
        # self.assertEqual(model[n-1].comment.value, self.new_label)
        self.assertEqual(z.GetLabel(n-1), self.new_label)

    def testInsertAt100(self):
        z = self.z
        n = self.n

        # Insert at i>>n adds before image surface
        z.InsertSurface(100)

        self.assertEqual(n+1, self.get_len())
        self.mark_new_surfaces()
        self.assertEqual(z.GetLabel(n-1), self.new_label)
예제 #3
0
파일: tests.py 프로젝트: uamhforever/libzmx
class ClientDeleteSurface(unittest.TestCase):
    """Check that we understand the semantics of the DeleteSurface method.

    Delete 0 => No effect
    Delete 1 => Delete surface 1 (first surface after object)
    Delete n-1 => Delete last surface (penultimate surface becomes image)
    Delete i (where i>=n) => As Delete n-1
    """
    def setUp(self):
        self.z = Connection()
        self.z.NewLens()

        self.z.InsertSurface(1)
        self.z.InsertSurface(1)

        self.n = self.get_len()
        for i in range(self.n):
            self.z.SetLabel(i, i)

    def get_len(self):
        response = self.z.GetSystem()
        return response[0]+1

    def ListLabels(self):
        for i in range(self.get_len()):
            print((i, self.z.GetLabel(i)))

    def testFind(self):
        for i in range(self.n):
            j = self.z.FindLabel(i)
            self.assertEqual(i, j)

    def testDeleteAtZero(self):
        z = self.z
        n = self.n

        # Delete at zero does nothing
        z.DeleteSurface(0)

        self.assertEqual(n, self.get_len())

    def testDeleteAtOne(self):
        z = self.z
        n = self.n

        # Delete at 1 deletes after object surface
        z.DeleteSurface(1)

        self.assertEqual(n-1, self.get_len())
        # i=1 removed
        self.assertRaises(SurfaceLabelError, lambda: z.FindLabel(1))

    def testDeleteAtEnd(self):
        z = self.z
        n = self.n

        # Delete at n-1 removes image surface
        z.DeleteSurface(n-1)

        self.assertEqual(n-1, self.get_len())
        # i=n-1 removed
        self.assertRaises(SurfaceLabelError, lambda: z.FindLabel(n-1))

    def testDeleteAt100(self):
        z = self.z
        n = self.n

        # Delete at i>>n removes image surface
        z.DeleteSurface(100)

        self.assertEqual(n-1, self.get_len())
        # i=n-1 removed
        self.assertRaises(SurfaceLabelError, lambda: z.FindLabel(n-1))