def test_for_any(self): some_predicate = for_any(gt(10), lt(6), eq(7.5)) self.assertTrue(some_predicate(7.5)) self.assertTrue(some_predicate(15)) self.assertTrue(some_predicate(-4)) self.assertFalse(some_predicate(6))
def tests_from_task(self): digit = oftype(int) & gt(-1) & lt(10) self.assertTrue(digit(5)) self.assertFalse(digit(-2)) self.assertFalse(digit("a")) binary = eq(0) | eq(1) self.assertTrue(binary(0)) self.assertFalse(binary(2)) number = for_any(oftype(int), oftype(float), oftype(complex)) self.assertTrue(number(10)) self.assertTrue(number(1 + 2j)) self.assertFalse(number("kiuftence")) is_the_empty_string = pred(lambda x: x is "") self.assertFalse(is_the_empty_string("me4ence")) self.assertFalse('') self.assertFalse("")
def tests_from_task(self): digit = oftype(int) & gt(-1) & lt(10) self.assertTrue(digit(5)) self.assertFalse(digit(-2)) self.assertFalse(digit("a")) binary = eq(0) | eq(1) self.assertTrue(binary(0)) self.assertFalse(binary(2)) number = for_any(oftype(int), oftype(float), oftype(complex)) self.assertTrue(number(10)) self.assertTrue(number(1+2j)) self.assertFalse(number("kiuftence")) is_the_empty_string = pred(lambda x: x is "") self.assertFalse(is_the_empty_string("me4ence")) self.assertFalse('') self.assertFalse("")
def test_combination_disjunction(self): negative_or_float=lt(0) | oftype(float) self.assertTrue(negative_or_float(-1)) self.assertTrue(negative_or_float(1.5)) self.assertFalse(negative_or_float(3)) neg_or_float_or_zero=negative_or_float | eq(0) self.assertTrue(neg_or_float_or_zero(0)) self.assertFalse(neg_or_float_or_zero(4)) self.assertTrue(neg_or_float_or_zero(1.5))
def test_combination_disjunction(self): negative_or_float = lt(0) | oftype(float) self.assertTrue(negative_or_float(-1)) self.assertTrue(negative_or_float(1.5)) self.assertFalse(negative_or_float(3)) neg_or_float_or_zero = negative_or_float | eq(0) self.assertTrue(neg_or_float_or_zero(0)) self.assertFalse(neg_or_float_or_zero(4)) self.assertTrue(neg_or_float_or_zero(1.5))
def test_predicate_disjunction(self): lt_pi_or_gt_fourty_two = lt(3.14) | gt(42) self.assertTrue(lt_pi_or_gt_fourty_two(1)) self.assertTrue(lt_pi_or_gt_fourty_two(43)) self.assertFalse(lt_pi_or_gt_fourty_two(15)) lt_pi_or_gt_fourty_two_and_13 = lt_pi_or_gt_fourty_two |\ eq(13) self.assertTrue(lt_pi_or_gt_fourty_two_and_13(13)) self.assertFalse(lt_pi_or_gt_fourty_two_and_13(15))
def test_eq(self): self.assertTrue(eq(0)(0)) self.assertFalse(eq(0)(1)) self.assertTrue(eq([])([])) self.assertTrue(eq(None)(None)) self.assertTrue(eq('man united champions')('man united champions')) self.assertFalse(eq('chelsea')('champions'))
def test_predicate_conjuction(self): between_pi_and_fourty_two = gt(3.14) & lt(42) self.assertTrue(between_pi_and_fourty_two(10)) self.assertFalse(between_pi_and_fourty_two(3)) self.assertFalse(between_pi_and_fourty_two(43)) between_pi_and_fourty_two_except_thirteen =\ between_pi_and_fourty_two & ~eq(13) self.assertTrue(between_pi_and_fourty_two_except_thirteen(5)) self.assertTrue(between_pi_and_fourty_two_except_thirteen(15)) self.assertFalse(between_pi_and_fourty_two_except_thirteen(13))
def test_or(self): self.assertTrue(( gt(0) | eq(-42) )(-42)) self.assertFalse(( gt(0) | eq(-42) )(-43)) self.assertTrue((gt(0) | lt(-5) | eq(-5) | oftype(float))(-3.0)) self.assertFalse((gt(0) | lt(-5) | eq(-5) | oftype(float))(-3)) self.assertTrue((gt(0) | lt(-5) | eq(-5) | oftype(float))(-5)) self.assertFalse((gt(0) | lt(-5) | eq(-5) | oftype(float))(-2)) for i in range(-5,6): if i == 0: self.assertFalse((gt(0) | lt(0))(i)) else: self.assertTrue((gt(0) | lt(0))(i))
def test_or(self): self.assertTrue((gt(0) | eq(-42))(-42)) self.assertFalse((gt(0) | eq(-42))(-43)) self.assertTrue((gt(0) | lt(-5) | eq(-5) | oftype(float))(-3.0)) self.assertFalse((gt(0) | lt(-5) | eq(-5) | oftype(float))(-3)) self.assertTrue((gt(0) | lt(-5) | eq(-5) | oftype(float))(-5)) self.assertFalse((gt(0) | lt(-5) | eq(-5) | oftype(float))(-2)) for i in range(-5, 6): if i == 0: self.assertFalse((gt(0) | lt(0))(i)) else: self.assertTrue((gt(0) | lt(0))(i))
def test_simple_eq(self): self.assertTrue(eq(10)(10)) self.assertFalse(eq(10)(5))
def test_for_any(self): self.assertTrue(for_any(eq(10), eq(5))(10)) self.assertTrue(for_any(eq(10), eq(5), eq(0))(0)) self.assertFalse(for_any(eq(10), eq(5), eq(0))(1))
def test_for_all(self): self.assertTrue(for_all(gt(0), lt(10))(5)) self.assertTrue(for_all(gt(0), lt(10), eq(5))(5)) self.assertFalse(for_all(gt(0), lt(10), eq(5))(7)) self.assertFalse(for_all(eq(0), eq(1))(0))
def test_equal_predicate(self): zero = eq(0) self.assertTrue(zero(0)) self.assertFalse(zero(1)) self.assertFalse(zero(-1.5))
def test_eq(self): equals_fourty_two = eq(42) self.assertTrue(equals_fourty_two(42)) self.assertFalse(equals_fourty_two(3.12))
def test_implication(self): self.assertTrue((gt(10) >> eq(20))(20)) self.assertTrue((gt(10) >> eq(20))(0)) self.assertTrue((gt(10) >> eq(0))(0)) self.assertFalse((gt(10) >> eq(20))(15))
def test_equal_predicate(self): zero=eq(0) self.assertTrue(zero(0)) self.assertFalse(zero(1)) self.assertFalse(zero(-1.5))