Search in sources :

Example 1 with SetType

use of org.btrplace.safeplace.spec.type.SetType 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 2 with SetType

use of org.btrplace.safeplace.spec.type.SetType 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 3 with SetType

use of org.btrplace.safeplace.spec.type.SetType 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)

Example 4 with SetType

use of org.btrplace.safeplace.spec.type.SetType in project scheduler by btrplace.

the class DefaultFuzzer method domain.

private Domain<?> domain(UserVar<?> v, Model mo) {
    Domain<?> d = doms.get(v.label());
    if (d != null) {
        return d;
    }
    // Default domains
    if (!(v.getBackend().type() instanceof SetType)) {
        return null;
    }
    SetType back = (SetType) v.getBackend().type();
    if (back.enclosingType().equals(NodeType.getInstance())) {
        return new ConstantDomain<>(rnd, "nodes", NodeType.getInstance(), new ArrayList<>(mo.getMapping().getAllNodes()));
    } else if (back.enclosingType().equals(VMType.getInstance())) {
        return new ConstantDomain<>(rnd, "vms", VMType.getInstance(), new ArrayList<>(mo.getMapping().getAllVMs()));
    }
    throw new IllegalArgumentException("No domain value attached to argument '" + v.label() + "'");
}
Also used : SetType(org.btrplace.safeplace.spec.type.SetType) ConstantDomain(org.btrplace.safeplace.testing.fuzzer.domain.ConstantDomain) ArrayList(java.util.ArrayList)

Example 5 with SetType

use of org.btrplace.safeplace.spec.type.SetType in project scheduler by btrplace.

the class PlusTest method testBadCollections.

@Test(expectedExceptions = { RuntimeException.class })
public void testBadCollections() throws RuntimeException {
    Constant v1 = new Constant(new HashSet<>(Arrays.asList(1, 2)), new SetType(IntType.getInstance()));
    Constant v2 = new Constant(new HashSet<>(Collections.singletonList(VMStateType.getInstance().parse("running"))), new SetType(VMStateType.getInstance()));
    @SuppressWarnings("unused") SetPlus bad = new SetPlus(v1, v2);
}
Also used : 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

SetType (org.btrplace.safeplace.spec.type.SetType)5 Constant (org.btrplace.safeplace.spec.term.Constant)4 Test (org.testng.annotations.Test)4 Set (java.util.Set)2 SetMinus (org.btrplace.safeplace.spec.term.SetMinus)2 SetPlus (org.btrplace.safeplace.spec.term.SetPlus)2 Context (org.btrplace.safeplace.testing.verification.spec.Context)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ConstantDomain (org.btrplace.safeplace.testing.fuzzer.domain.ConstantDomain)1