Minor documentation updates
[szyfrow.git] / tests / test_caesar.py
1 import pytest
2 import string
3
4 from szyfrow.caesar import *
5 from szyfrow.support.utilities import *
6
7
8 def test_encipher_letter():
9 for p, c in zip(
10 string.ascii_letters,
11 'fghijklmnopqrstuvwxyzabcdeFGHIJKLMNOPQRSTUVWXYZABCDE'):
12 assert caesar_encipher_letter(p, 5) == c
13
14 for p, c in zip(
15 string.ascii_letters,
16 'defghijklmnopqrstuvwxyzabcDEFGHIJKLMNOPQRSTUVWXYZABC'):
17 assert caesar_encipher_letter(p, 3) == c
18
19
20 def test_decipher_letter():
21 for p, c in zip(
22 string.ascii_letters,
23 'fghijklmnopqrstuvwxyzabcdeFGHIJKLMNOPQRSTUVWXYZABCDE'):
24 assert caesar_decipher_letter(c, 5) == p
25
26 for p, c in zip(
27 string.ascii_letters,
28 'defghijklmnopqrstuvwxyzabcDEFGHIJKLMNOPQRSTUVWXYZABC'):
29 assert caesar_decipher_letter(c, 3) == p
30
31 def test_encipher_message():
32 enciphered = caesar_encipher(
33 'hours passed during which jerico tried every trick he could think of',
34 15)
35 expected = 'wdjgh ephhts sjgxcv lwxrw ytgxrd igxts tktgn igxrz wt rdjas iwxcz du'
36 assert enciphered == expected
37
38
39 def test_decipher_message():
40
41 deciphered = caesar_decipher('wdjgh ephhts sjgxcv lwxrw ytgxrd igxts tktgn igxrz wt rdjas iwxcz du',
42 15)
43 expected = 'hours passed during which jerico tried every trick he could think of'
44 assert deciphered == expected
45
46
47 def test_break():
48 ciphertext = '''wdjgh ephhts sjgxcv lwxrw ytgxrd igxts tktgn igxrz wt
49 rdjas iwxcz du id egdbei hdbt ugthw xchexgpixdc. wt pggpcvts iwt
50 rgneidvgpbh rwgdcdadvxrpaan iwtc wt pggpcvts iwtb qn atcviw. iwtc
51 wt hdgits iwtb qn ugtfjtcrn. wt sddsats dc iwt exat du epetg. wt
52 egdlats pgdjcs iwt wji, dqaxkxdjh cdl id lwd lph addzxcv pi wxb
53 pcs lwd lphci.'''
54 expected_key = 15
55 expected_score = -340.6011819
56 actual_key, actual_score = caesar_break(ciphertext)
57 assert expected_key == actual_key
58 assert expected_score == pytest.approx(actual_score)