Search in sources :

Example 61 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class ProgramAbstractionTest method addClass.

@Test
public void addClass() {
    Model model = assertParse("module M;" + "delta D;" + "uses M;" + "adds class C(Rat myParam) { Int myField = 99; Int myMethod(String a, Bool b) { return 88; } }" + "productline PL;" + "features F;" + "delta D when F;" + "root FM { group allof { opt F } }");
    SemanticConditionList errors = new SemanticConditionList();
    ProductLine pl = model.getProductLine();
    DeltaTrie trie = ProductLineAnalysisHelper.buildPFGT(pl, errors);
    ProgramAbstraction pa = trie.getRoot().getChildren().get("D").getProgramAbstraction();
    assertTrue(pa.getClasses().containsKey("M.C"));
    assertEquals(2, pa.getClasses().get("M.C").get("fields").keySet().size());
    assertTrue(pa.getClasses().get("M.C").get("fields").containsKey("myParam"));
    assertEquals("Rat", pa.getClasses().get("M.C").get("fields").get("myParam").get(0));
    assertTrue(pa.getClasses().get("M.C").get("fields").containsKey("myField"));
    assertEquals("Int", pa.getClasses().get("M.C").get("fields").get("myField").get(0));
    assertTrue(pa.getClasses().get("M.C").get("methods").containsKey("myMethod"));
    assertEquals(3, pa.getClasses().get("M.C").get("methods").get("myMethod").size());
    assertEquals("Int", pa.getClasses().get("M.C").get("methods").get("myMethod").get(0));
    assertEquals("String", pa.getClasses().get("M.C").get("methods").get("myMethod").get(1));
    assertEquals("Bool", pa.getClasses().get("M.C").get("methods").get("myMethod").get(2));
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) ProductLine(org.abs_models.frontend.ast.ProductLine) Test(org.junit.Test)

Example 62 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class SearchSolutionsTest method SearchSolutions.

@Test
public void SearchSolutions() throws Exception {
    Model model = assertParse(helloprogram);
    model.setNullPrintStream();
    ChocoSolver s = model.instantiateCSModel();
    model.evaluateAllProductDeclarations();
    assertEquals(78, s.countSolutions());
    assertTrue(checkSol(s, model, "P1"));
    assertTrue(checkSol(s, model, "P2"));
    assertTrue(checkSol(s, model, "P3"));
    assertTrue(!checkSol(s, model, "P4"));
}
Also used : Model(org.abs_models.frontend.ast.Model) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 63 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class SearchSolutionsTest method SearchSolutionsNoAttr.

@Test
public void SearchSolutionsNoAttr() {
    Model model = assertParse(helloprogram);
    model.dropAttributes();
    ChocoSolver s = model.instantiateCSModel();
    assertEquals(8, s.countSolutions());
}
Also used : Model(org.abs_models.frontend.ast.Model) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 64 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class ParFnAppTest method sameAnonTwiceTwoClosureParams.

@Test
public void sameAnonTwiceTwoClosureParams() {
    Model m = testExpand(parse("Int x = 1; test(() => x, () => x)();", "def Int test(f, g)() = f() + g();"), "test_%s_Anon\\d+__");
    FunctionDecl function = getFunction(m, Pattern.compile(expandedName("test_%s_Anon\\d+__")));
    assertNotNull(function);
    assertEquals(2, function.getNumParam());
    assertEquals("x__0__", function.getParam(0).getName());
    assertEquals("x__1__", function.getParam(1).getName());
}
Also used : Model(org.abs_models.frontend.ast.Model) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 65 with Model

use of org.abs_models.frontend.ast.Model in project abstools by abstools.

the class ParFnAppTest method recursionWithClosure.

@Test
public void recursionWithClosure() {
    Model m = expand(parse("Int x = 0; Int y = 1; rec((Int i) => x, (Int j) => y)();", "def Int rec(f, g)() = rec();"));
    FnApp call = assertHasCall(m, expandedName("rec_%s_Anon\\d+__"));
    assertEquals(2, call.getNumParam());
}
Also used : FnApp(org.abs_models.frontend.ast.FnApp) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Aggregations

Model (org.abs_models.frontend.ast.Model)268 Test (org.junit.Test)227 FrontendTest (org.abs_models.frontend.FrontendTest)101 ClassDecl (org.abs_models.frontend.ast.ClassDecl)72 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)34 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)29 ABSTest (org.abs_models.ABSTest)22 ProductDecl (org.abs_models.frontend.ast.ProductDecl)17 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)15 HashSet (java.util.HashSet)13 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)13 PrintStream (java.io.PrintStream)12 Product (org.abs_models.frontend.ast.Product)11 SkipStmt (org.abs_models.frontend.ast.SkipStmt)11 VarUse (org.abs_models.frontend.ast.VarUse)11 Feature (org.abs_models.frontend.ast.Feature)10 File (java.io.File)9 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)9 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)9 KindedName (org.abs_models.frontend.typechecker.KindedName)9