Exemple #1
0
    def test_rule_1(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())

        r1 = ORN(r1_3, r1_5, r1_7, r1_8)
        self.assertEquals((True, 'Fizz'), r1.apply(6))
        self.assertEquals((True, 'Buzz'), r1.apply(10))
        self.assertEquals((True, 'Whizz'), r1.apply(14))
        self.assertEquals((True, 'Hazz'), r1.apply(16))
        self.assertEquals((False, ''), r1.apply(13))
Exemple #2
0
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)
    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))
    r3 = Atom(Contains(3), ToFizz())
    rd = Atom(AlwaysTrue(), ToStr())

    return ORN(r3, r2, r1, rd)
Exemple #3
0
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)
Exemple #4
0
    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))
Exemple #5
0
    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))
Exemple #6
0
 def test_atom_rule_1_8(self):
     r1_8 = Atom(Times(8), ToHazz())
     self.assertEquals((True, 'Hazz'), r1_8.apply(16))
     self.assertEquals((False, ''), r1_8.apply(13))        
Exemple #7
0
 def test_toHazz(self):
     toHazz = ToHazz()
     self.assertEquals("Hazz", toHazz.act(8))