-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
38 lines (31 loc) · 1.18 KB
/
test.py
File metadata and controls
38 lines (31 loc) · 1.18 KB
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
import os
import sys
import unittest
import numpy as np
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from sparse_vector import SparseVector
class SparseTester(unittest.TestCase):
def test_wide(self):
for i in range(5):
arr = np.random.randint(-1000, 200, 1000)
self.assertEqual((SparseVector(arr)[:] == arr).all(), True)
def test_narrow(self):
for i in range(5):
arr = np.random.randint(0, 2, 1000)
self.assertEqual((SparseVector(arr)[:] == arr).all(), True)
def test_long(self):
for i in range(3):
arr = np.random.randint(0, 10, 10000)
self.assertEqual((SparseVector(arr)[:] == arr).all(), True)
def test_insertion(self):
for _ in range(3):
arr = np.zeros(1000)
spr_arr = SparseVector(1000)
for i in range(100):
beg, end = np.sort(np.random.randint(0, 1000, 2))
val = np.random.randint(0, 10000)
arr[beg:end] = np.int64(val)
spr_arr[beg:end] = np.int64(val)
self.assertEqual((spr_arr[:] == arr).all(), True)
if __name__ == '__main__':
unittest.main()