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"))
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"))
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_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))
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_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_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'))
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'))
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_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_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'))
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_combiding_pred_with_gt(self): self.assertTrue((pred(lambda x: x > 2) & lt(4))(3))
def test_pred(self): self.assertTrue(pred(lambda x: x > 2)(4))
def test_pred(self): even_predicate = pred(TestPredicates.even) self.assertTrue(even_predicate(42)) self.assertFalse(even_predicate(11))
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))