Exemple #1
0
 def setUp(self):
     self.z = Connection()
     self.z.NewLens()
     self.model = SurfaceSequence(self.z, empty=True)
     self.model[0].comment.value = "OBJ"
     self.model[-1].comment.value = "IMG"
     self._list = ["OBJ", "IMG"]
Exemple #2
0
    def setUp(self):
        self.z = Connection()
        self.z.NewLens()
        self.model = SurfaceSequence(self.z)
        self.system = SystemConfig(self.z)
        self.system.rayaimingtype = 0

        self.model[0].thickness = 10.0

        # insert fold mirror
        self.model.append_new(surface.CoordinateBreak, rotate_y=40.0,
                              rotate_z=10.0)
        self.model.append_new(surface.Standard, glass="MIRROR")
        cb = self.model.append_new(surface.CoordinateBreak, thickness=-20.0)
        cb.rotate_x.align_to_chief_ray()
        cb.rotate_y.align_to_chief_ray()

        front = self.model.append_new(surface.Standard,
                                      curvature=-0.05, glass="BK7",
                                      thickness=-1.0)
        back = self.model.append_new(surface.Standard,
                                     curvature=-front.curvature.linked())

        self.z.SetSystemAper(3, front.get_surf_num(), 2.5)
        back.thickness.focus_on_next(self.marginal_ray_solve_pupil_coordinate)

        self.z.GetUpdate()
Exemple #3
0
    def runTest(self) :    
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        # setting the extra parameter on surface creation requires surface type to be set first, internally
        m1 = model.insert_new(1, surface.Toroidal, num_poly_terms=11)
    
        self.assertEqual(m1.num_poly_terms.value, 11)
Exemple #4
0
    def runTest(self):
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        # setting the extra parameter on surface creation requires
        # surface type to be set first, internally
        m1 = model.insert_new(1, surface.Toroidal, num_poly_terms=11)

        self.assertEqual(m1.num_poly_terms.value, 11)
Exemple #5
0
    def runTest(self) :    
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        m1 = model.insert_new(1, surface.Standard, "M1", glass="MIRROR", curvature=1, ignored=True, semidia=2,
                             thermal_expansivity=.001, coating="METAL")
    
        self.assertEqual( m1.comment.value, "M1" )
        self.assertEqual( m1.glass.value, "MIRROR")
        self.assertAlmostEqual(m1.curvature.value, 1)
        self.assertEqual(m1.ignored.value, True)
        self.assertAlmostEqual(m1.semidia.value, 2)
        self.assertAlmostEqual(m1.thermal_expansivity.value, .001)
        self.assertEqual(m1.coating.value, "METAL")
Exemple #6
0
    def runTest(self):
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        # id = model.insert_surface(1)
        # m1 = surface.Standard(z,id)
        m1 = model.insert_new(1, surface.Toroidal)

        m1.comment.value = "M1"
        self.assertEqual(m1.comment.value, "M1")

        m1.glass.value = "MIRROR"
        self.assertEqual(m1.glass.value, "MIRROR")

        m1.curvature.value = 1
        self.assertAlmostEqual(m1.curvature.value, 1)

        m1.ignored.value = True
        self.assertEqual(m1.ignored.value, True)

        m1.semidia.value = 2
        self.assertAlmostEqual(m1.semidia.value, 2)

        m1.thermal_expansivity.value = .001
        self.assertAlmostEqual(m1.thermal_expansivity.value, .001)

        m1.coating.value = "METAL"
        self.assertEqual(m1.coating.value, "METAL")

        # "extra" type parameters
        m1.num_poly_terms = 11
        self.assertEqual(m1.num_poly_terms.value, 11)

        m1.norm_radius = 123.0
        self.assertAlmostEqual(m1.norm_radius.value, 123.0)

        def access_missing_attr():
            item = m1.this_will_never_ever_exist
            print("Item: " + str(item))
            return item
        self.assertRaises(AttributeError, access_missing_attr)

        def access_missing_attr_linked():
            item = m1.this_will_never_ever_exist_linked
            return item
        self.assertRaises(AttributeError, access_missing_attr_linked)
