Ejemplo n.º 1
0
    def test_pred_predicate(self):
        even_length = pred(even_len)
        self.assertTrue(even_length("parjolka"))
        self.assertFalse(even_length('kebap4e'))

        even_length2 = pred(even_len2)
        self.assertTrue(even_length2("baba"))
        self.assertFalse(even_length2("dyado"))
Ejemplo n.º 2
0
 def test_pred_predicate(self):
     even_length=pred(even_len)
     self.assertTrue(even_length("parjolka"))
     self.assertFalse(even_length('kebap4e'))
     
     even_length2=pred(even_len2)
     self.assertTrue(even_length2("baba"))
     self.assertFalse(even_length2("dyado"))
Ejemplo n.º 3
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))
Ejemplo n.º 4
0
    def test_thrifty_conunction_and_disjunction(self):
        """Ако искате да тествате за това сменете raising_predicate
        с името на вашия 'хвърлящ' клас и го добавете в import-а"""
        number = pred(lambda x: True) | raising_predicate(5)
        number(5)

        number = pred(lambda x: False) & raising_predicate(17)
        self.assertRaises(number(17))

        number = for_any(pred(lambda x: True), raising_predicate(5))
        number(5)

        number = for_all(pred(lambda x: False), raising_predicate(5))
        self.assertRaises(number(17))
Ejemplo n.º 5
0
    def test_thrifty_conunction_and_disjunction(self):
        """Ако искате да тествате за това сменете raising_predicate
        с името на вашия 'хвърлящ' клас и го добавете в import-а"""
        number = pred(lambda x: True) | raising_predicate(5)
        number(5)

        number = pred(lambda x: False) & raising_predicate(17)
        self.assertRaises(number(17))

        number = for_any(pred(lambda x: True), raising_predicate(5))
        number(5)

        number = for_all(pred(lambda x: False), raising_predicate(5))
        self.assertRaises(number(17))
Ejemplo n.º 6
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))
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 9
0
 def test_combination_implication(self):
     
     string_element=oftype(str)
     even_length=pred(lambda x: len(x) %2 == 0)
     
     self.assertTrue((string_element >> even_length)(2))
     self.assertFalse((string_element >> even_length)("dyado"))
     self.assertTrue((string_element >> even_length)('baba'))
Ejemplo n.º 10
0
    def test_combination_implication(self):

        string_element = oftype(str)
        even_length = pred(lambda x: len(x) % 2 == 0)

        self.assertTrue((string_element >> even_length)(2))
        self.assertFalse((string_element >> even_length)("dyado"))
        self.assertTrue((string_element >> even_length)('baba'))
Ejemplo n.º 11
0
 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))
Ejemplo n.º 12
0
    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))
Ejemplo n.º 13
0
 def test_pred(self):
     def odd(x):
         return (x % 2)
     self.assertTrue(pred(odd)(1))
     self.assertTrue(pred(odd)(11))
     self.assertFalse(pred(odd)(8))
     self.assertTrue(pred(lambda x: x > 10)(11))
     self.assertFalse(pred(lambda x: x > 10)(9))
     self.assertTrue(pred(lambda x: x.lower() == x)('all lower'))
     self.assertFalse(pred(lambda x: x.lower() == x)('noT all lower'))
Ejemplo n.º 14
0
    def test_pred(self):
        def odd(x):
            return (x % 2)

        self.assertTrue(pred(odd)(1))
        self.assertTrue(pred(odd)(11))
        self.assertFalse(pred(odd)(8))
        self.assertTrue(pred(lambda x: x > 10)(11))
        self.assertFalse(pred(lambda x: x > 10)(9))
        self.assertTrue(pred(lambda x: x.lower() == x)('all lower'))
        self.assertFalse(pred(lambda x: x.lower() == x)('noT all lower'))
Ejemplo n.º 15
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("")
Ejemplo n.º 16
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("")
Ejemplo n.º 17
0
 def test_combiding_pred_with_gt(self):
     self.assertTrue((pred(lambda x: x > 2) & lt(4))(3))
Ejemplo n.º 18
0
 def test_pred(self):
     self.assertTrue(pred(lambda x: x > 2)(4))
Ejemplo n.º 19
0
 def test_pred(self):
     self.assertTrue(pred(lambda x: x > 2)(4))
Ejemplo n.º 20
0
    def test_pred(self):
        even_predicate = pred(TestPredicates.even)

        self.assertTrue(even_predicate(42))
        self.assertFalse(even_predicate(11))
Ejemplo n.º 21
0
 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))
Ejemplo n.º 22
0
 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))
Ejemplo n.º 23
0
    def test_pred(self):
        even_predicate = pred(TestPredicates.even)

        self.assertTrue(even_predicate(42))
        self.assertFalse(even_predicate(11))