コード例 #1
0
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"]
コード例 #2
0
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 == {}
コード例 #3
0
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"]
コード例 #4
0
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"
コード例 #5
0
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("[")
コード例 #6
0
def test_m3_transform_string(settings, input, output) -> None:
    assert M3(**settings).transform_string(input) == output
    assert M3(**settings).transform_string(output) == input