示例#1
0
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.fe = FactsEngine()
        self.re = RulesEngine()
        self.ie = InferenceEngine(self.fe, self.re)
        self.grid()

        common_font = ('DejaVu', '12')
        mono_font = ('Monospace', '10')

        self.build_labels(0, 0)

        sides_range = [x for x in range(0, 6)]
        self.cboxes = [
            Combobox(self, values=sides_range, font=common_font)
            for _ in range(0, 4)
        ]

        for index, cbox in enumerate(self.cboxes):
            cbox.bind('<<ComboboxSelected>>', self.process)
            cbox.grid(column=index, row=1)

        self.label_result = Label(self, text="...", font=common_font)
        self.label_result.grid(column=0, row=2)
        self.fact_displayer = tk.Text(self, font=mono_font)
        self.fact_displayer.insert(tk.END, "{}")
        self.fact_displayer.grid(column=1, row=2, columnspan=3)

        self.save_button = Button(self, text="SAVE", command=self.save_db)
        self.save_button.grid(column=0,
                              row=3,
                              columnspan=2,
                              sticky=tk.E + tk.W)
        self.load_button = Button(self, text="LOAD", command=self.load_db)
        self.load_button.grid(column=2,
                              row=3,
                              columnspan=2,
                              sticky=tk.E + tk.W)
示例#2
0
文件: shell.py 项目: 0b11stan/lab
 def __init__(self):
     self.fe = FactsEngine()
     self.re = RulesEngine()
     self.ie = InferenceEngine(fe, re)
     print("Welcome to polygonial !\n")
示例#3
0
 def setUp(self):
     """
     Create the rules engine.
     """
     self._re = RulesEngine(self)
示例#4
0
class TestRulesEngine(unittest.TestCase):
    """
    Tests for the rules engine.
    """
    def __init__(self, name):
        """
        :Parameters:
          name : str
            Unit test name.
        """
        super(TestRulesEngine, self).__init__(name)

    def setUp(self):
        """
        Create the rules engine.
        """
        self._re = RulesEngine(self)

    def tearDown(self):
        pass

    def testEmptyNode(self):
        """
        Test that the ``InvalidNodeSizeException`` exception is raised when
        an empty sequence object is encountered.
        """
        self.assertRaises(InvalidNodeSizeException, self._re.load, [])

    def testShortNode(self):
        """
        Test that the ``InvalidNodeSizeException`` exception is raised when
        a too short sequence object is encountered.
        """
        self.assertRaises(InvalidNodeSizeException, self._re.load, [
            None,
            None,
        ])

    def testLongNode(self):
        """
        Test that the ``InvalidNodeSizeException`` exception is raised when
        a too long sequence object is encountered.
        """
        self.assertRaises(InvalidNodeSizeException, self._re.load, [
            None,
            None,
            None,
            None,
        ])

    def testLogic_01(self):
        """
        Test that the iteration count is correct for the sequence object
        configuration.
        """
        self._re.load(self.nodeTree)
        self._re.dump()
        expect = 3
        count = self._re.getIterationCount()
        msg = "Iteration count should be {}, found {}".format(expect, count)
        self.assertTrue(count == expect, msg)

    def testLogic_02(self):
        """
        Test that the iteration count is correct for the sequence object
        configuration.
        """
        self._re.load(self.nodeTree)
        kwargs = {'arg1': True, 'arg2': False, 'arg3': True}
        self._re.dump(**kwargs)
        expect = 3
        count = self._re.getIterationCount()
        msg = "Iteration count should be {}, found {}".format(expect, count)
        self.assertTrue(count == expect, msg)

    def testLogic_03(self):
        """
        Test that the iteration count is correct for the sequence object
        configuration.
        """
        self._re.load(self.nodeTree)
        kwargs = {'arg1': False, 'arg2': False, 'arg3': True}
        self._re.dump(**kwargs)
        expect = 1
        count = self._re.getIterationCount()
        msg = "Iteration count should be {}, found {}".format(expect, count)
        self.assertTrue(count == expect, msg)

    def testLogic_04(self):
        """
        Test that the iteration count is correct for the sequence object
        configuration.
        """
        self._re.load(self.nodeTree)
        kwargs = {'arg1': True, 'arg2': True, 'arg3': True}
        self._re.dump(**kwargs)
        expect = 2
        count = self._re.getIterationCount()
        msg = "Iteration count should be {}, found {}".format(expect, count)
        self.assertTrue(count == expect, msg)

    def testTranslateCallSequence(self):
        result = self._re.translateToCallNames(TestRulesEngine.nodeTree)
        print result

    def _dummyMethod_01(self, **kwargs):
        """
        Test method 1.
        """
        return kwargs.get('arg1', True)

    def _dummyMethod_02(self, **kwargs):
        """
        Test method 2.
        """
        return kwargs.get('arg2', False)

    def _dummyMethod_03(self, **kwargs):
        """
        Test method 3.
        """
        return kwargs.get('arg3', True)

    # [callable,
    #  True -- (callable|None),
    #  False -- (callable|None)]
    nodeTree = [
        _dummyMethod_01,
        [_dummyMethod_02, None, [_dummyMethod_03, None, None]], None
    ]
示例#5
0
 def setUp(self):
     """
     Create the rules engine.
     """
     self._re = RulesEngine(self)
示例#6
0
class TestRulesEngine(unittest.TestCase):
    """
    Tests for the rules engine.
    """

    def __init__(self, name):
        """
        :Parameters:
          name : str
            Unit test name.
        """
        super(TestRulesEngine, self).__init__(name)

    def setUp(self):
        """
        Create the rules engine.
        """
        self._re = RulesEngine(self)

    def tearDown(self):
        pass

    def testEmptyNode(self):
        """
        Test that the ``InvalidNodeSizeException`` exception is raised when
        an empty sequence object is encountered.
        """
        self.assertRaises(InvalidNodeSizeException, self._re.load, [])

    def testShortNode(self):
        """
        Test that the ``InvalidNodeSizeException`` exception is raised when
        a too short sequence object is encountered.
        """
        self.assertRaises(InvalidNodeSizeException, self._re.load, [None, None])

    def testLongNode(self):
        """
        Test that the ``InvalidNodeSizeException`` exception is raised when
        a too long sequence object is encountered.
        """
        self.assertRaises(InvalidNodeSizeException, self._re.load, [None, None, None, None])

    def testLogic_01(self):
        """
        Test that the iteration count is correct for the sequence object
        configuration.
        """
        self._re.load(self.nodeTree)
        self._re.dump()
        expect = 3
        count = self._re.getIterationCount()
        msg = "Iteration count should be {}, found {}".format(expect, count)
        self.assertTrue(count == expect, msg)

    def testLogic_02(self):
        """
        Test that the iteration count is correct for the sequence object
        configuration.
        """
        self._re.load(self.nodeTree)
        kwargs = {"arg1": True, "arg2": False, "arg3": True}
        self._re.dump(**kwargs)
        expect = 3
        count = self._re.getIterationCount()
        msg = "Iteration count should be {}, found {}".format(expect, count)
        self.assertTrue(count == expect, msg)

    def testLogic_03(self):
        """
        Test that the iteration count is correct for the sequence object
        configuration.
        """
        self._re.load(self.nodeTree)
        kwargs = {"arg1": False, "arg2": False, "arg3": True}
        self._re.dump(**kwargs)
        expect = 1
        count = self._re.getIterationCount()
        msg = "Iteration count should be {}, found {}".format(expect, count)
        self.assertTrue(count == expect, msg)

    def testLogic_04(self):
        """
        Test that the iteration count is correct for the sequence object
        configuration.
        """
        self._re.load(self.nodeTree)
        kwargs = {"arg1": True, "arg2": True, "arg3": True}
        self._re.dump(**kwargs)
        expect = 2
        count = self._re.getIterationCount()
        msg = "Iteration count should be {}, found {}".format(expect, count)
        self.assertTrue(count == expect, msg)

    def testTranslateCallSequence(self):
        result = self._re.translateToCallNames(TestRulesEngine.nodeTree)
        print result

    def _dummyMethod_01(self, **kwargs):
        """
        Test method 1.
        """
        return kwargs.get("arg1", True)

    def _dummyMethod_02(self, **kwargs):
        """
        Test method 2.
        """
        return kwargs.get("arg2", False)

    def _dummyMethod_03(self, **kwargs):
        """
        Test method 3.
        """
        return kwargs.get("arg3", True)

    # [callable,
    #  True -- (callable|None),
    #  False -- (callable|None)]
    nodeTree = [_dummyMethod_01, [_dummyMethod_02, None, [_dummyMethod_03, None, None]], None]