Search in sources :

Example 1 with IntRange

use of kodkod.util.ints.IntRange in project org.alloytools.alloy by AlloyTools.

the class IntTest method test2sComplementUnOps.

private final void test2sComplementUnOps(IntExpression[] vals) {
    final Options options = solver.options();
    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();
    final int mask = ~(-1 << options.bitwidth());
    for (int i = min; i <= max; i++) {
        IntExpression vi = vals[i - min];
        testUnOp(IntOperator.NEG, vi, i, -i, mask);
        testUnOp(IntOperator.NOT, vi, i, ~i, mask);
        testUnOp(IntOperator.ABS, vi, i, Math.abs(i), mask);
        testUnOp(IntOperator.SGN, vi, i, i < 0 ? -1 : i > 0 ? 1 : 0, mask);
    }
}
Also used : Options(kodkod.engine.config.Options) IntExpression(kodkod.ast.IntExpression) IntRange(kodkod.util.ints.IntRange)

Example 2 with IntRange

use of kodkod.util.ints.IntRange in project org.alloytools.alloy by AlloyTools.

the class IntTest method testComparisonOps.

/**
 * Tests all comparison ops for this.solver.options and range of vals.
 *
 * @requires this.solver.options.intEncoding = binary
 * @requires vals contains int expressions that represent all integers allowed
 *           by this.solver.options, in proper sequence
 */
private final void testComparisonOps(IntExpression[] vals) {
    final Options options = solver.options();
    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();
    for (int i = min; i <= max; i++) {
        IntExpression vi = vals[i - min];
        for (int j = min; j <= max; j++) {
            IntExpression vj = vals[j - min];
            testCompOp(EQ, vi, vj, i, j, i == j);
            testCompOp(LT, vi, vj, i, j, i < j);
            testCompOp(LTE, vi, vj, i, j, i <= j);
            testCompOp(GT, vi, vj, i, j, i > j);
            testCompOp(GTE, vi, vj, i, j, i >= j);
        }
    }
}
Also used : Options(kodkod.engine.config.Options) IntExpression(kodkod.ast.IntExpression) IntRange(kodkod.util.ints.IntRange)

Example 3 with IntRange

use of kodkod.util.ints.IntRange in project org.alloytools.alloy by AlloyTools.

the class IntTest method test2sComplementBinOps.

/**
 * Tests all binary ops for this.solver.options and range of vals.
 *
 * @requires this.solver.options.intEncoding = binary
 * @requires vals contains int expressions that represent all integers allowed
 *           by this.solver.options, in proper sequence
 */
private final void test2sComplementBinOps(IntExpression[] vals) {
    final Options options = solver.options();
    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();
    final int mask = ~(-1 << options.bitwidth());
    final int shiftmask = ~(-1 << (32 - Integer.numberOfLeadingZeros(options.bitwidth() - 1)));
    for (int i = min; i <= max; i++) {
        IntExpression vi = vals[i - min];
        for (int j = min; j <= max; j++) {
            IntExpression vj = vals[j - min];
            testBinOp(PLUS, vi, vj, i, j, i + j, mask);
            testBinOp(MINUS, vi, vj, i, j, i - j, mask);
            testBinOp(MULTIPLY, vi, vj, i, j, i * j, mask);
            if (j != 0) {
                testBinOp(DIVIDE, vi, vj, i, j, i / j, mask);
                testBinOp(MODULO, vi, vj, i, j, i % j, mask);
            }
            testBinOp(AND, vi, vj, i, j, i & j, mask);
            testBinOp(OR, vi, vj, i, j, i | j, mask);
            testBinOp(XOR, vi, vj, i, j, i ^ j, mask);
            testBinOp(SHL, vi, vj, i, j, i << (j & shiftmask), i << j, mask);
            testBinOp(SHR, vi, vj, i, j, (i & mask) >>> (j & shiftmask), mask);
            testBinOp(SHA, vi, vj, i, j, i >> (j & shiftmask), mask);
        }
    }
}
Also used : Options(kodkod.engine.config.Options) IntExpression(kodkod.ast.IntExpression) IntRange(kodkod.util.ints.IntRange)

Example 4 with IntRange

use of kodkod.util.ints.IntRange in project org.alloytools.alloy by AlloyTools.

the class IntTest method nonConstants.

private IntExpression[] nonConstants() {
    final Options options = solver.options();
    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();
    final int size = range.size();
    final Relation[] r = new Relation[size];
    final TupleFactory f = bounds.universe().factory();
    for (int i = 0; i < size; i++) {
        int arity = i % 3 + 1;
        r[i] = Relation.nary("r" + i, arity);
        TupleSet b = f.noneOf(arity);
        for (int j = (i / 3) * ((int) Math.pow(SIZE, arity - 1)), jmax = j + size; j < jmax; j++) {
            b.add(f.tuple(arity, j % b.capacity()));
        }
        bounds.bound(r[i], b);
    }
    final IntExpression[] vals = new IntExpression[max - min + 1];
    for (int i = 0; i < size; i++) {
        vals[i] = i + min < 0 ? r[i].count().negate() : r[i].count();
    }
    return vals;
}
Also used : Options(kodkod.engine.config.Options) TupleSet(kodkod.instance.TupleSet) Relation(kodkod.ast.Relation) IntExpression(kodkod.ast.IntExpression) IntRange(kodkod.util.ints.IntRange) TupleFactory(kodkod.instance.TupleFactory)

Example 5 with IntRange

use of kodkod.util.ints.IntRange in project org.alloytools.alloy by AlloyTools.

the class IntTest method constants.

private IntExpression[] constants() {
    final Options options = solver.options();
    final IntRange range = options.integers();
    final int min = range.min(), max = range.max();
    final IntExpression[] vals = new IntExpression[max - min + 1];
    for (int i = min; i <= max; i++) {
        vals[i - min] = constant(i);
    }
    return vals;
}
Also used : Options(kodkod.engine.config.Options) IntExpression(kodkod.ast.IntExpression) IntRange(kodkod.util.ints.IntRange)

Aggregations

IntExpression (kodkod.ast.IntExpression)5 Options (kodkod.engine.config.Options)5 IntRange (kodkod.util.ints.IntRange)5 Relation (kodkod.ast.Relation)1 TupleFactory (kodkod.instance.TupleFactory)1 TupleSet (kodkod.instance.TupleSet)1