def testSizeConstraints(self): """Check if the size constraint really constrains the size. """ usc = UserSizeConstraint(4) at = _core.DoubleArraySlot(1, usc) # Size must be 4 self.assertEqual(at.size(), 4) # resize() must raise an exception self.assertRaises(ValueError, lambda: at.resize(5)) # Resize the constraint usc.setSize(7) self.assertEqual(at.size(), 7) # Check that a slot with a different size cannot serve as controller a2 = _core.DoubleArraySlot(1) a2.resize(10) self.assertRaises(ValueError, lambda: at.setController(a2)) # But it can be controller when it has the same size... a2.resize(7) at.setController(a2) # Check that the controller cannot be resized then... self.assertRaises(ValueError, lambda: a2.resize(10)) self.assertEqual(usc.getSize(), 7) self.assertEqual(at.size(), 7) # Check the isResizable() method self.assertEqual(True, a2.isResizable(7)) self.assertEqual(True, at.isResizable(7)) self.assertEqual(False, a2.isResizable(42)) self.assertEqual(False, at.isResizable(42))
def testExceptions(self): asl = _core.DoubleArraySlot(1) asl.resize(8) self.assertRaises(IndexError, lambda: asl[8]) self.assertRaises(IndexError, lambda: asl.getValue(8)) self.assertRaises(IndexError, lambda: asl.setValue(8,0)) self.assertRaises(TypeError, lambda: asl.setValue(0,vec3())) asl = _core.DoubleArraySlot(2) asl.resize(8) self.assertRaises(IndexError, lambda: asl[8]) self.assertRaises(IndexError, lambda: asl.getValue(8)) self.assertRaises(IndexError, lambda: asl.setValue(8,(1,2))) self.assertRaises(ValueError, lambda: asl.setValue(0,5))
def testResize(self): asl = _core.DoubleArraySlot(1) # Create 8 elements asl.resize(8) self.assertEqual(asl.size(), 8) self.assertEqual(list(asl), 8*[0]) # Set values for i in range(8): asl[i]=i+1 # Check if the values were properly set self.assertEqual(list(asl), range(1,9)) # Enlarge the array asl.resize(20) self.assertEqual(asl.size(), 20) # Check if the values were properly copied self.assertEqual(list(asl), range(1,9)+12*[0]) # Shrink the array asl.resize(4) # Check if the values were properly copied self.assertEqual(list(asl), range(1,5)) # Negative size must equal 0 asl.resize(-2) self.assertEqual(asl.size(), 0)
def testConstructor(self): asl = _core.DoubleArraySlot(1) # array size==0? self.assertEqual(asl.size(), 0) # multiplicity==1? self.assertEqual(asl.multiplicity(), 1) self.assertEqual(list(asl), []) self.assertEqual(asl.getController(), None) asl = _core.DoubleArraySlot() # array size==0? self.assertEqual(asl.size(), 0) # multiplicity==1? self.assertEqual(asl.multiplicity(), 1) self.assertEqual(list(asl), []) asl = _core.DoubleArraySlot(3) # array size==0? self.assertEqual(asl.size(), 0) # multiplicity==3? self.assertEqual(asl.multiplicity(), 3) self.assertEqual(list(asl), [])