コード例 #1
0
ファイル: testConsume.py プロジェクト: bkovitz/FARGish
    def test_consume_minus(self):
        g = NumboGraph(Numble([4, 9, 12], 17))
        brick4 = g.look_for(Brick(4))
        brick9 = g.look_for(Brick(9))
        assert g.has_tag(brick4, Avail)
        assert g.has_tag(brick9, Avail)

        g.consume_operands(Minus, minuend=brick9, subtrahend=brick4)

        minus = g.look_for(Minus, subset=g.neighbors(brick4))
        self.assertTrue(minus)
        block5 = g.look_for(Block(5))
        self.assertTrue(block5)
        self.assertTrue(g.has_tag(block5, Avail))
        self.assertFalse(g.has_tag(brick4, Avail))
        self.assertFalse(g.has_tag(brick9, Avail))
コード例 #2
0
ファイル: testConsume.py プロジェクト: bkovitz/FARGish
    def test_consume_times(self):
        g = NumboGraph(Numble([4, 5, 6], 15))
        brick4 = g.look_for(Brick(4))
        brick5 = g.look_for(Brick(5))
        assert g.has_tag(brick4, Avail)
        assert g.has_tag(brick5, Avail)

        g.consume_operands(Times, operands=[brick4, brick5])

        times = g.look_for(Times, subset=g.neighbors(brick4))
        self.assertTrue(times)
        block20 = g.look_for(Block(20))
        self.assertTrue(block20)
        self.assertTrue(g.has_tag(block20, Avail))
        self.assertFalse(g.has_tag(brick4, Avail))
        self.assertFalse(g.has_tag(brick5, Avail))
コード例 #3
0
ファイル: testConsume.py プロジェクト: bkovitz/FARGish
    def test_consume_plus(self):
        g = NumboGraph(Numble([4, 5, 6], 15))
        brick4 = g.look_for(Brick(4))
        brick5 = g.look_for(Brick(5))
        assert g.has_tag(brick4, Avail)
        assert g.has_tag(brick5, Avail)

        #g.consume_operands([brick4, brick5], Plus)
        g.consume_operands(Plus, operands=[brick4, brick5])

        plus = g.look_for(Plus, subset=g.neighbors(brick4))
        self.assertTrue(plus)
        block9 = g.look_for(Block(9))
        self.assertTrue(block9)
        self.assertTrue(g.has_tag(block9, Avail))
        self.assertFalse(g.has_tag(brick4, Avail))
        self.assertFalse(g.has_tag(brick5, Avail))
        self.assertTrue(g.is_member([plus, block9], g.ws))
コード例 #4
0
ファイル: testNumboGraph.py プロジェクト: bkovitz/FARGish
    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')
コード例 #5
0
ファイル: testNumboGraph.py プロジェクト: bkovitz/FARGish
    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))