-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_process_data.py
75 lines (59 loc) · 2.57 KB
/
test_process_data.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
import process_data
import numpy as np
def test_count_freqs_basic():
allchars = [chr(i) for i in range(256)]
payloads = ""
payloads = payloads.join(allchars)
expected = np.zeros(256, dtype=np.double)
expected += 1 / 256
assert (expected == process_data.count_mean_freqs(payloads)).all()
def test_count_freqs_empty():
payloads = ["", ]
expected = np.zeros(256, dtype=np.double)
assert (expected == process_data.count_mean_freqs(payloads)).all()
def test_count_freqs_distinct_payloads():
payloads = ["a", "b", "c"]
expected = np.zeros(256, dtype=np.double)
expected[97] = 1 / 3
expected[98] = 1 / 3
expected[99] = 1 / 3
assert (expected == process_data.count_mean_freqs(payloads)).all()
def test_count_freqs_distinct_payloads_of_variable_length():
payloads = ["a", "ab", "aaac", "x", "za", " a"]
expected = np.zeros(256, dtype=np.double)
expected[97] = (1 + 1 / 2 + 3 / 4 + 1 / 2 + 1 / 5) / 6
expected[98] = (1 / 2) / 6
expected[99] = (1 / 4) / 6
expected[120] = 1 / 6
expected[122] = (1 / 2) / 6
expected[32] = (4 / 5) / 6
assert (expected == process_data.count_mean_freqs(payloads)).all()
def test_count_devs_basic():
allchars = [chr(i) for i in range(256)]
payloads = ""
payloads = payloads.join(allchars)
expected = np.zeros(256, dtype=np.double)
actual = process_data.count_std_devs(payloads)
assert (expected == actual).all()
def test_count_devs_empty():
payloads = ["", ]
expected = np.zeros(256, dtype=np.double)
assert (expected == process_data.count_mean_freqs(payloads)).all()
def test_count_devs_distinct_payloads():
payloads = ["a", "b", "c"]
expected = np.zeros(256, dtype=np.double)
expected[97] = ((1 - 1 / 3) + (0 - 1 / 3) + (0 - 1 / 3)) / 3
expected[98] = ((1 - 1 / 3) + (0 - 1 / 3) + (0 - 1 / 3)) / 3
expected[99] = ((1 - 1 / 3) + (0 - 1 / 3) + (0 - 1 / 3)) / 3
assert (expected == process_data.count_std_devs(payloads)).all()
def test_count_devs_distinct_payloads_of_variable_length():
payloads = ["a", "ab", "aaaca", "bba"]
expected = np.zeros(256, dtype=np.double)
mean_a = (1 + 1 / 2 + 4 / 5 + 1 / 3) / 4
mean_b = (1 / 2 + 2 / 3) / 4
mean_c = (1 / 5) / 4
expected[97] = ((1 - mean_a) + (1 / 2 - mean_a) + (4 / 5 - mean_a) + (1 / 3 - mean_a)) / 4
expected[98] = ((0 - mean_b) + (1 / 2 - mean_b) + (0 - mean_b) + (2 / 3 - mean_b)) / 4
expected[99] = ((0 - mean_c) + (0 - mean_c) + (1 / 5 - mean_c) + (0 - mean_c)) / 4
actual = process_data.count_std_devs(payloads)
assert (expected == actual).all()