def test_alloc_boards_compensate_for_dead(self): # When over-allocating, extra boards in the allocation should # compensate for dead boards. a = Allocator(4, 2, dead_boards=set([(0, 0, 2)])) assert a._alloc_boards_possible(24, max_dead_boards=0) is False assert a._alloc_boards(24, max_dead_boards=0) is None assert a._alloc_boards_possible(23, max_dead_boards=0) is True assert len(a._alloc_boards(23, max_dead_boards=0)[1]) == 23
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