Beispiel #1
0
	def test_distance( self ):
		rows, cols = ( 8, 8 )
		tests = [
			( ( 0, 0 ), ( 1, 0 ), 1 ),
			( ( 0, 0 ), ( 1, 1 ), 1 ),
			( ( 0, 0 ), ( 1, 2 ), 2 ),
			( ( 5, 3 ), ( 9, 5 ), 4 ),
			( ( 9, 5 ), ( 5, 3 ), 4 ),
			( ( 7, 4 ), ( 3, 2 ), 4 ),
		]

		m = Map( ( rows, cols ) )

		for start, end, distance in tests:
			d = m.distance( start, end )
			self.assertTrue( distance == d,
				"Distance between %s, %s, expected to be %s, got %s"
				% ( start, end, distance, d ) )
Beispiel #2
0
    def test_distance(self):
        rows, cols = (8, 8)
        tests = [
            ((0, 0), (1, 0), 1),
            ((0, 0), (1, 1), 1),
            ((0, 0), (1, 2), 2),
            ((5, 3), (9, 5), 4),
            ((9, 5), (5, 3), 4),
            ((7, 4), (3, 2), 4),
        ]

        m = Map((rows, cols))

        for start, end, distance in tests:
            d = m.distance(start, end)
            self.assertTrue(
                distance == d, "Distance between %s, %s, expected to be %s, got %s" % (start, end, distance, d)
            )
Beispiel #3
0
	def test_size( self ):
		sizes = [ ( 1, 1 ), ( 2, 2 ), ( 3, 4 ), ( 5, 5 ), ( 10, 8 ) ]

		for rows, cols in sizes:
			m = Map( ( rows, cols ) )
			size = m.size
			self.assertTrue( rows == size[0],
				"Map %s returned %s rows, expected %s." % ( m, size[0], rows ) )

			self.assertTrue( cols == size[1],
				"Map %s returned %s rows, expected %s." % ( m, size[1], cols ) )
Beispiel #4
0
	def test_neighbors( self ):
		tests = {
			( 0, 0 ) : [ ( 1, 0 ), ( 1, 1 ) ],
			( 1, 2 ) : [ ( 1, 1 ), ( 2, 2 ), ( 2, 3 ) ],
			( 1, 1 ) : [ ( 0, 0 ), ( 1, 0 ), ( 2, 1 ), ( 2, 2 ), ( 1, 2 ) ],
			( 2, 1 ) : [ ( 1, 1 ), ( 1, 0 ), ( 2, 0 ), ( 3, 1 ), ( 3, 2 ), ( 2, 2 ) ],
			( 7, 0 ) : [ ( 6, 0 ), ( 7, 1 ), ( 8, 1 ) ],
			( 8, 1 ) : [ ( 7, 0 ), ( 7, 1 ), ( 8, 2 ) ],
			( 3, 6 ) : [ ( 3, 5 ), ( 4, 6 ), ( 4, 7 ) ],
			( 4, 7 ) : [ ( 3, 6 ), ( 4, 6 ), ( 5, 7 ) ],
			( 9, 4 ) : [ ( 9, 3 ), ( 8, 3 ), ( 8, 4 ), ( 9, 5 ), ( 10, 5 ) ],
			( 11, 7 ): [ ( 10, 6 ), ( 10, 7 ) ]
		}

		m = Map( ( 8, 8 ) )
		for node, results in tests.items():
			neighbors = m.neighbors( node )
			self.assertEqual( set( neighbors ), set( results ),
				"Got incorrect neighbors for node %s:\n Expected: %s\nReceived: %s"
				% ( node, results, neighbors ) )