Exemple #7
0
    def testLimitLength(self) :
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        # Zemax surface comments must be 32 characters or less, to survive saving and reloading
        surf = model.insert_new(1, surface.Standard)
        def set_comment() :
            surf.comment = "z" * (libzmx.CommentParameter.max_len+1)
        self.assertRaises(ValueError, set_comment)

        comment = "c"*20
        tag = "t"*10
        surf.comment = comment
        def set_tag() :
            surf.comment.tag = tag
        self.assertRaises(ValueError, set_tag)
Exemple #8
0
    def runTest(self):
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        m1 = model.insert_new(1, surface.Standard, "M1",
                              glass="MIRROR", curvature=1,
                              ignored=True, semidia=2,
                              thermal_expansivity=.001,
                              coating="METAL")

        self.assertEqual(m1.comment.value, "M1")
        self.assertEqual(m1.glass.value, "MIRROR")
        self.assertAlmostEqual(m1.curvature.value, 1)
        self.assertEqual(m1.ignored.value, True)
        self.assertAlmostEqual(m1.semidia.value, 2)
        self.assertAlmostEqual(m1.thermal_expansivity.value, .001)
        self.assertEqual(m1.coating.value, "METAL")
Exemple #9
0
    def runTest(self):
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        # id = model.insert_surface(1)
        # m1 = surface.Standard(z,id)
        s = model.insert_new(1, surface.Standard)

        # there are no adjustable variables
        self.assertEqual(0, len(s.fix_variables()))

        # make some parameters adjustable
        s.thickness.vary()
        s.curvature.vary()

        # there are some adjustable variables
        self.assertEqual(2, len(s.fix_variables()))
        # adjustable variables are now fixed
        self.assertEqual(0, len(s.fix_variables()))
Exemple #10
0
    def testLimitLength(self):
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        # Zemax surface comments must be 32 characters or less, to
        # survive saving and reloading
        surf = model.insert_new(1, surface.Standard)

        def set_comment():
            surf.comment = "z" * (libzmx.CommentParameter.max_len+1)
        self.assertRaises(ValueError, set_comment)

        comment = "c"*20
        tag = "t"*10
        surf.comment = comment

        def set_tag():
            surf.comment.tag = tag
        self.assertRaises(ValueError, set_tag)
Exemple #11
0
    def testTagging(self):
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)
        els = NamedElements(model)

        surf = model.insert_new(1, surface.Standard)

        comment = "first comment"
        surf.comment = comment

        # if no tag set, comment matches "comment" verbatim
        self.assertEqual(comment, surf.comment._client_get_value())
        self.assertEqual(comment, surf.comment.value)

        # Setting the surface as an attribute of a NamedElements instance,
        # causes the name to be stored as a tag on the surface.
        els.m1 = surf
        # value in zemax model now has tag embedded
        self.assertNotEqual(comment, surf.comment._client_get_value())
        # the tag is invisible in the value of comment
        self.assertEqual(comment, surf.comment.value)
        # the tag can be accessed, however
        self.assertEqual("m1", surf.comment.tag)

        # Updating the comment does not alter the tag
        comment = "second comment"
        self.assertNotEqual(comment, surf.comment.value)
        surf.comment = comment
        self.assertEqual(comment, surf.comment.value)
        # the tag is unchanged
        self.assertEqual("m1", surf.comment.tag)

        # we can access the surface as a property of a newly-created
        # NamedElements instance
        els2 = NamedElements(model)
        self.assertEqual(comment, els2.m1.comment.value)
        self.assertEqual(surf.id, els2.m1.id)

        # named surfaces can be discovered in models
        self.assertTrue("m1" in dir(els2))
Exemple #12
0
    def setUp(self):
        self.z = Connection()
        self.z.NewLens()
        model = SurfaceSequence(self.z)

        m1 = model.insert_new(1, surface.Toroidal)
        m1.comment.value = "M1"
        m1.glass.value = "MIRROR"
        m1.curvature.value = 1
        m1.conic.value = 0.1
        m1.ignored.value = True
        m1.semidia.value = 2
        m1.thermal_expansivity.value = .001
        m1.coating.value = "METAL"
        m1.thickness.value = 30
        m1.norm_radius = 123.0
        m1.num_poly_terms = 5

        self.m1 = m1
        self.m2 = model.insert_new(-1, surface.Toroidal)

        cb1 = model.insert_new(-1, surface.CoordinateBreak)
        cb1.rotate_x.value = 34
        cb1.rotate_y.value = 42
        cb1.rotate_z.value = 83
        cb1.offset_x.value = 2.63
        cb1.offset_y.value = 753.3
        cb1.thickness.value = 322.3

        self.cb1 = cb1
        self.cb2 = model.insert_new(-1, surface.CoordinateBreak)
