def testTwoPages(self): arena = fract4dc.arena_create(10,2) alloc = fract4dc.arena_alloc(arena, 8, 1, 9) # fills first page alloc = fract4dc.arena_alloc(arena, 8, 1, 9) # forces second page # shouldn't work self.assertRaises(MemoryError, fract4dc.arena_alloc,arena, 8, 1, 10)
def testMultipleAllocs(self): arena = fract4dc.arena_create(10,1) for i in xrange(5): fract4dc.arena_alloc(arena,8,1,1) # should be full now self.assertRaises(MemoryError, fract4dc.arena_alloc,arena,8,1,1)
def testReadArrayVal(self): arena = fract4dc.arena_create(10,1) alloc = fract4dc.arena_alloc(arena, 4, 1, 10) for i in xrange(10): result = fract4dc.array_get_int(alloc,1,i) self.assertEqual( (0,1), result, "bad result %s for %d" % (result, i)) self.assertEqual((-1,0), fract4dc.array_get_int(alloc,1, 10)) self.assertEqual((-1,0), fract4dc.array_get_int(alloc,1, -1))
def testReadAndWriteArray(self): arena = fract4dc.arena_create(10,1) alloc = fract4dc.arena_alloc(arena, 4, 1, 10) for i in xrange(10): val = i result = fract4dc.array_set_int(alloc,1, i,val) self.assertEqual(1,result) for i in xrange(10): result = fract4dc.array_get_int(alloc,1, i) self.assertEqual( (i,1), result, "bad result %s for %d" % (result, i)) self.assertEqual((-1,0), fract4dc.array_get_int(alloc,1,10)) self.assertEqual((-1,0), fract4dc.array_get_int(alloc,1,-1)) self.assertEqual(0, fract4dc.array_set_int(alloc,1,10,99)) self.assertEqual(0, fract4dc.array_set_int(alloc,1,-1,99))
def testTwoDimensions(self): arena = fract4dc.arena_create(10,2) alloc = fract4dc.arena_alloc(arena, 8, 2, 2, 3) i = 0 for y in xrange(2): for x in xrange(3): result = fract4dc.array_set_int(alloc,2, i, y, x) self.assertEqual( 1,result, "bad set for %d,%d" % (x,y)) #print "%d,%d => %d" % (x,y,i) i += 1 i = 0 for y in xrange(2): for x in xrange(3): val = fract4dc.array_get_int(alloc,2, y, x) #print "%d,%d <= %d" % (x,y,i) self.assertEqual( (i,1), val, "bad result %s instead of %s for %d,%d" % (val,(i,1),x,y)) i += 1
def testArenaAlloc(self): arena = fract4dc.arena_create(100,1) alloc = fract4dc.arena_alloc(arena, 1,1,10) alloc = fract4dc.arena_alloc(arena, 10,1,1)