示例#1
0
 def test_getRandomIntsGet100(self):
     result = util.getRandomInts(0, 2, 1, 100)
     self.assertEqual(len(result), 100)
     self.assertIn(0, result)
     self.assertIn(1, result)
     self.assertIn(2, result)
     self.assertNotIn(3, result)
示例#2
0
 def test_getRandomIntsGet100Step10(self):
     result = util.getRandomInts(0, 30, 10, 100)
     self.assertEqual(len(result), 100)
     self.assertIn(0, result)
     self.assertIn(10, result)
     self.assertIn(20, result)
     self.assertIn(30, result)
     self.assertNotIn(40, result)
示例#3
0
 def generateTiles(self):
     # enough tiles to hold 1-2 small towns
     if self.size == "tiny":
         # One town can fit in a 5x5 grid (77.5 sq. mi.); two can be crammed
         # into a 5x10 grid (155 sq. mi.), however, two would fit more
         # comfortably in a 10x10 (310 sq. mi.) or 10x15 grid (465 sq. mi.).
         min = 5
         max = 15
         step = 5
         (x, y) = util.getRandomInts(min=min, max=max, step=step, count=2)
         # XXX debug
         print "grid size: (%s, %s)" % (x, y)
         self.tileDimensions = (x, y)
         grid = createEmptyGrid(x, y)
         tile = terrain.getRandomTileClass()
         # let's get the first one started, and then start setting the
         # surrounding tiles
         grid[0][0] = tile
         setSurroundingTiles(tile, 0, 0, grid)
     # enough tiles to hold 3-6 small towns
     elif self.size == "small":
         pass
     # enough tiles to hold one large city and a good-sized boundary area
     elif self.size == "medium":
         pass
     # enough tiles to hold something the size of a state in the US
     elif self.size == "large":
         pass
     # enough tiles to hold one country
     elif self.size == "huge":
         pass
     # enough tiles to hold a continent
     elif self.size == "gigantic":
         pass
     # for all non-planetary sized grids, border tiles will be non-passable
     # at the edges
     # enough tiles to hold an Earth-sized planet
     elif self.size == "planetary":
         pass
     self.grid = grid
     # XXX debug
     self.printTiles()
示例#4
0
 def test_getRandomIntsGetOne(self):
     result = util.getRandomInts(0, 1, 1, 1)
     self.assertEqual(len(result), 1)
示例#5
0
 def test_getRandomIntsGet2Step5(self):
     result = util.getRandomInts(min=5, max=15, step=5, count=2)
     self.assertEqual(len(result), 2)
     self.assertIn(True, [x in result for x in [5, 10, 15]])
     self.assertNotIn(0, result)
     self.assertNotIn(1, result)