Пример #1
0
 def test_filter(self):
     assert filter_(lambda v: Right(v % 2 == 0), range(3)) == Right((0, 2))
Пример #2
0
 def test_for_each(self):
     assert for_each(Right, range(3)) == Right((0, 1, 2))
Пример #3
0
 def test_sequence(self):
     assert sequence([Right(v) for v in range(3)]) == Right((0, 1, 2))
Пример #4
0
 def test_stack_safety(self):
     with recursion_limit(100):
         sequence([Right(v) for v in range(500)])
Пример #5
0
 def test_bool(self, value):
     assert bool(Right(value))
     assert not bool(Left(value))
Пример #6
0
 def test_either_decorator(self):
     result_int = either(int)
     assert result_int('1') == Right(1)
Пример #7
0
 def test_composition_law(self, f: Unary, g: Unary, value):
     h = compose(f, g)
     assert Left(value).map(h) == Left(value).map(g).map(f)
     assert Right(value).map(h) == Right(value).map(g).map(f)
Пример #8
0
 def test_or_else(self, value, default):
     assert Right(value).or_else(default) == value
     assert Left(value).or_else(default) == default
Пример #9
0
 def test_identity_law(self, value):
     assert Left(value).map(identity) == Left(value)
     assert Right(value).map(identity) == Right(value)
Пример #10
0
 def test_inequality(self, first, second):
     assume(first != second)
     assert Left(first) != Left(second)
     assert Right(first) != Right(second)
     assert Left(first) != Right(first)
Пример #11
0
 def test_equality(self, value):
     assert Left(value) == Left(value)
     assert Right(value) == Right(value)
Пример #12
0
 def test_left_identity_law(self, value, f: Unary[Any, Either]):
     assert Right(value).and_then(f) == f(value)
Пример #13
0
 def test_gather(self):
     assert gather([Right(v) for v in range(3)]) == Right((0, 1, 2))