-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtest_brute.py
91 lines (65 loc) · 2.18 KB
/
test_brute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Test suite."""
from types import GeneratorType
from unittest import TestCase
from brute import brute
class TestBrute(TestCase):
def test_brute_length_default(self):
last_str = ''
for pw in brute():
last_str = pw
self.assertEqual(len(last_str), 3)
def test_brute_returns_generator(self):
self.assertIsInstance(brute(), GeneratorType)
def test_letters_numbers_symbols_whitespace_default(self):
letters = False
numbers = False
symbols = False
whitespace = True
for pw in brute():
if 'a' in pw:
letters = True
elif '1' in pw:
numbers = True
elif '!' in pw:
symbols = True
elif ' ' in pw:
whitespace = False
self.assertTrue(letters)
self.assertTrue(numbers)
self.assertTrue(symbols)
self.assertTrue(whitespace)
def test_disable_letters(self):
letters = True
for pw in brute(letters=False):
if 'a' in pw:
letters = False
self.assertTrue(letters)
def test_disable_numbers(self):
numbers = True
for pw in brute(numbers=False):
if '1' in pw:
numbers = False
self.assertTrue(numbers)
def test_disable_symbols(self):
symbols = True
for pw in brute(symbols=False):
if '!' in pw:
symbols = False
self.assertTrue(symbols)
def test_enable_spaces(self):
spaces = False
for pw in brute(spaces=True):
if ' ' in pw:
spaces = True
self.assertTrue(spaces)
def test_ramp(self):
for pw in brute(length=3, ramp=False):
self.assertEqual(len(pw), 3)
def test_ramp_start_length(self):
for pw in brute(start_length=2, length=3, ramp=True):
self.assertTrue(len(pw) >= 2)
def test_ramp_bad_start_length(self):
for pw in brute(start_length=0, length=3, ramp=True):
self.assertTrue(len(pw) >= 1)
for pw in brute(start_length=4, length=3, ramp=True):
self.assertTrue(len(pw) < 4)