def spec(): r1_3 = Atom(Times(3), ToFizz()) r1_5 = Atom(Times(5), ToBuzz()) r1_7 = Atom(Times(7), ToWhizz()) r1 = OR3(r1_3, r1_5, r1_7) r2 = OR4(AND3(r1_3, r1_5, r1_7), AND(r1_3, r1_5), AND(r1_3, r1_7), AND(r1_5, r1_7)) r3 = Atom(Contains(3), ToFizz()) rd = Atom(AlwaysTrue(), ToStr()) return OR4(r3, r2, r1, rd)
def test_and_rule(self): r1_3 = Atom(Times(3), ToFizz()) r1_5 = Atom(Times(5), ToBuzz()) and_35 = AND(r1_3, r1_5) self.assertEquals((False, ''), and_35.apply(3)) self.assertEquals((False, ''), and_35.apply(5)) self.assertEquals((True, 'FizzBuzz'), and_35.apply(15)) self.assertEquals((False, ''), and_35.apply(16))
def test_or_rule(self): r1_3 = Atom(Times(3), ToFizz()) r1_5 = Atom(Times(5), ToBuzz()) or_35 = OR(r1_3, r1_5) self.assertEquals((True, 'Fizz'), or_35.apply(6)) self.assertEquals((True, 'Buzz'), or_35.apply(10)) self.assertEquals((True, 'Fizz'), or_35.apply(15)) self.assertEquals((False, ''), or_35.apply(7))
def test_rule_1(self): r1_3 = Atom(Times(3), ToFizz()) r1_5 = Atom(Times(5), ToBuzz()) r1_7 = Atom(Times(7), ToWhizz()) r1 = OR3(r1_3, r1_5, r1_7) self.assertEquals((True, 'Fizz'), r1.apply(6)) self.assertEquals((True, 'Buzz'), r1.apply(10)) self.assertEquals((True, 'Whizz'), r1.apply(14)) self.assertEquals((False, ''), r1.apply(13))
def spec(): r1_3 = Atom(Times(3), ToFizz()) r1_5 = Atom(Times(5), ToBuzz()) r1_7 = Atom(Times(7), ToWhizz()) r1_8 = Atom(Times(8), ToHazz()) r1 = ORN(r1_3, r1_5, r1_7, r1_8) atom_rules = [r1_3, r1_5, r1_7, r1_8] combinated_rules = flatten([ combinate(atom_rules, 4), combinate(atom_rules, 3), combinate(atom_rules, 2) ]) r2 = _ORN([_ANDN(rules) for rules in combinated_rules]) r3 = Atom(Contains(3), ToFizz()) rd = Atom(AlwaysTrue(), ToStr()) return ORN(r3, r2, r1, rd)
def test_rule_2(self): r1_3 = Atom(Times(3), ToFizz()) r1_5 = Atom(Times(5), ToBuzz()) r1_7 = Atom(Times(7), ToWhizz()) r2 = OR4(AND3(r1_3, r1_5, r1_7), AND(r1_3, r1_5), AND(r1_3, r1_7), AND(r1_5, r1_7)) self.assertEquals((False, ''), r2.apply(3)) self.assertEquals((False, ''), r2.apply(5)) self.assertEquals((False, ''), r2.apply(7)) self.assertEquals((True, 'FizzBuzzWhizz'), r2.apply(3 * 5 * 7)) self.assertEquals((False, ''), r2.apply(104)) self.assertEquals((True, 'FizzBuzz'), r2.apply(15)) self.assertEquals((False, ''), r2.apply(14)) self.assertEquals((True, 'FizzWhizz'), r2.apply(21)) self.assertEquals((False, ''), r2.apply(22)) self.assertEquals((True, 'BuzzWhizz'), r2.apply(35)) self.assertEquals((False, ''), r2.apply(34))
def test_rule_2(self): r1_3 = Atom(Times(3), ToFizz()) r1_5 = Atom(Times(5), ToBuzz()) r1_7 = Atom(Times(7), ToWhizz()) r1_8 = Atom(Times(8), ToHazz()) atom_rules = [r1_3, r1_5, r1_7, r1_8] combinated_rules = flatten([combinate(atom_rules, 4), combinate(atom_rules, 3), combinate(atom_rules, 2)]) r2 = _ORN([_ANDN(rules) for rules in combinated_rules]) self.assertEquals((False, ''), r2.apply(3)) self.assertEquals((False, ''), r2.apply(5)) self.assertEquals((False, ''), r2.apply(7)) self.assertEquals((False, ''), r2.apply(8)) self.assertEquals((True, 'FizzBuzzWhizzHazz'), r2.apply(3*5*7*8)) self.assertEquals((False, ''), r2.apply(841)) self.assertEquals((True, 'FizzBuzzWhizz'), r2.apply(3*5*7)) self.assertEquals((False, ''), r2.apply(104)) self.assertEquals((True, 'FizzBuzzHazz'), r2.apply(3*5*8)) self.assertEquals((False, ''), r2.apply(121)) self.assertEquals((True, 'FizzWhizzHazz'), r2.apply(3*7*8)) self.assertEquals((False, ''), r2.apply(167)) self.assertEquals((True, 'BuzzWhizzHazz'), r2.apply(5*7*8)) self.assertEquals((False, ''), r2.apply(281)) self.assertEquals((True, 'FizzBuzz'), r2.apply(15)) self.assertEquals((False, ''), r2.apply(14)) self.assertEquals((True, 'FizzWhizz'), r2.apply(21)) self.assertEquals((False, ''), r2.apply(22)) self.assertEquals((True, 'FizzHazz'), r2.apply(24)) self.assertEquals((False, ''), r2.apply(23)) self.assertEquals((True, 'BuzzWhizz'), r2.apply(35)) self.assertEquals((False, ''), r2.apply(34)) self.assertEquals((True, 'BuzzHazz'), r2.apply(40)) self.assertEquals((False, ''), r2.apply(41)) self.assertEquals((True, 'WhizzHazz'), r2.apply(56)) self.assertEquals((False, ''), r2.apply(55))
def test_rule_2(self): r1_3 = Atom(Times(3), ToFizz()) r1_5 = Atom(Times(5), ToBuzz()) r1_7 = Atom(Times(7), ToWhizz()) r1_8 = Atom(Times(8), ToHazz()) r2 = ORN(AND4(r1_3, r1_5, r1_7, r1_8), AND3(r1_3, r1_5, r1_7), AND3(r1_3, r1_5, r1_8), AND3(r1_3, r1_7, r1_8), AND3(r1_5, r1_7, r1_8), AND(r1_3, r1_5), AND(r1_3, r1_7), AND(r1_3, r1_8), AND(r1_5, r1_7), AND(r1_5, r1_8), AND(r1_7, r1_8)) self.assertEquals((False, ''), r2.apply(3)) self.assertEquals((False, ''), r2.apply(5)) self.assertEquals((False, ''), r2.apply(7)) self.assertEquals((False, ''), r2.apply(8)) self.assertEquals((True, 'FizzBuzzWhizzHazz'), r2.apply(3 * 5 * 7 * 8)) self.assertEquals((False, ''), r2.apply(841)) self.assertEquals((True, 'FizzBuzzWhizz'), r2.apply(3 * 5 * 7)) self.assertEquals((False, ''), r2.apply(104)) self.assertEquals((True, 'FizzBuzzHazz'), r2.apply(3 * 5 * 8)) self.assertEquals((False, ''), r2.apply(121)) self.assertEquals((True, 'FizzWhizzHazz'), r2.apply(3 * 7 * 8)) self.assertEquals((False, ''), r2.apply(167)) self.assertEquals((True, 'BuzzWhizzHazz'), r2.apply(5 * 7 * 8)) self.assertEquals((False, ''), r2.apply(281)) self.assertEquals((True, 'FizzBuzz'), r2.apply(15)) self.assertEquals((False, ''), r2.apply(14)) self.assertEquals((True, 'FizzWhizz'), r2.apply(21)) self.assertEquals((False, ''), r2.apply(22)) self.assertEquals((True, 'FizzHazz'), r2.apply(24)) self.assertEquals((False, ''), r2.apply(23)) self.assertEquals((True, 'BuzzWhizz'), r2.apply(35)) self.assertEquals((False, ''), r2.apply(34)) self.assertEquals((True, 'BuzzHazz'), r2.apply(40)) self.assertEquals((False, ''), r2.apply(41)) self.assertEquals((True, 'WhizzHazz'), r2.apply(56)) self.assertEquals((False, ''), r2.apply(55))
def test_toFizz(self): toFizz = ToFizz() self.assertEquals('Fizz', toFizz.act(3))
def test_atom_rule_1_3(self): r1_3 = Atom(Times(3), ToFizz()) self.assertEquals((True, 'Fizz'), r1_3.apply(3)) self.assertEquals((False, ''), r1_3.apply(4))
def test_rule_3(self): r3 = Atom(Contains(3), ToFizz()) self.assertEquals((True, 'Fizz'), r3.apply(3)) self.assertEquals((True, 'Fizz'), r3.apply(13)) self.assertEquals((True, 'Fizz'), r3.apply(31)) self.assertEquals((False, ''), r3.apply(24))