Search in sources :

Example 31 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class SearchSolutionsTest method CheckEmptyProduct.

@Test
public void CheckEmptyProduct() throws WrongProgramArgumentException {
    Model model = assertParseOk(withoutProducLine);
    ChocoSolver s = model.instantiateCSModel();
    model.evaluateAllProductDeclarations();
    ProductDecl product = model.findProduct("P");
    Map<String, Integer> guess = product.getProduct().getSolution();
    assertEquals(true, s.checkSolution(guess, model));
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 32 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class ParFnAppTest method tooManyArgsForFuncParam.

@Test
public void tooManyArgsForFuncParam() {
    Model m = parse("apply(tooFew)(0);", applyFunction(), "def Int tooFew() = 0;");
    m.expandPartialFunctions();
    SemanticConditionList conditions = m.typeCheck();
    assertTrue(conditions.containsErrors());
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Example 33 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class ParFnAppTest method sameAnonTwiceTwoExpansions.

@Test
public void sameAnonTwiceTwoExpansions() {
    Model m = testExpand(parse("apply((Int i) => i)(1);" + "apply((Int i) => i)(1);", applyFunction()));
    ModuleDecl module = m.lookupModule("UnitTest");
    int foundExpansions = 0;
    for (Decl decl : module.getDecls()) {
        if (decl instanceof FunctionDecl) {
            FunctionDecl fun = (FunctionDecl) decl;
            if (fun.getName().startsWith("Apply_")) {
                ++foundExpansions;
            }
        }
    }
    assertEquals(2, foundExpansions);
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 34 with Model

use of abs.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("X0", function.getParam(0).getName());
    assertEquals("X1", function.getParam(1).getName());
}
Also used : Model(abs.frontend.ast.Model) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 35 with Model

use of abs.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(abs.frontend.ast.FnApp) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Aggregations

Model (abs.frontend.ast.Model)226 Test (org.junit.Test)170 FrontendTest (abs.frontend.FrontendTest)93 ClassDecl (abs.frontend.ast.ClassDecl)57 DeltaDecl (abs.frontend.ast.DeltaDecl)30 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)24 FunctionDecl (abs.frontend.ast.FunctionDecl)15 PrintStream (java.io.PrintStream)14 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)11 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)9 ModuleDecl (abs.frontend.ast.ModuleDecl)9 CompilationUnit (abs.frontend.ast.CompilationUnit)7 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 PartialFunctionDecl (abs.frontend.ast.PartialFunctionDecl)7 PureExp (abs.frontend.ast.PureExp)7 TraitExpr (abs.frontend.ast.TraitExpr)7 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)6