Пример #1
0
 def test_lower_than_predicate(self):
     negative=lt(0)
     self.assertTrue(negative(-2))
     self.assertTrue(negative(-1.5))
     self.assertFalse(negative(0))
     self.assertFalse(negative(1))
     self.assertFalse(negative(1.5))
Пример #2
0
    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))
Пример #3
0
    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))
Пример #4
0
    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))
Пример #5
0
 def test_lower_than_predicate(self):
     negative = lt(0)
     self.assertTrue(negative(-2))
     self.assertTrue(negative(-1.5))
     self.assertFalse(negative(0))
     self.assertFalse(negative(1))
     self.assertFalse(negative(1.5))
Пример #6
0
    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))
Пример #7
0
    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))
Пример #8
0
    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))
Пример #9
0
    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))
Пример #10
0
 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))
Пример #11
0
    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))
Пример #12
0
    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))
Пример #13
0
 def test_lt(self):
     self.assertFalse(lt(0)(1))
     self.assertFalse(lt(0)(0))
     self.assertTrue(lt(0)(-1))
     self.assertFalse(lt(1.5)(1.6))
     self.assertFalse(lt(1.5)(1.5))
     self.assertTrue(lt(1.5)(-1.5))
Пример #14
0
 def test_lt(self):
     self.assertFalse(lt(0)(1))
     self.assertFalse(lt(0)(0))
     self.assertTrue(lt(0)(-1))
     self.assertFalse(lt(1.5)(1.6))
     self.assertFalse(lt(1.5)(1.5))
     self.assertTrue(lt(1.5)(-1.5))
Пример #15
0
    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))
Пример #16
0
    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))
Пример #17
0
 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))
Пример #18
0
 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))
Пример #19
0
 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))
Пример #20
0
 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))
Пример #21
0
    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("")
Пример #22
0
 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("")
Пример #23
0
 def test_combining_lt_and_gt(self):
     self.assertTrue((lt(4) & gt(2))(3))
Пример #24
0
 def test_for_any(self):
     self.assertTrue(for_any(gt(0), lt(1))(0))
     self.assertFalse(for_any()(0))
Пример #25
0
 def test_combining_gt_and_lt(self):
     self.assertTrue((gt(2) & lt(4))(3))
Пример #26
0
    def test_lt(self):
        less_than_fourty_two = lt(42)

        self.assertTrue(less_than_fourty_two(3.14))
        self.assertFalse(less_than_fourty_two(43))
Пример #27
0
 def test_combining_gt_and_lt(self):
     self.assertTrue((gt(2) & lt(4))(3))
Пример #28
0
 def test_combining_lt_and_gt(self):
     self.assertTrue((lt(4) & gt(2))(3))
Пример #29
0
 def test_simple_lt(self):
     self.assertTrue(lt(2)(0))
     self.assertFalse(lt(2)(4))
Пример #30
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))
Пример #31
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) )
Пример #32
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))
Пример #33
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))
Пример #34
0
    def test_predicate_negation(self):
        ge_five = ~lt(5)

        self.assertTrue(ge_five(10))
        self.assertTrue(ge_five(5))
        self.assertFalse(ge_five(3))
Пример #35
0
 def test_for_any(self):
     self.assertTrue(for_any(gt(0), lt(1))(0))
     self.assertFalse(for_any()(0))
Пример #36
0
    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))
Пример #37
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))
Пример #38
0
    def test_lt(self):
        less_than_fourty_two = lt(42)

        self.assertTrue(less_than_fourty_two(3.14))
        self.assertFalse(less_than_fourty_two(43))
Пример #39
0
 def test_combiding_pred_with_gt(self):
     self.assertTrue((pred(lambda x: x > 2) & lt(4))(3))
Пример #40
0
    def test_predicate_negation(self):
        ge_five = ~lt(5)

        self.assertTrue(ge_five(10))
        self.assertTrue(ge_five(5))
        self.assertFalse(ge_five(3))