Skip to content

Commit

Permalink
add vector_test
Browse files Browse the repository at this point in the history
  • Loading branch information
weilycoder committed Oct 5, 2024
1 parent 52cc6f1 commit ef32276
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions cyaron/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .polygon_test import TestPolygon
from .compare_test import TestCompare
from .graph_test import TestGraph
from .vector_test import TestVector
33 changes: 33 additions & 0 deletions cyaron/tests/vector_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import unittest
from cyaron.vector import *


def has_duplicates(lst: list):
return len(lst) != len(set(lst))


class TestVector(unittest.TestCase):
def test_unique_vector(self):
v = Vector.random(10**5, [10**6])
self.assertFalse(has_duplicates(list(map(lambda tp: tuple(tp), v))))
self.assertTrue(all(map(lambda v: 0 <= v[0] <= 10**6, v)))
v = Vector.random(1000, [(10**5, 10**6)])
self.assertTrue(all(map(lambda v: 10**5 <= v[0] <= 10**6, v)))
with self.assertRaises(
Exception,
msg="1st param is so large that CYaRon can not generate unique vectors",
):
v = Vector.random(10**5, [10**4])

def test_repeatable_vector(self):
v = Vector.random(10**5 + 1, [10**5], VectorRandomMode.repeatable)
self.assertTrue(all(map(lambda v: 0 <= v[0] <= 10**5, v)))
self.assertTrue(has_duplicates(list(map(lambda tp: tuple(tp), v))))
v = Vector.random(1000, [(10**5, 10**6)], VectorRandomMode.repeatable)
self.assertTrue(all(map(lambda v: 10**5 <= v[0] <= 10**6, v)))

def test_float_vector(self):
v = Vector.random(10**5, [10**5], VectorRandomMode.float)
self.assertTrue(all(map(lambda v: 0 <= v[0] <= 10**5, v)))
v = Vector.random(10**5, [(24, 25)], VectorRandomMode.float)
self.assertTrue(all(map(lambda v: 24 <= v[0] <= 25, v)))

0 comments on commit ef32276

Please sign in to comment.