Search in sources :

Example 6 with BtrpNumber

use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.

the class ScriptBuilderTest method testNumberComputation.

public void testNumberComputation() {
    ScriptBuilder b = new ScriptBuilder(new DefaultModel());
    try {
        Script v = b.build(new File(RC_ROOT + "number.btrp"));
        BtrpNumber x = (BtrpNumber) v.getImportable("$x");
        BtrpNumber y = (BtrpNumber) v.getImportable("$y");
        BtrpNumber z = (BtrpNumber) v.getImportable("$z");
        BtrpNumber a = (BtrpNumber) v.getImportable("$a");
        BtrpNumber c2 = (BtrpNumber) v.getImportable("$c");
        BtrpNumber toto = (BtrpNumber) v.getImportable("$toto");
        BtrpNumber titi = (BtrpNumber) v.getImportable("$titi");
        BtrpNumber foo = (BtrpNumber) v.getImportable("$foo");
        BtrpNumber bar = (BtrpNumber) v.getImportable("$bar");
        BtrpNumber bi = (BtrpNumber) v.getImportable("$bi");
        BtrpNumber f1 = (BtrpNumber) v.getImportable("$f1");
        BtrpNumber f2 = (BtrpNumber) v.getImportable("$f2");
        BtrpNumber f3 = (BtrpNumber) v.getImportable("$f3");
        // System.err.println(v);
        Assert.assertTrue(x.isInteger());
        Assert.assertEquals(x.getIntValue(), 2);
        Assert.assertTrue(y.isInteger());
        Assert.assertEquals(y.getIntValue(), 8);
        Assert.assertTrue(z.isInteger());
        Assert.assertEquals(z.getIntValue(), 26);
        Assert.assertTrue(a.isInteger());
        Assert.assertEquals(a.getIntValue(), 2);
        Assert.assertTrue(c2.isInteger());
        Assert.assertEquals(c2.getIntValue(), 1);
        Assert.assertFalse(f1.isInteger());
        Assert.assertEquals(f1.getDoubleValue(), 0.7);
        Assert.assertFalse(f2.isInteger());
        Assert.assertEquals(f2.getDoubleValue(), 3.0);
        Assert.assertFalse(f3.isInteger());
        Assert.assertEquals(f3.getDoubleValue(), 892, 5);
        BtrpNumber baz = (BtrpNumber) v.getImportable("$baz");
        Assert.assertEquals(baz, BtrpNumber.TRUE);
        BtrpNumber biz = (BtrpNumber) v.getImportable("$biz");
        Assert.assertEquals(biz, BtrpNumber.TRUE);
        Assert.assertEquals(toto, BtrpNumber.FALSE);
        Assert.assertEquals(titi, BtrpNumber.TRUE);
        Assert.assertEquals(foo, BtrpNumber.TRUE);
        Assert.assertEquals(bar, BtrpNumber.TRUE);
        Assert.assertEquals(bi, BtrpNumber.FALSE);
    } catch (ScriptBuilderException x) {
        Assert.fail(x.getMessage(), x);
    }
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber) File(java.io.File)

Example 7 with BtrpNumber

use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.

the class SymbolsTableTest method testPushAndPop.

public void testPushAndPop() {
    SymbolsTable t = new SymbolsTable();
    BtrpNumber i = new BtrpNumber(5, BtrpNumber.Base.BASE_10);
    t.declareImmutable("$v1", i);
    BtrpNumber i2 = new BtrpNumber(7, BtrpNumber.Base.BASE_10);
    t.declare("$v2", i2);
    t.pushTable();
    Assert.assertTrue(t.isDeclared("$v1"));
    Assert.assertTrue(t.isDeclared("$v2"));
    BtrpNumber i3 = new BtrpNumber(7, BtrpNumber.Base.BASE_10);
    t.declare("$v3", i3);
    // New variable
    Assert.assertTrue(t.isDeclared("$v3"));
    // Redefinition
    BtrpNumber i4 = new BtrpNumber(-7, BtrpNumber.Base.BASE_10);
    t.declare("$v2", i4);
    Assert.assertEquals(t.getSymbol("$v2"), i4);
    // Immutable variable that will stay
    BtrpNumber i10 = new BtrpNumber(10, BtrpNumber.Base.BASE_10);
    t.declareImmutable("$v10", i10);
    Assert.assertTrue(t.popTable());
    // $v3 as disappear
    Assert.assertFalse(t.isDeclared("$v3"));
    Assert.assertNull(t.getSymbol("$v3"));
    // $v4 always present with the modified value
    Assert.assertEquals(t.getSymbol("$v2"), i4);
    Assert.assertEquals(t.getSymbol("$v10"), i10);
    Assert.assertFalse(t.popTable());
}
Also used : BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber)

