@Test public void testUrgent() { String path = UNIT_BASEDIR + "urgent/"; Configuration c = flatten(SpaceExImporter.importModels(path + "urgent.cfg", path + "urgent.xml")); BaseComponent ha = (BaseComponent) c.root; if (!AutomatonUtil.hasUrgentMode(ha)) { Assert.fail("urgent model not imported correctly"); } }
@Test public void testInputOutput() { // test model with input and output variables String cfgPath = UNIT_BASEDIR + "comp_in_out/sys.cfg"; String xmlPath = UNIT_BASEDIR + "comp_in_out/sys.xml"; SpaceExDocument doc = SpaceExImporter.importModels(cfgPath, xmlPath); Map<String, Component> componentTemplates = TemplateImporter.createComponentTemplates(doc); Configuration config = ConfigurationMaker.fromSpaceEx(doc, componentTemplates); NetworkComponent nc = (NetworkComponent) config.root; BaseComponent bcX = (BaseComponent) nc.children.get("out_x_1").child; BaseComponent bcY = (BaseComponent) nc.children.get("out_y_1").child; Assert.assertEquals("two variables in out_x component", 2, bcX.variables.size()); Assert.assertEquals( "one defined flow in out_x component", 1, bcX.modes.values().iterator().next().flowDynamics.size()); // also test AutomatonUtil.isOutputVariable() Assert.assertTrue( "x is an output variable of base component 'out_x_1'", AutomatonUtil.isOutputVariable(bcX, "x")); Assert.assertTrue( "y is NOT an output variable of base component 'out_x_1'", !AutomatonUtil.isOutputVariable(bcX, "y")); Assert.assertTrue( "x is NOT an output variable of base component 'out_y_1'", !AutomatonUtil.isOutputVariable(bcY, "x")); Assert.assertTrue( "y is an output variable of base component 'out_y_1'", AutomatonUtil.isOutputVariable(bcY, "y")); }
@Test public void testPrintInitStates() { // Luan's import test. Init was printing as null when it wasn't null String cfgPath = UNIT_BASEDIR + "loc_init/one_init.cfg"; String xmlPath = UNIT_BASEDIR + "loc_init/model.xml"; SpaceExDocument doc = SpaceExImporter.importModels(cfgPath, xmlPath); Map<String, Component> componentTemplates = TemplateImporter.createComponentTemplates(doc); Configuration config = com.verivital.hyst.importer.ConfigurationMaker.fromSpaceEx(doc, componentTemplates); String initString = AutomatonUtil.getMapExpressionString(config.init); Assert.assertTrue("init string is not null", initString != null); }
@Test public void testClassifySubtract() { String[][] dy = {{"x", "-x - 2 * y -0.2 * u"}, {"y", "4 * x - 3 * y + 2 * u"}, {"u", "1"}}; // Automaton with three variables ['x', 'y', 'u'] and flows: // x' == -x - 2 * y -0.2 * u // y' == 4 * x - 3 * y + 2 * u // u' == 1 Configuration c = AutomatonUtil.makeDebugConfiguration(dy); BaseComponent ha = ((BaseComponent) c.root); AutomatonMode mode = ha.modes.values().iterator().next(); Classification cls = new Classification(); Classification.ha = ha; cls.setVarID(ha); cls.setLinearMatrix(mode); double TOL = 1e-9; Assert.assertEquals(-1, Classification.linearMatrix[0][0], TOL); }