Exemple #13
0
    def testSaving(self):
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        # Zemax surface comments must be 32 characters or less, to
        # survive saving and reloading
        surf = model.insert_new(1, surface.Standard)
        id = surf.id
        comment = "c"*20
        tag = "t"*9
        surf.comment = comment
        surf.comment.tag = tag

        self.assertEqual(len(surf.comment._client_get_value()),
                         libzmx.CommentParameter.max_len)

        # Surface can be retrieved from unsaved model
        els = NamedElements(model)
        self.assertEqual(id, getattr(els, tag).id)

        # Save model
        (fd, modelf) = tempfile.mkstemp(".ZMX")
        z.SaveFile(modelf)

        n = len(model)
        z.NewLens()
        self.assertNotEqual(n, len(model))

        # Reload model
        z.LoadFile(modelf)
        els2 = NamedElements(model)

        # Comment and tag are intact
        s2 = getattr(els2, tag)
        self.assertEqual(id, s2.id)
        self.assertEqual(s2.comment.value, comment)

        os.close(fd)
        os.remove(modelf)
Exemple #14
0
    def runTest(self):
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z)

        m1 = model.insert_new(1, surface.Standard)

        m1.coating.set_value("METAL")
        self.assertEqual(m1.coating.value, "METAL")
        self.assertEqual(m1.coating.get_value(), "METAL")

        # We allow direct access to attributes values (similar to Django Model)
        m1.coating = "METAL2"
        self.assertEqual(m1.coating.value, "METAL2")
        self.assertEqual(repr(m1.coating), repr("METAL2"))
        self.assertEqual(str(m1.coating), "METAL2")

        thickness = 3.1
        m1.thickness = thickness
        self.assertAlmostEqual(m1.thickness.value, thickness)
        self.assertAlmostEqual(float(repr(m1.thickness)), thickness)
        self.assertAlmostEqual(float(str(m1.thickness)), thickness)
Exemple #15
0
    def runTest(self):
        z = Connection()
        z.NewLens()
        model = SurfaceSequence(z, empty=True)
        build_coord_break_sequence(model)

        # set each surface to be the global reference, in turn
        last = None
        for surf in model:
            surf.make_global_reference()
            self.assertTrue(surf.is_global_reference)
            if last is not None:
                self.assertFalse(last.is_global_reference)
            rot, offset = z.GetGlobalMatrix(surf.get_surf_num())
            self.assertAlmostEqual(abs(rot - numpy.eye(3)).max(), 0)
            self.assertAlmostEqual(abs(offset).max(), 0)
            last = surf
Exemple #16
0
 def setUp(self):
     self.z = Connection()
     self.model = SurfaceSequence(self.z, empty=True)
     make_singlet(self.z)
