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)
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))