Search in sources :

Example 1 with Constant

use of org.btrplace.safeplace.spec.term.Constant in project scheduler by btrplace.

the class TestCase method toJSON.

public String toJSON() throws JSONConverterException {
    InstanceConverter ic = new InstanceConverter();
    ic.getConstraintsConverter().register(new ScheduleConverter());
    ReconfigurationPlanConverter pc = new ReconfigurationPlanConverter();
    JSONObject o = new JSONObject();
    o.put("constraint", constraint().id());
    JSONArray a = new JSONArray();
    for (Constant c : args()) {
        a.add(c.toJSON());
    }
    o.put("args", a);
    o.put("continuous", continuous());
    o.put("groups", groups());
    o.put("plan", pc.toJSON(plan()));
    o.put("instance", ic.toJSON(instance()));
    return o.toJSONString();
}
Also used : ScheduleConverter(org.btrplace.safeplace.testing.verification.btrplace.ScheduleConverter) JSONObject(net.minidev.json.JSONObject) Constant(org.btrplace.safeplace.spec.term.Constant) InstanceConverter(org.btrplace.json.model.InstanceConverter) ReconfigurationPlanConverter(org.btrplace.json.plan.ReconfigurationPlanConverter) JSONArray(net.minidev.json.JSONArray)

Example 2 with Constant

use of org.btrplace.safeplace.spec.term.Constant in project scheduler by btrplace.

the class SpecVerifier method fillArguments.

public void fillArguments(Context mo, TestCase tc) {
    Constraint c = tc.constraint();
    List<Constant> values = tc.args();
    // Check signature
    if (values.size() != c.args().size()) {
        throw new IllegalArgumentException(c.toString(values) + " cannot match " + c.signatureToString());
    }
    for (int i = 0; i < values.size(); i++) {
        UserVar<?> var = c.args().get(i);
        Type t = values.get(i).type();
        if (!var.type().equals(t)) {
            throw new IllegalArgumentException(c.toString(values) + " cannot match " + c.signatureToString());
        }
        mo.setValue(var.label(), values.get(i).eval(mo));
    }
}
Also used : Type(org.btrplace.safeplace.spec.type.Type) Constraint(org.btrplace.safeplace.spec.Constraint) Constant(org.btrplace.safeplace.spec.term.Constant) Constraint(org.btrplace.safeplace.spec.Constraint)

Example 3 with Constant

use of org.btrplace.safeplace.spec.term.Constant in project scheduler by btrplace.

the class MinusTest method testCollections.

@Test
public void testCollections() {
    Constant v1 = new Constant(Arrays.asList(1, 2), new SetType(IntType.getInstance()));
    Constant v2 = new Constant(Arrays.asList(2, 5), new SetType(IntType.getInstance()));
    Minus<?> p = new SetMinus(v1, v2);
    Set<?> s = (Set<?>) p.eval(new Context());
    Assert.assertEquals(s.size(), 1);
    Assert.assertEquals(p.type(), new SetType(IntType.getInstance()));
}
Also used : Context(org.btrplace.safeplace.testing.verification.spec.Context) Set(java.util.Set) SetType(org.btrplace.safeplace.spec.type.SetType) Constant(org.btrplace.safeplace.spec.term.Constant) SetMinus(org.btrplace.safeplace.spec.term.SetMinus) Test(org.testng.annotations.Test)

Example 4 with Constant

use of org.btrplace.safeplace.spec.term.Constant in project scheduler by btrplace.

the class MinusTest method testBadCollections.

@Test(expectedExceptions = { RuntimeException.class })
public void testBadCollections() throws RuntimeException {
    Constant v1 = new Constant(Arrays.asList(1, 2), new SetType(IntType.getInstance()));
    Constant v2 = new Constant(Collections.singletonList(VMStateType.getInstance().parse("running")), new SetType(VMStateType.getInstance()));
    @SuppressWarnings("unused") SetMinus bad = new SetMinus(v1, v2);
}
Also used : SetType(org.btrplace.safeplace.spec.type.SetType) Constant(org.btrplace.safeplace.spec.term.Constant) SetMinus(org.btrplace.safeplace.spec.term.SetMinus) Test(org.testng.annotations.Test)

Example 5 with Constant

use of org.btrplace.safeplace.spec.term.Constant in project scheduler by btrplace.

the class PlusTest method testCollections.

@Test
public void testCollections() {
    Constant v1 = new Constant(new HashSet<>(Arrays.asList(1, 2)), new SetType(IntType.getInstance()));
    Constant v2 = new Constant(new HashSet<>(Arrays.asList(4, 5)), new SetType(IntType.getInstance()));
    Plus<?> p = new SetPlus(v1, v2);
    Set<?> s = (Set<?>) p.eval(new Context());
    Assert.assertEquals(s.size(), 4);
    Assert.assertEquals(p.type(), new SetType(IntType.getInstance()));
}
Also used : Context(org.btrplace.safeplace.testing.verification.spec.Context) Set(java.util.Set) HashSet(java.util.HashSet) SetType(org.btrplace.safeplace.spec.type.SetType) Constant(org.btrplace.safeplace.spec.term.Constant) SetPlus(org.btrplace.safeplace.spec.term.SetPlus) Test(org.testng.annotations.Test)

Aggregations

Constant (org.btrplace.safeplace.spec.term.Constant)8 SetType (org.btrplace.safeplace.spec.type.SetType)4 Test (org.testng.annotations.Test)4 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 JSONArray (net.minidev.json.JSONArray)2 JSONObject (net.minidev.json.JSONObject)2 InstanceConverter (org.btrplace.json.model.InstanceConverter)2 ReconfigurationPlanConverter (org.btrplace.json.plan.ReconfigurationPlanConverter)2 SatConstraint (org.btrplace.model.constraint.SatConstraint)2 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)2 Constraint (org.btrplace.safeplace.spec.Constraint)2 SetMinus (org.btrplace.safeplace.spec.term.SetMinus)2 SetPlus (org.btrplace.safeplace.spec.term.SetPlus)2 ScheduleConverter (org.btrplace.safeplace.testing.verification.btrplace.ScheduleConverter)2 Context (org.btrplace.safeplace.testing.verification.spec.Context)2 StringReader (java.io.StringReader)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1