Exemple #17
0
class RayCoordinates(unittest.TestCase):
    marginal_ray_solve_pupil_coordinate = 0.7
    tracing_accuracy = 4  # expected accuracy in decimal places

    def setUp(self):
        self.z = Connection()
        self.z.NewLens()
        self.model = SurfaceSequence(self.z)
        self.system = SystemConfig(self.z)
        self.system.rayaimingtype = 0

        self.model[0].thickness = 10.0

        # insert fold mirror
        self.model.append_new(surface.CoordinateBreak, rotate_y=40.0,
                              rotate_z=10.0)
        self.model.append_new(surface.Standard, glass="MIRROR")
        cb = self.model.append_new(surface.CoordinateBreak, thickness=-20.0)
        cb.rotate_x.align_to_chief_ray()
        cb.rotate_y.align_to_chief_ray()

        front = self.model.append_new(surface.Standard,
                                      curvature=-0.05, glass="BK7",
                                      thickness=-1.0)
        back = self.model.append_new(surface.Standard,
                                     curvature=-front.curvature.linked())

        self.z.SetSystemAper(3, front.get_surf_num(), 2.5)
        back.thickness.focus_on_next(self.marginal_ray_solve_pupil_coordinate)

        self.z.GetUpdate()

    def testFocus(self):
        image = self.model[-1]
        chief = image.get_ray_intersect()
        marginal = image.get_ray_intersect(
            (0, 0), (0, self.marginal_ray_solve_pupil_coordinate), 0)
        self.assertAlmostEqual(abs(marginal.intersect - chief.intersect).max(),
                               0.0)

    def testDirectTracing(self):
        """Verify that we can launch rays using normalised pupil coordinates and local
        surface cartesian coordinates, with consistent results."""

        pc = (0.3, 0.5)  # normalised pupil coordinate under test
        image = self.model[-1]
        # find ray intersection on image plane
        (status, vigcode, im_intersect, im_exit_cosines, normal,
         intensity) = image.get_ray_intersect((0, 0), pc)
        for surf in self.model:
            # get ray intersection on surface
            (status, vigcode, surf_intersect, exit_cosines, normal,
             intensity) = surf.get_ray_intersect((0, 0), pc)

            # Launch ray directly using the obtained origin and exit cosines.
            # GetTraceDirect launches a ray from startsurf coordinate
            # frame, but the ray does not interact with startsurf.

            (status, vigcode, intersect, cosines, normal,
             intensity) = self.z.GetTraceDirect(0, 0,
                                                surf.get_surf_num(),
                                                image.get_surf_num(),
                                                surf_intersect,
                                                exit_cosines)

            # verify that the ray is the same as obtained with
            # normalised pupil coordinates on the image plane
            self.assertAlmostEqual(abs(intersect - im_intersect).max(), 0.0,
                                   self.tracing_accuracy)
            self.assertAlmostEqual(abs(cosines - im_exit_cosines).max(), 0.0,
                                   self.tracing_accuracy)
            if surf.id != image.id:
                self.assertNotAlmostEqual(
                    abs(surf_intersect - im_intersect).max(),
                    0.0, self.tracing_accuracy)

    def testMatrixCoordinateTransforms(self):
        """Check we can acquire and use global transformation matrices.

        Make each surface the coordinate global reference in turn.
        For each iteration check we can recover the original global
        reference of each surface by applying the inverse of the new
        global reference."""

        def trans_mat(rotation, offset):
            m = numpy.zeros((4, 4), float)
            m[0:3, 0:3] = rotation
            m[0:3, 3] = offset
            m[3, 3] = 1.0
            return numpy.matrix(m)

        surf_ids = range(len(self.model))
        initial_global_ref = self.system.globalrefsurf
        initial_surface_coord_frames = [
            trans_mat(*self.z.GetGlobalMatrix(i)) for i in surf_ids]

        for i in surf_ids:
            if isinstance(self.model[i], surface.CoordinateBreak):
                # coordinate breaks as global reference surfaces give
                # unexpected results
                continue

            self.system.globalrefsurf = i
            # find inverse transformation
            trans = initial_surface_coord_frames[i].I

            self.z.GetUpdate()
            for j in surf_ids:
                new_frame = trans_mat(*self.z.GetGlobalMatrix(j))
                # calc_frame = numpy.dot(trans,
                #     initial_surface_coord_frames[j])
                calc_frame = trans * initial_surface_coord_frames[j]
                self.assertAlmostEqual(abs(new_frame - calc_frame).max(), 0)

    def testCheckRayTraceResults(self):
        pc = (0.3, 0.5)  # normalised pupil coordinate under test
        for surf in self.model:
            n = surf.get_surf_num()
            # get ray intersection on surface in local coordinates
            # (status, vigcode, intersect, exit_cosines, normal,
            # intensity) = surf.get_ray_intersect((0,0), pc)
            ray = surf.get_ray_intersect((0, 0), pc)
            # compare with values obtained from operands
            for val, op in zip(ray.intersect, ("REAX", "REAY", "REAZ")):
                opval = self.z.OperandValue(op, n, 0, 0.0, 0.0, pc[0], pc[1])
                self.assertAlmostEqual(opval, val, places=5)

            # get ray intersection on surface in global coordinates
            # (status, vigcode, intersect_gl, exit_cosines, normal,
            # intensity) = surf.get_ray_intersect((0,0), pc, _global=True)
            glray = surf.get_ray_intersect((0, 0), pc, _global=True)
            # compare with direct global coordinates from operands
            for val, op in zip(glray.intersect, ("RAGX", "RAGY", "RAGZ")):
                opval = self.z.OperandValue(op, n, 0, 0.0, 0.0, pc[0], pc[1])
                self.assertAlmostEqual(opval, val, self.tracing_accuracy)