Beispiel #5
0
    def test_neighbors(self):
        tests = {
            (0, 0): [(1, 0), (1, 1)],
            (1, 2): [(1, 1), (2, 2), (2, 3)],
            (1, 1): [(0, 0), (1, 0), (2, 1), (2, 2), (1, 2)],
            (2, 1): [(1, 1), (1, 0), (2, 0), (3, 1), (3, 2), (2, 2)],
            (7, 0): [(6, 0), (7, 1), (8, 1)],
            (8, 1): [(7, 0), (7, 1), (8, 2)],
            (3, 6): [(3, 5), (4, 6), (4, 7)],
            (4, 7): [(3, 6), (4, 6), (5, 7)],
            (9, 4): [(9, 3), (8, 3), (8, 4), (9, 5), (10, 5)],
            (11, 7): [(10, 6), (10, 7)],
        }

        m = Map((8, 8))
        for node, results in tests.items():
            neighbors = m.neighbors(node)
            self.assertEqual(
                set(neighbors),
                set(results),
                "Got incorrect neighbors for node %s:\n Expected: %s\nReceived: %s" % (node, results, neighbors),
            )
Beispiel #6
0
    def test_direction(self):
        rows, cols = (8, 8)
        m = Map((rows, cols))

        # Test dominated directions
        tests = [
            ((0, 0), (1, 0), (1, 0)),
            ((0, 0), (1, 1), (1, 1)),
            ((0, 0), (0, 1), (0, 1)),
            ((0, 1), (0, 0), (0, -1)),
            ((1, 1), (0, 0), (-1, -1)),
            ((1, 0), (0, 0), (-1, 0)),
            ((0, 0), (3, 1), (1, 0)),
            ((5, 3), (8, 5), (1, 1)),
            ((8, 5), (5, 3), (-1, -1)),
        ]

        for start, end, direction in tests:
            d = m.direction(start, end)
            self.assertTrue(
                direction == d,
                "Direction between %s, %s, expected to be %s, got %s" %
                (start, end, direction, d))

        # Test directions with a random component
        tests = [
            ((0, 0), (2, 1), [(1, 0), (1, 1)]),
            ((2, 2), (3, 4), [(0, 1), (1, 1)]),
            ((5, 4), (6, 3), [(1, 0), (0, -1)]),
            ((6, 3), (5, 4), [(-1, 0), (0, 1)]),
        ]

        for start, end, directions in tests:
            d = m.direction(start, end)
            self.assertTrue(
                d in directions,
                "Direction between %s, %s, expected to be in %s, got %s" %
                (start, end, directions, d))
Beispiel #7
0
    def test_direction(self):
        rows, cols = (8, 8)
        m = Map((rows, cols))

        # Test dominated directions
        tests = [
            ((0, 0), (1, 0), (1, 0)),
            ((0, 0), (1, 1), (1, 1)),
            ((0, 0), (0, 1), (0, 1)),
            ((0, 1), (0, 0), (0, -1)),
            ((1, 1), (0, 0), (-1, -1)),
            ((1, 0), (0, 0), (-1, 0)),
            ((0, 0), (3, 1), (1, 0)),
            ((5, 3), (8, 5), (1, 1)),
            ((8, 5), (5, 3), (-1, -1)),
        ]

        for start, end, direction in tests:
            d = m.direction(start, end)
            self.assertTrue(
                direction == d, "Direction between %s, %s, expected to be %s, got %s" % (start, end, direction, d)
            )

            # Test directions with a random component
        tests = [
            ((0, 0), (2, 1), [(1, 0), (1, 1)]),
            ((2, 2), (3, 4), [(0, 1), (1, 1)]),
            ((5, 4), (6, 3), [(1, 0), (0, -1)]),
            ((6, 3), (5, 4), [(-1, 0), (0, 1)]),
        ]

        for start, end, directions in tests:
            d = m.direction(start, end)
            self.assertTrue(
                d in directions, "Direction between %s, %s, expected to be in %s, got %s" % (start, end, directions, d)
            )
Beispiel #8
0
	def setUp( self ):
		self.map = Map( ( 5, 5 ) )
		self.map.units = Grid()