예제 #1
0
    def test_alloc_board_possible(self):
        a = Allocator(2, 3)

        # Should fail if the board is outside the system
        assert a._alloc_board_possible(-1, 0, 0) is False
        assert a._alloc_board_possible(0, -1, 0) is False
        assert a._alloc_board_possible(-1, -1, 0) is False
        assert a._alloc_board_possible(0, 3, 0) is False
        assert a._alloc_board_possible(2, 0, 0) is False
        assert a._alloc_board_possible(2, 3, 0) is False
        assert a._alloc_board_possible(0, 0, -1) is False
        assert a._alloc_board_possible(0, 0, 3) is False

        # Should fail if the required board is dead
        a.dead_boards.add((0, 0, 1))
        assert a._alloc_board_possible(0, 0, 1) is False

        # Should fail if all the boards are dead
        a.dead_boards = set((x, y, z)
                            for x in range(2)
                            for y in range(3)
                            for z in range(3))
        assert a._alloc_board_possible() is False
        assert a._alloc_board_possible(0, 0, 0) is False

        a.dead_boards = set()

        # Otherwise should succeed
        assert a._alloc_board_possible() is True
        assert a._alloc_board_possible(0, 0, 0) is True
예제 #2
0
    def test_all_boards_possible(self):
        a = Allocator(3, 4)

        # Fail too big
        assert a._alloc_boards_possible(4*4*3) is False

        # Fail too small
        assert a._alloc_boards_possible(0) is False
        assert a._alloc_boards_possible(-1) is False

        # Fail torus wrong size
        assert a._alloc_boards_possible(2*4*3, require_torus=True) is False

        # Fail due to (0, 0, 0) being dead
        a.dead_boards.add((0, 0, 0))
        assert a._alloc_boards_possible(3*4*3) is False

        # Fail due to corners being dead and requiring nothing to be dead
        a.dead_boards.add((0, 3, 0))
        a.dead_boards.add((2, 0, 0))
        a.dead_boards.add((2, 3, 0))
        assert a._alloc_boards_possible(2*2*3, max_dead_boards=0) is False

        # Fail due to all working links being required
        a.dead_boards = set()
        a.dead_links.add((0, 0, 0, Links.north))
        a.dead_links.add((0, 3, 0, Links.north))
        a.dead_links.add((2, 0, 0, Links.north))
        a.dead_links.add((2, 3, 0, Links.north))
        assert a._alloc_boards_possible(2*2*3, max_dead_links=0) is False

        # Finally, should be possible to succeed when we relax the criteria
        assert a._alloc_boards_possible(2*2*3) is True