Search in sources :

Example 6 with TestException

use of maspack.util.TestException in project artisynth_core by artisynth.

the class VectorTest method testSetAndGet.

void testSetAndGet(Vector vr) {
    Random randGen = RandomGenerator.get();
    int size = vr.size();
    double[] setBuf = new double[size];
    double[] getBuf = new double[size];
    for (int i = 0; i < size; i++) {
        double value = randGen.nextDouble();
        vr.set(i, value);
        if (vr.get(i) != value) {
            throw new TestException(elementFailMessage("get/set", i));
        }
        setBuf[i] = value;
    }
    vr.get(getBuf);
    for (int i = 0; i < size; i++) {
        if (getBuf[i] != setBuf[i]) {
            throw new TestException(elementFailMessage("set", i));
        }
    }
    vx.set(vr);
    vr.set(vx);
    vr.get(getBuf);
    for (int i = 0; i < size; i++) {
        if (getBuf[i] != setBuf[i]) {
            throw new TestException("set(Vector) failed for i=" + i + ": get=" + getBuf[i] + ", set=" + setBuf[i]);
        }
    }
}
Also used : Random(java.util.Random) TestException(maspack.util.TestException)

Example 7 with TestException

use of maspack.util.TestException in project artisynth_core by artisynth.

the class VectorTest method doScanWrite.

void doScanWrite(Vector vr, String fmt, boolean withBrackets) {
    StringWriter sw = new StringWriter();
    try {
        vr.write(new PrintWriter(sw), new NumberFormat(fmt), withBrackets);
        vr.scan(new ReaderTokenizer(new StringReader(sw.toString())));
    } catch (Exception e) {
        throw new TestException("scan/write error: " + e.getMessage());
    }
}
Also used : TestException(maspack.util.TestException) ReaderTokenizer(maspack.util.ReaderTokenizer) TestException(maspack.util.TestException) NumberFormat(maspack.util.NumberFormat)

Example 8 with TestException

use of maspack.util.TestException in project artisynth_core by artisynth.

the class VectoriTest method checkResult.

void checkResult(Vectori vr, Vectori vc, Exception eactual, Exception eexpected) {
    MatrixTest.checkExceptions(eactual, eexpected);
    if (!vr.equals(vc)) {
        VectorNi ME = new VectorNi(vr);
        VectorNi v1 = new VectorNi(vc);
        ME.sub(v1);
        ME.absolute();
        throw new TestException("Expected result:\n" + vc.toString(new NumberFormat("%d")) + "\n" + "Actual result:\n" + vr.toString(new NumberFormat("%d")) + "\n" + "max err: " + ME.maxElement());
    }
}
Also used : TestException(maspack.util.TestException) NumberFormat(maspack.util.NumberFormat)

Example 9 with TestException

use of maspack.util.TestException in project artisynth_core by artisynth.

the class VectoriTest method doScanWrite.

void doScanWrite(Vectori vr, String fmt, boolean withBrackets) {
    StringWriter sw = new StringWriter();
    try {
        vr.write(new PrintWriter(sw), new NumberFormat(fmt), withBrackets);
        vr.scan(new ReaderTokenizer(new StringReader(sw.toString())));
    } catch (Exception e) {
        throw new TestException("scan/write error: " + e.getMessage());
    }
}
Also used : TestException(maspack.util.TestException) ReaderTokenizer(maspack.util.ReaderTokenizer) TestException(maspack.util.TestException) NumberFormat(maspack.util.NumberFormat)

Example 10 with TestException

use of maspack.util.TestException in project artisynth_core by artisynth.

the class SpatialInertiaTest method checkComponents.

private void checkComponents(String msg, SpatialInertia M, double massCheck, Point3d comCheck, SymmetricMatrix3d JCheck) {
    SymmetricMatrix3d J = new SymmetricMatrix3d();
    Point3d com = new Point3d();
    double mass = M.getMass();
    M.getCenterOfMass(com);
    M.getRotationalInertia(J);
    if (Math.abs(mass - massCheck) > EPS) {
        throw new TestException(msg + "\ngetMass(): expected " + massCheck + " but got " + mass);
    }
    if (!com.epsilonEquals(comCheck, EPS)) {
        throw new TestException(msg + "\ngetCenterOfMass(): expected " + comCheck + "\ngot " + com);
    }
    if (!J.epsilonEquals(JCheck, EPS)) {
        throw new TestException(msg + "\ngetRotationalInertia(): expected\n" + JCheck + "\nGot\n" + J);
    }
    MatrixNd MM = new MatrixNd(6, 6);
    MatrixNd MCheck = new MatrixNd(6, 6);
    MM.set(M);
    for (int i = 0; i < 3; i++) {
        MCheck.set(i, i, mass);
    }
    MCheck.set(0, 4, mass * com.z);
    MCheck.set(0, 5, -mass * com.y);
    MCheck.set(1, 5, mass * com.x);
    MCheck.set(1, 3, -mass * com.z);
    MCheck.set(2, 3, mass * com.y);
    MCheck.set(2, 4, -mass * com.x);
    MCheck.set(3, 3, J.m00 + mass * (com.z * com.z + com.y * com.y));
    MCheck.set(4, 4, J.m11 + mass * (com.z * com.z + com.x * com.x));
    MCheck.set(5, 5, J.m22 + mass * (com.y * com.y + com.x * com.x));
    MCheck.set(3, 4, J.m01 - mass * (com.x * com.y));
    MCheck.set(3, 5, J.m02 - mass * (com.x * com.z));
    MCheck.set(4, 5, J.m12 - mass * (com.z * com.y));
    for (int i = 1; i < 6; i++) {
        for (int j = 0; j < i; j++) {
            MCheck.set(i, j, MCheck.get(j, i));
        }
    }
    if (!MM.epsilonEquals(MCheck, EPS)) {
        throw new TestException(msg + "\nMatrix: expected\n" + MCheck + "\nGot\n" + MM);
    }
}
Also used : TestException(maspack.util.TestException) SymmetricMatrix3d(maspack.matrix.SymmetricMatrix3d) Point3d(maspack.matrix.Point3d) MatrixNd(maspack.matrix.MatrixNd)

Aggregations

TestException (maspack.util.TestException)17 NumberFormat (maspack.util.NumberFormat)4 Point3d (maspack.matrix.Point3d)3 Random (java.util.Random)2 Vector3d (maspack.matrix.Vector3d)2 ReaderTokenizer (maspack.util.ReaderTokenizer)2 StringReader (java.io.StringReader)1 InsideQuery (maspack.geometry.BVFeatureQuery.InsideQuery)1 Vertex3d (maspack.geometry.Vertex3d)1 MatrixNd (maspack.matrix.MatrixNd)1 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)1 VectorNd (maspack.matrix.VectorNd)1