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