def test_m3_stepping_locked() -> None: m3 = M3(rotors=(("III", "U"), ("II", "A"), ("I", "A")), reflector="B", locked=True) assert m3.rotor_positions() == ["U", "A", "A"] m3.transform_character("A") assert m3.rotor_positions() == ["U", "A", "A"] m3.transform_character("A") assert m3.rotor_positions() == ["U", "A", "A"]
def test_m3_initialisation() -> None: m3 = M3(rotors=(("I", "A"), ("II", "A"), ("III", "A")), reflector="B") assert len(m3.rotors) == 3 assert m3.rotors[0].type == "I" assert m3.rotors[1].type == "II" assert m3.rotors[2].type == "III" assert m3.reflector.type == "B" assert m3.plugboard.map == {}
def test_m3_stepping_normal() -> None: m3 = M3(rotors=(("III", "U"), ("II", "A"), ("I", "A")), reflector="B") assert m3.rotor_positions() == ["U", "A", "A"] m3.transform_character("A") assert m3.rotor_positions() == ["V", "A", "A"] m3.transform_character("A") assert m3.rotor_positions() == ["W", "B", "A"] m3.transform_character("A") assert m3.rotor_positions() == ["X", "B", "A"]
def test_m3_transform_spaces_ignored() -> None: m3 = M3(rotors=(("I", "A"), ("II", "A"), ("III", "A")), reflector="B") assert m3.transform_string("Hello World") == "MFNCZBBFZM"
def test_m3_transform_invalid_character() -> None: with pytest.raises(InputException, match=r"Input must be between A-Z"): m3 = M3(rotors=(("I", "A"), ("II", "A"), ("III", "A")), reflector="B") m3.transform_character("[")
def test_m3_transform_string(settings, input, output) -> None: assert M3(**settings).transform_string(input) == output assert M3(**settings).transform_string(output) == input