import pytest import main ######### # In order to reduce the dependency of method shifting(), # the position is not explicitly checked. ######### @pytest.fixture(autouse=True) def patch_log(monkeypatch): monkeypatch.setattr(main, "log", lambda msg: None) monkeypatch.setattr(main, "logvv", lambda msg: None) def test_single_item_no_match(): matrixdims = (6, 3) pos = (0,0) before = {1:pos} after = main.make_pos_free((2, 3), before, matrixdims) assert after[1] == pos def test_single_item_match_at_0_0(): pos = (0,0) before = {1:pos} matrixdims = (6, 3) after = main.make_pos_free(pos, before, matrixdims) assert after[1] != pos def test_single_item_match_at_horizont(): pos = (0, 1) before = {1:pos} # Y # 0 # 1 <--- Horizon # 2 matrixdims = (99, 2) after = main.make_pos_free(pos, before, matrixdims) assert after[1] != pos def test_single_item_match_at_upper(): pos = (0, 0) before = {1:pos} # Y # 0 # 1 <--- Horizon # 2 matrixdims = (99, 2) after = main.make_pos_free(pos, before, matrixdims) assert after[1] != pos def test_single_item_match_at_lower(): pos = (0, 2) before = {1:pos} # Y # 0 ^ # 1 <--- Horizon | Lower | Upper # 2 V matrixdims = (99, 2) after = main.make_pos_free(pos, before, matrixdims) assert after[1] != pos def test_first_item(): pos = (1,1) matrixdims = (6, 3) before = [] after = main.make_pos_free(pos, before, matrixdims) assert len(after) == 0 def test_check_direct_neighbours_upwards(): matrixdims = (1000, 1000) pos = (100,200) before = { 1:(pos[main.P.X] , pos[main.P.Y] ), 2:(pos[main.P.X] , pos[main.P.Y]-1 ), } after = main.make_pos_free(pos, before, matrixdims) for i in after: for j in after: if i == j: continue assert after[j] != after[i], f"i={i}, j={j}: Two items may not have the same position: {after[i]}" def test_multiple_item_no_match(): matrixdims = (6, 3) pos = (1,1) before = { 1:(pos[main.P.X]+1, pos[main.P.Y] ), 2:(pos[main.P.X]-1, pos[main.P.Y] ), 3:(pos[main.P.X] , pos[main.P.Y]+1), 4:(pos[main.P.X] , pos[main.P.Y]-1), 5:(pos[main.P.X]+1, pos[main.P.Y]+1), 6:(pos[main.P.X]+1, pos[main.P.Y]-1), 7:(pos[main.P.X]-1, pos[main.P.Y]+1), 8:(pos[main.P.X]-1, pos[main.P.Y]-1), } after = main.make_pos_free(pos, before, matrixdims) for i in after: for j in after: if i == j: continue assert after[j] != after[i], f"i={i}, j={j}: Two items may not have the same position: {after[i]}"