|
27 | 27 | from mockredis import MockRedis as Redis |
28 | 28 |
|
29 | 29 | from future.builtins import range |
| 30 | +from future.builtins import zip |
30 | 31 |
|
31 | 32 | from nearpy.storage import MemoryStorage, RedisStorage |
32 | 33 |
|
@@ -55,6 +56,24 @@ def check_store_vector(self, x): |
55 | 56 | self.storage.clean_all_buckets() |
56 | 57 | self.assertEqual(self.storage.get_bucket('testHash', bucket_key), []) |
57 | 58 |
|
| 59 | + def check_store_many_vectors(self, xs): |
| 60 | + num_vector = len(xs) |
| 61 | + bucket_keys = list(map(str, |
| 62 | + list(range(10000000, |
| 63 | + 10000000 + num_vector)))) |
| 64 | + x_data = list(range(0, num_vector)) |
| 65 | + self.storage.store_many_vectors('testHash', bucket_keys, xs, x_data) |
| 66 | + for bucket_key, x, data in zip(bucket_keys, xs, x_data): |
| 67 | + bucket = self.storage.get_bucket('testHash', bucket_key) |
| 68 | + self.assertEqual(len(bucket), 1) |
| 69 | + y, y_data = bucket[0] |
| 70 | + self.assertEqual(type(y), type(x)) |
| 71 | + self.assertEqual(y.shape, x.shape) |
| 72 | + self.assertEqual(max(abs(y - x)), 0) |
| 73 | + self.assertEqual(y_data, data) |
| 74 | + self.storage.clean_all_buckets() |
| 75 | + self.assertEqual(self.storage.get_bucket('testHash', bucket_key), []) |
| 76 | + |
58 | 77 | def check_get_all_bucket_keys(self): |
59 | 78 | x, x_data = numpy.ones(100), "data" |
60 | 79 | hash_config = [ |
@@ -135,5 +154,10 @@ def test_store_zero(self): |
135 | 154 | _, data = bucket[0] |
136 | 155 | self.assertEqual(data, 0) |
137 | 156 |
|
| 157 | + def test_store_many_vectors(self): |
| 158 | + x = numpy.random.randn(100, 10) |
| 159 | + self.check_store_many_vectors(x) |
| 160 | + |
| 161 | + |
138 | 162 | if __name__ == '__main__': |
139 | 163 | unittest.main() |
0 commit comments