Beispiel #1
0
    def test_plus(self):
        g = NumboGraph(Numble([4, 5, 6], 15))
        brick4 = g.look_for(Brick(4))
        brick5 = g.look_for(Brick(5))

        (plus, block) = g.build_op_and_result(Plus, operands=[brick4, brick5])
        self.assertTrue(g.is_of_class(plus, Plus))
        self.assertEqual(block, Block(9))
        self.assertCountEqual(g.neighbors(plus, 'operands'),
                              as_nodeids([brick4, brick5]))
Beispiel #2
0
    def test_current_soln(self):
        g = NumboGraph(Numble([4, 5, 6], 15))
        b4, b5, b6 = g.get_nodes(Brick(4), Brick(5), Brick(6))

        self.assertEqual(g.current_soln(), '4, 5, 6')

        (plus1, sum1) = g.build_op_and_result(Plus, operands=[b4, b5, b6])
        self.assertEqual(g.current_soln(), '4, 5, 6')

        (plus2, sum2) = g.consume_operands(Plus, operands=[b4, b5, b6])
        self.assertEqual(g.current_soln(), '4 + 5 + 6 = 15')
Beispiel #3
0
    def test_not_the_args_of(self):
        g = NumboGraph(Numble([4, 5, 6], 15))
        b4 = g.look_for(Brick(4))
        b5 = g.look_for(Brick(5))
        plus, block9 = g.build_op_and_result(Plus, operands=[b4, b5])
        assert b4 and b5 and plus and block9

        msg = 'NotTheArgsOf failed to recognize Plus(4, 5)'
        ntao_o = NotTheArgsOf(Plus, 'operands')
        self.assertFalse(ntao_o(g, [b4, b5]), msg)
        ntao_s = NotTheArgsOf(Plus, 'source')
        self.assertFalse(ntao_s(g, [b4, b5]), msg)
Beispiel #4
0
    def test_operator_with_avail_operands(self):
        criterion = OperatorWithAvailOperands()

        g = NumboGraph(Numble([4, 5, 6], 15))

        # Don't accept the Plus that is tagged Allowed and has no operands
        ur_plus = g.look_for(And(Plus, CTagged(Allowed)), focal_point=g.ws)
        self.assertFalse(criterion(g, ur_plus))

        (b4, b5) = g.look_for([Brick(4), Brick(5)], focal_point=g.ws)
        (plus, block) = g.build_op_and_result(Plus, operands=(b4, b5))
        self.assertTrue(criterion(g, plus))

        (consumer_plus, block2) = g.consume_operands(Plus, operands=(b4, b5))
        self.assertFalse(criterion(g, plus))
        self.assertFalse(criterion(g, consumer_plus))