Search in sources :

Example 1 with ProductDecl

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

the class DeltaOrderingTest method properSorting9.

@Test
public void properSorting9() throws DeltaModellingException, WrongProgramArgumentException {
    Model model = assertParse("module Test;" + "delta D1;" + "delta D2;" + "delta D3;" + "delta D4;" + "delta D5;" + "delta D6;" + "delta D7;" + "delta D8;" + "delta D9;" + "productline PL;" + "features A,B,C,D,E,F,G,H,I;" + "delta D1 after D2 when A;" + "delta D2 after D3 when B;" + "delta D3 after D4 when C;" + "delta D4 after D5 when D;" + "delta D5 after D6 when E;" + "delta D6 after D7 when F;" + "delta D7 after D8 when G;" + "delta D8 after D9 when H;" + "delta D9 when I;" + "product P1(A,B,C,D,E,F,G,H,I);" + "product P2(A,C,E,G,I);");
    model.evaluateAllProductDeclarations();
    ProductDecl prod = model.findProduct("P1");
    ProductLine pl = model.getProductLine();
    Set<String> deltaids = pl.findApplicableDeltas(prod.getProduct());
    List<String> sorted_deltaids = pl.sortDeltas(deltaids);
    assertArrayEquals(new String[] { "D9", "D8", "D7", "D6", "D5", "D4", "D3", "D2", "D1" }, sorted_deltaids.toArray());
    prod = model.findProduct("P2");
    deltaids = pl.findApplicableDeltas(prod.getProduct());
    sorted_deltaids = pl.sortDeltas(deltaids);
    assertArrayEquals(new String[] { "D9", "D7", "D5", "D3", "D1" }, sorted_deltaids.toArray());
    assertFalse(model.typeCheck().containsErrors());
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) ProductLine(org.abs_models.frontend.ast.ProductLine) Test(org.junit.Test)

Example 2 with ProductDecl

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

the class ProductDeclarationTest method productUnion.

@Test
public void productUnion() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2, F3} || {F4};");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    Product impl = p.getProduct();
    assertEquals(4, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F1", "F2", "F3", "F4"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ProductDecl

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

the class ProductDeclarationTest method oldProductSyntax.

@Test
public void oldProductSyntax() throws WrongProgramArgumentException {
    Model model = assertParse("product P1(F1, F2, F3);");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    Product impl = p.getProduct();
    assertEquals(3, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F1", "F2", "F3"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ProductDecl

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

the class ProductDeclarationTest method productIntersect.

@Test
public void productIntersect() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2, F3} && {F2, F3};");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    Product impl = p.getProduct();
    assertEquals(2, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F2", "F3"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with ProductDecl

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

the class ProductDeclarationTest method invalidProduct.

@Test
public void invalidProduct() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2};" + "root FM {" + "group allof { F1, F2, F3 }" + "}");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    SemanticConditionList e = new SemanticConditionList();
    typeCheck(model, p, e);
    assertEquals(1, e.getErrorCount());
    assertEquals(ErrorMessage.INVALID_PRODUCT, e.getFirstError().msg);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Aggregations

ProductDecl (org.abs_models.frontend.ast.ProductDecl)19 Model (org.abs_models.frontend.ast.Model)17 Test (org.junit.Test)16 HashSet (java.util.HashSet)11 Feature (org.abs_models.frontend.ast.Feature)10 Product (org.abs_models.frontend.ast.Product)9 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)4 WrongProgramArgumentException (org.abs_models.common.WrongProgramArgumentException)3 ProductLine (org.abs_models.frontend.ast.ProductLine)3 Constraint (choco.kernel.model.constraints.Constraint)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 InternalBackendException (org.abs_models.backend.common.InternalBackendException)1 FrontendTest (org.abs_models.frontend.FrontendTest)1 DataConstructor (org.abs_models.frontend.ast.DataConstructor)1 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1 DataTypeDecl (org.abs_models.frontend.ast.DataTypeDecl)1 Decl (org.abs_models.frontend.ast.Decl)1 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)1