def test_and(self): self.assertTrue((gt(0) & lt(5))(3)) self.assertFalse((lt(5) & gt(0))(5)) self.assertFalse((gt(0) & lt(5))(0)) self.assertFalse((gt(0) & lt(0))(1)) self.assertFalse((gt(0) & lt(0))(-1)) self.assertFalse((gt(0) & lt(0))(0)) self.assertTrue(( oftype(float) & gt(-1) & lt(10) & lt(9) & pred(lambda x: x%2) )(5.0)) self.assertFalse(( oftype(float) & gt(-1) & lt(10) & lt(9) & pred(lambda x: x%2) )(5)) self.assertFalse(( oftype(float) & gt(-1) & lt(10) & lt(9) & pred(lambda x: x%2) )(4.0)) self.assertFalse(( oftype(float) & gt(-1) & lt(10) & lt(9) & pred(lambda x: x%2) )(-4.0))
def test_and(self): self.assertTrue((gt(0) & lt(5))(3)) self.assertFalse((lt(5) & gt(0))(5)) self.assertFalse((gt(0) & lt(5))(0)) self.assertFalse((gt(0) & lt(0))(1)) self.assertFalse((gt(0) & lt(0))(-1)) self.assertFalse((gt(0) & lt(0))(0)) self.assertTrue((oftype(float) & gt(-1) & lt(10) & lt(9) & pred(lambda x: x % 2))(5.0)) self.assertFalse((oftype(float) & gt(-1) & lt(10) & lt(9) & pred(lambda x: x % 2))(5)) self.assertFalse((oftype(float) & gt(-1) & lt(10) & lt(9) & pred(lambda x: x % 2))(4.0)) self.assertFalse((oftype(float) & gt(-1) & lt(10) & lt(9) & pred(lambda x: x % 2))(-4.0))
def test_greater_than_predicate(self): positive = gt(0) self.assertTrue(positive(2)) self.assertTrue(positive(1.5)) self.assertFalse(positive(0)) self.assertFalse(positive(-1)) self.assertFalse(positive(-1.5))
def test_predicates_implication(self): gt_five = gt(5) lt_ten = lt(10) self.assertTrue((gt_five >> lt_ten)(7)) self.assertFalse((gt_five >> lt_ten)(20)) self.assertTrue((gt_five >> lt_ten)(4))
def test_greater_than_predicate(self): positive=gt(0) self.assertTrue(positive(2)) self.assertTrue(positive(1.5)) self.assertFalse(positive(0)) self.assertFalse(positive(-1)) self.assertFalse(positive(-1.5))
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 test_for_all(self): some_predicate = for_all(pred(even), gt(0), lt(10)) self.assertTrue(some_predicate(4)) self.assertTrue(some_predicate(6)) self.assertFalse(some_predicate(3)) self.assertFalse(some_predicate(-2)) self.assertFalse(some_predicate(14))
def test_combination_negation(self): not_positive=~gt(0) self.assertTrue(not_positive(-1)) self.assertTrue(not_positive(0)) self.assertFalse(not_positive(1)) positive=~not_positive self.assertTrue(positive(5)) self.assertFalse(positive(0)) self.assertFalse(positive(-3))
def test_combinations_conjunction(self): positive_integer = gt(0) & oftype(int) self.assertTrue(positive_integer(5)) self.assertFalse(positive_integer(1.5)) self.assertFalse(positive_integer(-1)) positive_even_integer = positive_integer & pred(lambda x: x % 2 == 0) self.assertTrue(positive_even_integer(6)) self.assertFalse(positive_even_integer(0)) self.assertFalse(positive_even_integer(3))
def test_combination_negation(self): not_positive = ~gt(0) self.assertTrue(not_positive(-1)) self.assertTrue(not_positive(0)) self.assertFalse(not_positive(1)) positive = ~not_positive self.assertTrue(positive(5)) self.assertFalse(positive(0)) self.assertFalse(positive(-3))
def test_combinations_conjunction(self): positive_integer=gt(0) & oftype(int) self.assertTrue(positive_integer(5)) self.assertFalse(positive_integer(1.5)) self.assertFalse(positive_integer(-1)) positive_even_integer=positive_integer & pred(lambda x: x % 2 == 0) self.assertTrue(positive_even_integer(6)) self.assertFalse(positive_even_integer(0)) self.assertFalse(positive_even_integer(3))
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_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_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_invert(self): negative = ~gt(0) positive = ~lt(0) negative2 = ~positive positive2 = ~~~~positive self.assertTrue(negative(-1)) self.assertFalse(negative(1)) self.assertTrue(positive(1)) self.assertFalse(positive(-1)) self.assertTrue(negative2(-1)) self.assertFalse(negative2(1)) self.assertTrue(positive2(1)) self.assertFalse(positive2(-1)) non = ~present() self.assertTrue(non(None)) not_integer = ~oftype(int) self.assertTrue(not_integer(1 + 1j)) self.assertFalse(not_integer(1))
def test_invert(self): negative = ~gt(0) positive = ~lt(0) negative2 = ~positive positive2 = ~~~~positive self.assertTrue(negative(-1)) self.assertFalse(negative(1)) self.assertTrue(positive(1)) self.assertFalse(positive(-1)) self.assertTrue(negative2(-1)) self.assertFalse(negative2(1)) self.assertTrue(positive2(1)) self.assertFalse(positive2(-1)) non = ~present() self.assertTrue(non(None)) not_integer = ~oftype(int) self.assertTrue(not_integer(1+1j)) self.assertFalse(not_integer(1))
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_combining_gt_and_lt(self): self.assertTrue((gt(2) & lt(4))(3))
def test_simple_gt(self): self.assertTrue(gt(2)(4))
def test_combining_lt_and_gt(self): self.assertTrue((lt(4) & gt(2))(3))
def test_negation(self): self.assertTrue((~gt(10))(5)) self.assertFalse((~gt(10))(15))
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_for_all(self): pos_even_integer = for_all(gt(0), pred(lambda x: x % 2 == 0), oftype(int)) self.assertTrue(pos_even_integer(6)) self.assertFalse(pos_even_integer(1.5)) self.assertFalse(pos_even_integer(-1))
def test_for_all(self): pos_even_integer=for_all(gt(0), pred(lambda x: x%2==0), oftype(int)) self.assertTrue(pos_even_integer(6)) self.assertFalse(pos_even_integer(1.5)) self.assertFalse(pos_even_integer(-1))
def test_and_intersection(self): self.assertTrue(((lt(6) & gt(-5)) & (gt(4) & lt(10)))(5)) self.assertFalse(((lt(6) & gt(-5)) & (gt(4) & lt(10)))(6)) self.assertFalse(((lt(6) & gt(-5)) & (gt(4) & lt(10)))(4))
def test_gt(self): self.assertTrue(gt(0)(1)) self.assertFalse(gt(0)(0)) self.assertFalse(gt(0)(-1)) self.assertTrue(gt(1.5)(1.6)) self.assertFalse(gt(1.5)(1.5))
def test_gt(self): greater_than_fourty_two = gt(42) self.assertTrue(greater_than_fourty_two(43)) self.assertFalse(greater_than_fourty_two(3.14))
def test_for_any(self): self.assertTrue(for_any(gt(0), lt(1))(0)) self.assertFalse(for_any()(0))
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_and_intersection(self): self.assertTrue( ((lt(6) & gt(-5)) & (gt(4) & lt(10)))(5) ) self.assertFalse( ((lt(6) & gt(-5)) & (gt(4) & lt(10)))(6) ) self.assertFalse( ((lt(6) & gt(-5)) & (gt(4) & lt(10)))(4) )
def test_disjunction(self): self.assertTrue((gt(10) | lt(5))(0)) self.assertTrue((gt(10) | lt(5))(15)) self.assertFalse((gt(10) | lt(5))(7))