Exemple #18
0
 def setUp(self):
     self.z = Connection()
     self.z.NewLens()
     self.system = SystemConfig(self.z)
     self.model = SurfaceSequence(self.z)
Exemple #19
0
class ConfigureSystemParameters(unittest.TestCase):
    # numsurfs = SystemParameter(0, int)
    # unitcode = SystemParameter(1, int)
    # stopsurf = SystemParameter(2, int)
    # nonaxialflag = SystemParameter(3, bool)
    # rayaimingtype = SystemParameter(4, int)
    # adjustindex = SystemParameter(5, bool)
    # temperature = SystemParameter(6, float)
    # pressure = SystemParameter(7, float)
    # globalrefsurf = SystemParameter(8, float)

    def setUp(self):
        self.z = Connection()
        self.z.NewLens()
        self.system = SystemConfig(self.z)
        self.model = SurfaceSequence(self.z)

    def testSurfaceNumbers(self):
        n = self.system.numsurfs
        self.assertEqual(n, 2)
        self.model.append_new(surface.Standard)
        self.assertEqual(n+1, self.system.numsurfs)

    def testGlobalReferenceSurface(self):
        newglref = 2
        oldglref = self.system.globalrefsurf
        self.assertNotEqual(newglref, oldglref)
        self.system.globalrefsurf = newglref
        # self.z.GetUpdate()
        self.assertEqual(self.system.globalrefsurf, newglref)

    def testStopSurface(self):
        newstop = 2
        oldstop = self.system.stopsurf
        self.assertNotEqual(newstop, oldstop)
        self.system.stopsurf = newstop
        self.assertEqual(self.system.stopsurf, newstop)

    def testAdjustIndex(self):
        old = self.system.adjustindex
        new = not old
        self.system.adjustindex = new
        self.assertEqual(self.system.adjustindex, new)

    def testTemperature(self):
        new = -40.0
        old = self.system.temperature
        self.assertNotAlmostEqual(new, old)
        self.system.temperature = new
        self.assertAlmostEqual(new, self.system.temperature)

    def testPressure(self):
        new = 1.1
        old = self.system.pressure
        self.assertNotAlmostEqual(new, old)
        self.system.pressure = new
        self.assertAlmostEqual(new, self.system.pressure)

    def testRayAiming(self):
        new = 1
        old = self.system.rayaimingtype
        self.assertNotEqual(new, old)
        self.system.rayaimingtype = new
        self.assertEqual(self.system.rayaimingtype, new)
Exemple #20
0
 def setUp(self):
     self.z = Connection()
     self.z.NewLens()
     self.model = SurfaceSequence(self.z, empty=True)
     self.first, self.last = build_coord_break_sequence(self.model)
