-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_diversity.py
More file actions
25 lines (19 loc) · 879 Bytes
/
test_diversity.py
File metadata and controls
25 lines (19 loc) · 879 Bytes
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
from numpy import zeros, ones_like, uint64
from numpy.random import random
from numpy.testing import assert_allclose
from diversity import q_score
def test_qscore():
all_zeros = zeros([10000], uint64)
all_ones = ones_like(all_zeros, uint64)
assert q_score(all_ones, all_zeros) == -1
assert q_score(all_zeros, all_ones) == -1
assert q_score(all_ones, all_ones) == 1
assert q_score(all_zeros, all_zeros) == 1
for i in range(1000):
random_rater_1 = (random(all_zeros.shape) > 0.5).astype(uint64)
random_rater_2 = (random(all_zeros.shape) > 0.5).astype(uint64)
assert_allclose(q_score(random_rater_1, random_rater_2), 0, atol = 0.1)
assert q_score(random_rater_1, random_rater_1) == 1
assert q_score(random_rater_1, (random_rater_1 + 1) % 2) == -1
if __name__ == '__main__':
test_qscore()