|
| 1 | +import unittest |
| 2 | +from cyaron.vector import * |
| 3 | + |
| 4 | + |
| 5 | +def has_duplicates(lst: list): |
| 6 | + return len(lst) != len(set(lst)) |
| 7 | + |
| 8 | + |
| 9 | +class TestVector(unittest.TestCase): |
| 10 | + def test_unique_vector(self): |
| 11 | + v = Vector.random(10**5, [10**6]) |
| 12 | + self.assertFalse(has_duplicates(list(map(lambda tp: tuple(tp), v)))) |
| 13 | + self.assertTrue(all(map(lambda v: 0 <= v[0] <= 10**6, v))) |
| 14 | + v = Vector.random(1000, [(10**5, 10**6)]) |
| 15 | + self.assertTrue(all(map(lambda v: 10**5 <= v[0] <= 10**6, v))) |
| 16 | + with self.assertRaises( |
| 17 | + Exception, |
| 18 | + msg="1st param is so large that CYaRon can not generate unique vectors", |
| 19 | + ): |
| 20 | + v = Vector.random(10**5, [10**4]) |
| 21 | + |
| 22 | + def test_repeatable_vector(self): |
| 23 | + v = Vector.random(10**5 + 1, [10**5], VectorRandomMode.repeatable) |
| 24 | + self.assertTrue(all(map(lambda v: 0 <= v[0] <= 10**5, v))) |
| 25 | + self.assertTrue(has_duplicates(list(map(lambda tp: tuple(tp), v)))) |
| 26 | + v = Vector.random(1000, [(10**5, 10**6)], VectorRandomMode.repeatable) |
| 27 | + self.assertTrue(all(map(lambda v: 10**5 <= v[0] <= 10**6, v))) |
| 28 | + |
| 29 | + def test_float_vector(self): |
| 30 | + v = Vector.random(10**5, [10**5], VectorRandomMode.float) |
| 31 | + self.assertTrue(all(map(lambda v: 0 <= v[0] <= 10**5, v))) |
| 32 | + v = Vector.random(10**5, [(24, 25)], VectorRandomMode.float) |
| 33 | + self.assertTrue(all(map(lambda v: 24 <= v[0] <= 25, v))) |
0 commit comments