-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidate_test.v
127 lines (99 loc) · 3.27 KB
/
validate_test.v
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
module passvalid
import math
fn test_remove_more_than_two() {
assert remove_more_than_two('12345678', '0123456789') == '12'
assert remove_more_than_two('abcqwertyabc', 'qwertyuiop') == 'abcqwabc'
assert remove_more_than_two('', '') == ''
assert remove_more_than_two('', '12345') == ''
}
fn test_remove_repeating_chars() {
mut actual := remove_more_than_two_repeating_chars('aaaa')
mut expected := 'aa'
assert actual == expected
actual = remove_more_than_two_repeating_chars('bbbbbbbaaaaaaaaa')
expected = 'bbaa'
assert actual == expected
actual = remove_more_than_two_repeating_chars('ab')
expected = 'ab'
assert actual == expected
actual = remove_more_than_two_repeating_chars('')
expected = ''
assert actual == expected
}
fn test_get_length() {
mut actual := get_length('aaaa')
mut expected := 2
assert actual == expected
actual = get_length('11112222')
expected = 4
assert actual == expected
actual = get_length('aa123456')
expected = 4
assert actual == expected
actual = get_length('876543')
expected = 2
assert actual == expected
actual = get_length('qwerty123456z')
expected = 5
assert actual == expected
}
fn test_log_pow() {
mut expected := math.round(math.log2(math.pow(7, 8)))
mut actual := math.round(log_pow(7, 8, 2))
assert actual == expected
expected = math.round(math.log2(math.pow(10, 11)))
actual = math.round(log_pow(10, 11, 2))
assert actual == expected
expected = math.round(math.log2(math.pow(11, 17)))
actual = math.round(log_pow(11, 17, 2))
assert actual == expected
expected = math.round(math.log10(math.pow(13, 21)))
actual = math.round(log_pow(13, 21, 10))
assert actual == expected
}
fn test_validate() {
mut err_msg := ''
validate('mypass', 50) or { err_msg = err.msg }
mut expected_error := 'insecure password, try including more special characters, using uppercase letters, using numbers or using a longer password'
assert err_msg == expected_error
err_msg = ''
validate('MYPASS', 50) or { err_msg = err.msg }
expected_error = 'insecure password, try including more special characters, using lowercase letters, using numbers or using a longer password'
assert err_msg == expected_error
err_msg = ''
validate('mypassword', 4) or { err_msg = err.msg }
assert err_msg == ''
err_msg = ''
validate('aGoo0dMi#oFChaR2', 80) or { err_msg = err.msg }
assert err_msg == ''
err_msg = ''
expected_error = 'insecure password, try including more special characters, using lowercase letters, using uppercase letters or using a longer password'
validate('123', 60) or { err_msg = err.msg }
assert err_msg == expected_error
}
fn test_get_base() {
mut actual := get_base('abcd')
mut expected := lowercase.len
assert actual == expected
actual = get_base('abcdA')
expected = lowercase.len uppercase.len
assert actual == expected
actual = get_base('A')
expected = uppercase.len
assert actual == expected
actual = get_base('^_')
expected = other_special_chars.len sep_chars.len
assert actual == expected
actual = get_base('^')
expected = other_special_chars.len
assert actual == expected
actual = get_base('!')
expected = replace_chars.len
assert actual == expected
actual = get_base('123')
expected = numbers.len
assert actual == expected
actual = get_base('123ü')
expected = numbers.len 1
assert actual == expected
}