Exemple #21
0
class CoordinateReturn(unittest.TestCase):
    def setUp(self):
        self.z = Connection()
        self.z.NewLens()
        self.model = SurfaceSequence(self.z, empty=True)
        self.first, self.last = build_coord_break_sequence(self.model)

    def testZemaxCoordinateReturn(self):
        cb = self.model.append_new(surface.CoordinateBreak)
        return_surf = cb.get_surf_num()
        self.z.SetSurfaceData(return_surf, 81, self.first)
        self.z.SetSurfaceData(return_surf, 80, 3)  # orientation + offset
        self.z.GetUpdate()
        self.coord_return_common_tests(return_surf)

    def testLibraryCoordinateReturn(self):
        cb = self.model.append_new(surface.CoordinateBreak)
        cb.return_to(self.model[self.first])
        self.z.GetUpdate()
        self.coord_return_common_tests(cb.get_surf_num())
        # To unset the coordinate return, pass None (has no effect here)
        cb.return_to(None)  # unset coordinate return status

    def testFull(self):
        return_surf = return_to_coordinate_frame(self.model, self.first,
                                                 self.last)
        self.z.GetUpdate()
        self.coord_return_common_tests(return_surf)

    def testOmitZeroThicknesses(self):
        self.z.GetUpdate()
        return_surf = return_to_coordinate_frame(self.model,
                                                 self.first,
                                                 self.last,
                                                 include_null_transforms=False)
        self.z.GetUpdate()
        self.coord_return_common_tests(return_surf)

    def testWithCursor(self):
        insert_point = self.last
        insertion_point_sequence = count(insert_point+1)

        def factory():
            return self.model.insert_new(next(insertion_point_sequence),
                                         surface.CoordinateBreak)

        self.z.GetUpdate()
        return_surf = return_to_coordinate_frame(self.model,
                                                 self.first,
                                                 self.last,
                                                 include_null_transforms=False,
                                                 factory=factory)
        self.z.GetUpdate()
        self.coord_return_common_tests(return_surf)

    def testWithAppend(self):
        def factory():
            return self.model.append_new(surface.CoordinateBreak)
        self.z.GetUpdate()
        return_surf = return_to_coordinate_frame(self.model,
                                                 self.first,
                                                 self.last,
                                                 include_null_transforms=False,
                                                 factory=factory)
        self.z.GetUpdate()
        self.coord_return_common_tests(return_surf)

    def coord_return_common_tests(self, return_surf):
        first_rot, first_offset = self.z.GetGlobalMatrix(self.first)
        last_rot, last_offset = self.z.GetGlobalMatrix(self.last)
        return_rot, return_offset = self.z.GetGlobalMatrix(return_surf + 1)

        # check coordinate frames are identical
        self.assertAlmostEqual(abs(first_rot - return_rot).max(), 0)
        self.assertAlmostEqual(abs(first_offset - return_offset).max(), 0)

        # check we have finite rotation matrices
        self.assertNotAlmostEqual(abs(first_rot).max(), 0)

        # check that first and last frames differ
        self.assertNotAlmostEqual(abs(first_rot - last_rot).max(), 0)
        self.assertNotAlmostEqual(abs(first_offset - last_offset).max(), 0)
Exemple #22
0
class SurfaceSequenceManipulate(unittest.TestCase):
    """Check that semantics of SurfaceSequence are close to Python list type.

    """
    def setUp(self):
        self.z = Connection()
        self.z.NewLens()
        self.model = SurfaceSequence(self.z, empty=True)
        self.model[0].comment.value = "OBJ"
        self.model[-1].comment.value = "IMG"
        self._list = ["OBJ", "IMG"]

    def verifyIdentical(self):
        self.z.GetUpdate()
        self.assertEqual(len(self._list), len(self.model))
        for a, s in zip(self._list, self.model):
            self.assertEqual(a, s.comment.value)

    def testInit(self):
        self.verifyIdentical()

    def testInsert(self):
        self.model.insert_new(1, surface.Standard, "Inserted 1")
        self._list.insert(1, "Inserted 1")

        self.model.insert_new(-1, surface.Standard, "Inserted -1")
        self._list.insert(-1, "Inserted -1")

        self.verifyIdentical()

    def testDelete(self):
        self.model.insert_new(1, surface.Standard, "Inserted 1")
        self._list.insert(1, "Inserted 1")

        self.model.insert_new(-1, surface.Standard, "Inserted -1")
        self._list.insert(-1, "Inserted -1")

        self.verifyIdentical()

        del self.model[1]
        del self._list[1]

        self.verifyIdentical()

        del self.model[-2]
        del self._list[-2]

        self.verifyIdentical()

    def testGetItem(self):
        self.model.insert_new(1, surface.Standard, "Inserted 1")
        self._list.insert(1, "Inserted 1")

        for i in range(len(self.model)):
            self.assertEqual(self.model[i].comment.value, self._list[i])
            self.assertEqual(self.model[-i].comment.value, self._list[-i])

    def testAppendItem(self):
        # Here the behaviour differs. The surface is inserted before
        # the last (image) surface
        self.model.insert_new(1, surface.Standard, "Inserted 1")
        self._list.insert(1, "Inserted 1")

        self.model.append_new(surface.Standard, "Appended")
        self._list.insert(-1, "Appended")

        self.verifyIdentical()

    def testIndexing(self):
        new_surf = self.model.insert_new(1, surface.Grating, "Inserted 1")
        indexed_surf = self.model[1]

        self.assertEqual(new_surf.id, indexed_surf.id)
        # check that model retrieves surface object with correct class
        self.assertEqual(new_surf.__class__, indexed_surf.__class__)