コード例 #1
0
def test_letter_add_possibilities():
    code = "osxwkvosxb"
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    ha = hack(code, alphabet, many_char)
    char = letter('c', ha)
    char.add_possibilities(3)
    assert len(char.possibilities) == 3
    code = "osxwkvosxb"
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    ha = hack(code, alphabet, many_char)
    char = letter('d', ha)
    char.add_possibilities(5)
    assert len(char.possibilities) == 5
コード例 #2
0
def test_count_and_sort():
    code = "osxwkvosxb"
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    ha = hack(code, alphabet, many_char)
    ha.count_and_sort()
    assert ha.sort_counts == [('o', 2),
                              ('s', 2),
                              ('x', 2),
                              ('b', 1),
                              ('k', 1),
                              ('v', 1),
                              ('w', 1),
                              ('a', 0),
                              ('c', 0),
                              ('d', 0),
                              ('e', 0),
                              ('f', 0),
                              ('g', 0),
                              ('h', 0),
                              ('i', 0),
                              ('j', 0),
                              ('l', 0),
                              ('m', 0),
                              ('n', 0),
                              ('p', 0),
                              ('q', 0),
                              ('r', 0),
                              ('t', 0),
                              ('u', 0),
                              ('y', 0),
                              ('z', 0)]
コード例 #3
0
def test_hack_init():
    ha = hack("coDe", alphabet="ABC", many_char="Efj")
    assert ha.code == "code"
    assert ha.alphabet == "abc"
    assert ha.many_char == list("efj")
    assert ha.sort_counts == []
    assert ha.letters == []
    assert ha.finished == []
コード例 #4
0
def test_get_index():
    code = "osxwkvosxb"
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    ha = hack(code, alphabet, many_char)
    char = letter('c', ha)
    assert char.get_index("a") == 0
    assert char.get_index("b") == 1
コード例 #5
0
def test_letter_init():
    code = "osxwkvosxb"
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    ha = hack(code, alphabet, many_char)
    char = letter('c', ha)
    assert char.char == 'c'
    assert type(char.hack) == hack
コード例 #6
0
def test_letter_add_possibilities_stupid():
    code = "osxwkvosxb"
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    ha = hack(code, alphabet, many_char)
    char = letter('c', ha)
    with pytest.raises(AssertionError):
        char.add_possibilities("a")
コード例 #7
0
def test_add_letters():
    code = "osxwkvosxb"
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    ha = hack(code, alphabet, many_char)
    ha.count_and_sort()
    ha.add_letters()
    assert len(ha.sort_counts) == len(ha.letters)
    assert ha.finished == []
コード例 #8
0
def test_key():
    code = "osxwkvosxb"
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    ha = hack(code, alphabet, many_char)
    ha.count_and_sort()
    ha.add_letters()
    ha.calc_most_used_possibilities()
    assert type(ha.keys[0]) == int
    assert type(ha.key) == set
コード例 #9
0
def test_calc_most_used_possibilities():
    code = "osxwkvosxb"
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    ha = hack(code, alphabet, many_char)
    ha.count_and_sort()
    ha.add_letters()
    ha.calc_most_used_possibilities()
    assert ha.many_char == list("sratdhulcgmobwfkzpvjyxq")
    assert len(ha.finished) == 3
コード例 #10
0
ファイル: main.py プロジェクト: LarsZauberer/Caesar-Hack
if code is None:
    log.error("No code was entered."
              + "Try to start the program with the argument -c")
    sys.exit()
if alphabet is None:
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    log.debug(f"No Alphabet in arguments")
if many_char is None:
    many_char = "enisratdhulcgmobwfkzpvjyxq"
    log.debug(f"No common letters in arguments")
log.debug(f"Finished giving values")

if args["g"]:
    import matplotlib.pyplot as plt
    log.debug(f"Switching to graphics mode")
    ha = hack(code, alphabet, many_char)
    ha.count_and_sort()
    x, y = zip(*ha.sort_counts)

    # Configuring the graphic
    log.debug(f"Configuring the graphic")
    plt.title('Letters used in the code')
    plt.ylabel('How ofthen used')
    plt.xlabel("Letters")
    couleur = ['#000000', '#dbb243', '#2e42d3', '#e54fe3', '#f23434']
    plt.bar(x, y, align='center', alpha=0.6, color=couleur)
    plt.show()
else:
    # Hack the code
    ha = hack(code, alphabet, many_char)
コード例 #11
0
def test_hack_init_stupid():
    with pytest.raises(AssertionError):
        hack(2, 4, 8)
    with pytest.raises(AssertionError):
        hack("code", "ce", "e")
コード例 #12
0
def test_letter_init_stupid():
    with pytest.raises(AssertionError):
        letter(8, hack("", "", ""))
        letter('a', 8)