Exemplo n.º 1
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))
Exemplo n.º 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))
Exemplo n.º 3
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("")
Exemplo n.º 4
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("")
Exemplo n.º 5
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))
Exemplo n.º 6
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))
Exemplo n.º 7
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))
Exemplo n.º 8
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))
Exemplo n.º 9
0
 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'))
Exemplo n.º 10
0
 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'))
Exemplo n.º 11
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))
Exemplo n.º 12
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))
Exemplo n.º 13
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))
Exemplo n.º 14
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))
Exemplo n.º 15
0
 def test_simple_eq(self):
     self.assertTrue(eq(10)(10))
     self.assertFalse(eq(10)(5))
Exemplo n.º 16
0
    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))
Exemplo n.º 17
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))
Exemplo n.º 18
0
 def test_equal_predicate(self):
     zero = eq(0)
     self.assertTrue(zero(0))
     self.assertFalse(zero(1))
     self.assertFalse(zero(-1.5))
Exemplo n.º 19
0
    def test_eq(self):
        equals_fourty_two = eq(42)

        self.assertTrue(equals_fourty_two(42))
        self.assertFalse(equals_fourty_two(3.12))
Exemplo n.º 20
0
    def test_eq(self):
        equals_fourty_two = eq(42)

        self.assertTrue(equals_fourty_two(42))
        self.assertFalse(equals_fourty_two(3.12))
Exemplo n.º 21
0
    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))
Exemplo n.º 22
0
 def test_equal_predicate(self):
     zero=eq(0)
     self.assertTrue(zero(0))
     self.assertFalse(zero(1))
     self.assertFalse(zero(-1.5))