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();
}
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));
}
}
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()));
}
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);
}
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()));
}
Aggregations