-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52cc6f1
commit ef32276
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |