Esempio n. 1
0
    def test_hc(self):
        cfg = ContextFreeGrammar("test_hc_1.cfg")
        self.assertTrue(cfg.has_cycle())

        cfg = ContextFreeGrammar("test_hc_2.cfg")
        self.assertTrue(cfg.has_cycle())

        cfg = ContextFreeGrammar("test_hc_3.cfg")
        self.assertTrue(cfg.has_cycle())

        cfg = ContextFreeGrammar("test_hc_4.cfg")
        self.assertTrue(cfg.has_cycle())

        cfg = ContextFreeGrammar("test_hc_1.cfg")
        cfg.remove_unit()
        self.assertFalse(cfg.has_cycle())

        cfg = ContextFreeGrammar("test_hc_2.cfg")
        cfg.remove_unit()
        self.assertFalse(cfg.has_cycle())

        cfg = ContextFreeGrammar("test_hc_3.cfg")
        cfg.remove_unit()
        self.assertFalse(cfg.has_cycle())

        cfg = ContextFreeGrammar("test_hc_4.cfg")
        cfg.remove_unit()
        self.assertFalse(cfg.has_cycle())

        cfg = ContextFreeGrammar("test_fnc_1.cfg")
        self.assertFalse(cfg.has_cycle())
Esempio n. 2
0
    def test_ru(self):
        cfg = ContextFreeGrammar("test_ru_1.cfg")
        cfg.remove_unit()
        cfg.save_to_file("test_ru_1T.cfg")
        test_path = os.path.join(CFGS_DIR, "test_ru_1T.cfg")
        ref_path = os.path.join(CFGS_DIR, "test_ru_1A.cfg")
        self.assertTrue(filecmp.cmp(test_path, ref_path))
        ContextFreeGrammar("test_ru_1A.cfg") # TEST .CFG CONFORMATION

        cfg = ContextFreeGrammar("test_ru_2.cfg")
        cfg.remove_unit()
        cfg.save_to_file("test_ru_2T.cfg")
        test_path = os.path.join(CFGS_DIR, "test_ru_2T.cfg")
        ref_path = os.path.join(CFGS_DIR, "test_ru_2A.cfg")
        self.assertTrue(filecmp.cmp(test_path, ref_path))
        ContextFreeGrammar("test_ru_2A.cfg") # TEST .CFG CONFORMATION

        cfg = ContextFreeGrammar("test_ru_3.cfg")
        cfg.remove_unit()
        cfg.save_to_file("test_ru_3T.cfg")
        test_path = os.path.join(CFGS_DIR, "test_ru_3T.cfg")
        ref_path = os.path.join(CFGS_DIR, "test_ru_3A.cfg")
        self.assertTrue(filecmp.cmp(test_path, ref_path))
        ContextFreeGrammar("test_ru_3A.cfg") # TEST .CFG CONFORMATION

        cfg = ContextFreeGrammar("test_ru_4.cfg")
        cfg.remove_unit()
        cfg.save_to_file("test_ru_4T.cfg")
        test_path = os.path.join(CFGS_DIR, "test_ru_4T.cfg")
        ref_path = os.path.join(CFGS_DIR, "test_ru_4A.cfg")
        self.assertTrue(filecmp.cmp(test_path, ref_path))
        ContextFreeGrammar("test_ru_4A.cfg") # TEST .CFG CONFORMATION

        cfg = ContextFreeGrammar("test_ru_5.cfg")
        cfg.remove_unit()
        cfg.save_to_file("test_ru_5T.cfg")
        test_path = os.path.join(CFGS_DIR, "test_ru_5T.cfg")
        ref_path = os.path.join(CFGS_DIR, "test_ru_5A.cfg")
        self.assertTrue(filecmp.cmp(test_path, ref_path))
        ContextFreeGrammar("test_ru_5A.cfg") # TEST .CFG CONFORMATION