2021-10-09 13:22:58 +00:00
|
|
|
import mapytex
|
|
|
|
|
|
|
|
def test_generate_list():
|
2021-10-09 14:09:09 +00:00
|
|
|
random_list = mapytex.random.list(["a", "b"])
|
|
|
|
assert len(random_list) == 2
|
|
|
|
random_list = mapytex.random.list(["a", "b", "c"])
|
|
|
|
assert len(random_list) == 3
|
|
|
|
random_list = mapytex.random.list(["a", "b", "a", "b"])
|
|
|
|
assert random_list[0] == random_list[2]
|
|
|
|
assert random_list[1] == random_list[3]
|
|
|
|
|
|
|
|
def test_generate_list_calculus():
|
|
|
|
random_list = mapytex.random.list(["a", "b", "a+b"])
|
|
|
|
assert random_list[0] + random_list[1] == random_list[2]
|
|
|
|
|
|
|
|
random_list = mapytex.random.list(["a", "b", "a-b"])
|
|
|
|
assert random_list[0] - random_list[1] == random_list[2]
|
|
|
|
|
|
|
|
random_list = mapytex.random.list(["a", "b", "a*b"])
|
|
|
|
assert random_list[0] * random_list[1] == random_list[2]
|
|
|
|
|
|
|
|
random_list = mapytex.random.list(["a", "b", "a/b"])
|
|
|
|
assert random_list[0] / random_list[1] == random_list[2]
|
|
|
|
|
|
|
|
def test_generate_list_calculus_math():
|
|
|
|
import math
|
|
|
|
a, b, gcd = mapytex.random.list(["a", "b", "gcd(a, b)"])
|
|
|
|
assert math.gcd(a, b) == gcd
|
2021-10-09 18:01:32 +00:00
|
|
|
a, b, exp, cos = mapytex.random.list(["a", "b", "exp(a)", "cos(b)"])
|
2021-10-09 14:09:09 +00:00
|
|
|
assert math.exp(a) == exp
|
2021-10-09 18:01:32 +00:00
|
|
|
assert math.cos(b) == cos
|
2021-10-09 14:09:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_generate_list_conditions():
|
2021-10-09 14:18:37 +00:00
|
|
|
a, b = mapytex.random.list(["a", "b"], conditions=["a + b == 10"])
|
|
|
|
assert a + b == 10
|
|
|
|
a, b = mapytex.random.list(["a", "b"], conditions=["a * b > 0", "a + b == 10"])
|
|
|
|
assert a + b == 10
|
|
|
|
assert a * b > 0
|
|
|
|
|
|
|
|
def test_generate_list_conditions_math():
|
|
|
|
import math
|
|
|
|
a, b = mapytex.random.list(["a", "b"], conditions=["gcd(a, b) == 3"])
|
|
|
|
assert math.gcd(a, b) == 3
|
|
|
|
|
|
|
|
def test_generate_list_global_config():
|
|
|
|
global_config = {"rejected": [0, 1, 2, 3]}
|
|
|
|
a, = mapytex.random.list(["a"], global_config=global_config)
|
|
|
|
assert a not in global_config["rejected"]
|
|
|
|
|
|
|
|
global_config = {"min_max": (20, 30)}
|
|
|
|
a, = mapytex.random.list(["a"], global_config=global_config)
|
|
|
|
assert a >= 20
|
|
|
|
assert a <= 30
|
2021-10-09 14:09:09 +00:00
|
|
|
|