Example 8 with BtrpNumber

use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.

the class SymbolsTableTest method testRemove.

public void testRemove() {
    SymbolsTable t = new SymbolsTable();
    BtrpNumber i = new BtrpNumber(5, BtrpNumber.Base.BASE_10);
    t.declareImmutable("$v1", i);
    BtrpNumber i2 = new BtrpNumber(7, BtrpNumber.Base.BASE_10);
    t.declare("$v2", i2);
    Assert.assertNotNull(t.toString());
    Assert.assertTrue(t.remove("$v1"));
    Assert.assertTrue(t.remove("$v2"));
    Assert.assertFalse(t.remove("$v3"));
}
Also used : BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber)

Example 9 with BtrpNumber

use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.

the class SymbolsTableTest method testDeclare.

public void testDeclare() {
    SymbolsTable t = new SymbolsTable();
    BtrpNumber i = new BtrpNumber(5, BtrpNumber.Base.BASE_10);
    t.declareImmutable("$v3", i);
    BtrpNumber i3 = new BtrpNumber(5, BtrpNumber.Base.BASE_10);
    Assert.assertTrue(t.declare("$v1", i3));
    Assert.assertEquals(t.getSymbol("$v1"), i3);
    Assert.assertTrue(t.isDeclared("$v1"));
    // Declared as immutable, no way
    Assert.assertFalse(t.declare("$v3", i));
    BtrpNumber i2 = new BtrpNumber(7, BtrpNumber.Base.BASE_10);
    Assert.assertTrue(t.declare("$v1", i2));
    Assert.assertEquals(t.getSymbol("$v1"), i2);
    Assert.assertNotNull(t.toString());
}
Also used : BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber)

Example 10 with BtrpNumber

use of org.btrplace.btrpsl.element.BtrpNumber in project scheduler by btrplace.

the class SymbolsTableTest method testDeclareImmutable.

public void testDeclareImmutable() {
    SymbolsTable t = new SymbolsTable();
    BtrpNumber i = new BtrpNumber(5, BtrpNumber.Base.BASE_10);
    Assert.assertTrue(t.declareImmutable("$v1", i));
    Assert.assertEquals(t.getSymbol("$v1"), i);
    Assert.assertTrue(t.isDeclared("$v1"));
    Assert.assertTrue(t.isImmutable("$v1"));
    // No way to override an immutable value
    BtrpNumber i2 = new BtrpNumber(7, BtrpNumber.Base.BASE_10);
    Assert.assertFalse(t.declare("$v1", i2));
    Assert.assertFalse(t.declareImmutable("$v1", i2));
    Assert.assertNotNull(t.toString());
}
Also used : BtrpNumber(org.btrplace.btrpsl.element.BtrpNumber)

Aggregations

BtrpNumber (org.btrplace.btrpsl.element.BtrpNumber)13 File (java.io.File)4 List (java.util.List)4 DefaultModel (org.btrplace.model.DefaultModel)4 Node (org.btrplace.model.Node)3 SatConstraint (org.btrplace.model.constraint.SatConstraint)3 HashSet (java.util.HashSet)1 BtrpOperand (org.btrplace.btrpsl.element.BtrpOperand)1 BtrpSet (org.btrplace.btrpsl.element.BtrpSet)1 VM (org.btrplace.model.VM)1 MaxOnline (org.btrplace.model.constraint.MaxOnline)1 ResourceCapacity (org.btrplace.model.constraint.ResourceCapacity)1 RunningCapacity (org.btrplace.model.constraint.RunningCapacity)1