TEST(MatrixTest, should_multiply_correctly) { float as[6] = { 0, 1, 2, 3, 4, 5 }; Matrix *a = new Matrix(2, 3, as); float bs[6] = { -1, -2, 3, 4, 5, 6 }; Matrix *b = new Matrix(3, 2, bs); Matrix c = a[0] * b[0]; CHECK_EQUAL(2, c.getRows()); CHECK_EQUAL(2, c.getCols()); DOUBLES_EQUAL(13.0f, c.getCell(0, 0), 0.001); DOUBLES_EQUAL(16.0f, c.getCell(0, 1), 0.001); DOUBLES_EQUAL((float)(-3+12+25), c.getCell(1, 0), 0.001); DOUBLES_EQUAL((float)(-6+16+30), c.getCell(1, 1), 0.001); delete a; delete b; }
TEST(RTMaterial, shouldSupportAddition) { RTMaterial m1; m1.setKTransparency(0.1); m1.setShininess(0.2); m1.setDiffColor(RTColor(0,0.1,0.2)); m1.setSpecColor(RTColor(0,0.1,0.2)); m1.setAmbColor(RTColor(0,0.1,0.2)); m1.setEmissColor(RTColor(0,0.1,0.2)); RTMaterial m2; m2.setKTransparency(0.3); m2.setShininess(0.2); m2.setDiffColor(RTColor(0,0.1,0.2)); m2.setSpecColor(RTColor(0,0.1,0.2)); m2.setAmbColor(RTColor(0,0.1,0.2)); m2.setEmissColor(RTColor(0,0.1,0.2)); m1 += m2; DOUBLES_EQUAL( 0.4, m1.getKTransparency(), 0.00001 ); DOUBLES_EQUAL( 0.4, m1.getShininess(), 0.00001 ); COLOR_EQUAL(0, 51, 102, m1.getDiffColor() ); COLOR_EQUAL(0, 51, 102, m1.getSpecColor() ); COLOR_EQUAL(0, 51, 102, m1.getAmbColor() ); COLOR_EQUAL(0, 51, 102, m1.getEmissColor() ); }
void TestRegistry::test<1>() { set_test_name("Determinant (2x2 matrix)"); m2f[0] = 1.0f; m2f[2] = 3.0f; m2f[1] = 2.0f; m2f[3] = 4.0f; result = jship::Hazmat::Determinant(m2f); DOUBLES_EQUAL(m2f[0], 1.0, 1e-5); DOUBLES_EQUAL(m2f[1], 2.0, 1e-5); DOUBLES_EQUAL(m2f[2], 3.0, 1e-5); DOUBLES_EQUAL(m2f[3], 4.0, 1e-5); DOUBLES_EQUAL(result, -2.0, 1e-5); m2f[0] = 1.0f; m2f[2] = 2.0f; m2f[1] = -3.0f; m2f[3] = 1.0f; result = jship::Hazmat::Determinant(m2f); DOUBLES_EQUAL(m2f[0], 1.0, 1e-5); DOUBLES_EQUAL(m2f[1], -3.0, 1e-5); DOUBLES_EQUAL(m2f[2], 2.0, 1e-5); DOUBLES_EQUAL(m2f[3], 1.0, 1e-5); DOUBLES_EQUAL(result, 7.0, 1e-5); }
TEST(MS4525DO, pressure_conversion_absolute_type_A) { ms4525do_init(&d, &i2c, 'A', 'I', 2, 'A'); DOUBLES_EQUAL(0, ms4525do_pressure_raw_to_Pa(&d, 1638), 1); // values from datasheet table DOUBLES_EQUAL(1*PSI, ms4525do_pressure_raw_to_Pa(&d, 8192), 1); DOUBLES_EQUAL(2*PSI, ms4525do_pressure_raw_to_Pa(&d, 14746), 3); }
TEST(MockSupport_c, whenNoReturnValueIsGivenReturnDoubleValueOrDefaultShouldlUseTheDefaultValue) { double defaultValue = 2.2; mock_c()->expectOneCall("foo"); DOUBLES_EQUAL(defaultValue, mock_c()->actualCall("foo")->returnDoubleValueOrDefault(defaultValue), 0.005); DOUBLES_EQUAL(defaultValue, mock_c()->returnDoubleValueOrDefault(defaultValue), 0.005); }
TEST(MockSupport_c, returnDoubleValue) { mock_c()->expectOneCall("boo")->andReturnDoubleValue(1.0); DOUBLES_EQUAL(1.0, mock_c()->actualCall("boo")->doubleReturnValue(), 0.005); DOUBLES_EQUAL(1.0, mock_c()->doubleReturnValue(), 0.005); LONGS_EQUAL(MOCKVALUETYPE_DOUBLE, mock_c()->returnValue().type); }
TEST(MS4525DO, pressure_conversion_differential_type_B) { ms4525do_init(&d, &i2c, 'B', 'I', 2, 'D'); DOUBLES_EQUAL(-2*PSI, ms4525do_pressure_raw_to_Pa(&d, 819), 1); // values from datasheet table DOUBLES_EQUAL(0, ms4525do_pressure_raw_to_Pa(&d, 8192), 1); DOUBLES_EQUAL(2*PSI, ms4525do_pressure_raw_to_Pa(&d, 15563), 3); }
TEST(PositioningTestGroup, OutputParamIsNULL) { position_t p_a = {POINT_A_X, POINT_A_Y}; position_t p_b = {POINT_B_X, POINT_B_Y}; position_t p_c = {POINT_C_X, POINT_C_Y}; reference_triangle_t t = {NULL, NULL, NULL, 0, 0, 0}; positioning_reference_triangle_from_points(&p_a, &p_b, &p_c, &t); position_t some_point = {1.0f, 1.0f}; Angles angles = Vec2D(&some_point).angles_relative_to_triangle(&t); position_t result = {0, 0}; bool valid = positioning_from_angles( angles.alpha, angles.beta, angles.gamma, &t, NULL); CHECK(!valid); DOUBLES_EQUAL(0.0, result.x, 0.0001); DOUBLES_EQUAL(0.0, result.y, 0.0001); }
TEST(RayTracer, can_compute_point) { RayTracer r(30, 20, Vect(0, 0, -1), Vect(0, 1, 0)); Point_2D pt = r.computePoint(10, 5); DOUBLES_EQUAL(0.35, pt.x, 0.00001); DOUBLES_EQUAL(0.275, pt.y, 0.00001); }
TEST(MS4525DO, temperature_conversion) { ms4525do_init(&d, &i2c, 'B', 'I', 2, 'D'); DOUBLES_EQUAL(-50, ms4525do_temperature_raw_to_Celsius(&d, 0), 0.1); // values from datasheet table DOUBLES_EQUAL(0, ms4525do_temperature_raw_to_Celsius(&d, 511), 0.1); DOUBLES_EQUAL(25, ms4525do_temperature_raw_to_Celsius(&d, 767), 0.1); DOUBLES_EQUAL(150, ms4525do_temperature_raw_to_Celsius(&d, 2047), 0.1); }
TEST(MockSupport_c, whenReturnValueIsGivenReturnDoubleValueOrDefaultShouldIgnoreTheDefault) { double defaultValue = 2.2; double expectedValue = defaultValue + 0.1; mock_c()->expectOneCall("foo")->andReturnDoubleValue(expectedValue); DOUBLES_EQUAL(expectedValue, mock_c()->actualCall("foo")->returnDoubleValueOrDefault(defaultValue), 0.005); DOUBLES_EQUAL(expectedValue, mock_c()->returnDoubleValueOrDefault(defaultValue), 0.005); }
TEST(RayTracer, has_normalized_vectors) { RayTracer rt(10, 10); rt.setViewDirection(Vect(3, 4, 5)); Vect viewDir = rt.getViewDirection(); DOUBLES_EQUAL(0.424264, viewDir.getX(), 0.0001); DOUBLES_EQUAL(0.565685, viewDir.getY(), 0.0001); DOUBLES_EQUAL(0.707106, viewDir.getZ(), 0.0001); }
TEST(Matrix, shouldHaveFourComponentVectorConstructor) { Matrix m(1, 2, 3, 4); DOUBLES_EQUAL(1.0, m.get(0), 0.0001); DOUBLES_EQUAL(2.0, m.get(1), 0.0001); DOUBLES_EQUAL(3.0, m.get(2), 0.0001); DOUBLES_EQUAL(4.0, m.get(3), 0.0001); }
TEST(Matrix, shouldProvideVectorGet) { Matrix m(1.0, 2.0, 4.0, 3.0); DOUBLES_EQUAL(1.0, m.get(0), 0.0001); DOUBLES_EQUAL(2.0, m.get(1), 0.0001); DOUBLES_EQUAL(4.0, m.get(2), 0.0001); DOUBLES_EQUAL(3.0, m.get(3), 0.0001); }
TEST(Matrix, shouldProvideAbsFunction) { Matrix m1(1, -2, -4); Matrix m2 = m1.abs(); DOUBLES_EQUAL(1, m2.get(0), 0.0001); DOUBLES_EQUAL(2, m2.get(1), 0.0001); DOUBLES_EQUAL(4, m2.get(2), 0.0001); }
TEST(Matrix, shouldProvideDivide) { Matrix m1(1, 2, 3); Matrix m2(2, 2, 3); Matrix m3 = m1 / m2; DOUBLES_EQUAL(0.5f, m3.get(0), 0.0001); DOUBLES_EQUAL(1, m3.get(1), 0.0001); DOUBLES_EQUAL(1, m3.get(2), 0.0001); }
TEST(Matrix, shouldHaveAVectorContructor) { float v[3] = { 1,2,3 }; Matrix m(v); CHECK_EQUAL(3, m.getM()); CHECK_EQUAL(1, m.getN()); DOUBLES_EQUAL(1, m.get(0), 0.0001); DOUBLES_EQUAL(2, m.get(1), 0.0001); DOUBLES_EQUAL(3, m.get(2), 0.0001); }
TEST(Matrix, shouldSubtractTwoMatrices) { Matrix m1(2, 2, 3); Matrix m2(1, 1, 1); Matrix r = m1 - m2; DOUBLES_EQUAL(1, r.get(0), 0.0001); DOUBLES_EQUAL(1, r.get(1), 0.0001); DOUBLES_EQUAL(2, r.get(2), 0.0001); }
TEST(Matrix, shouldNormalize) { Matrix m(1, 2, 3); m.normalize(); float L = 3.741657387f; DOUBLES_EQUAL(1.0/L, m.get(0), 0.0001); DOUBLES_EQUAL(2.0/L, m.get(1), 0.0001); DOUBLES_EQUAL(3.0/L, m.get(2), 0.0001); }
TEST(RayTracer, can_compute_ray) { RayTracer r(2, 2, Vect(0, 0, -1), Vect(0, 1, 0)); Ray r0 = r.computeRay(0, 0); Vect ctr = r0.getOrigin(); CHECK_EQUAL(0, ctr.getX()); CHECK_EQUAL(0, ctr.getY()); CHECK_EQUAL(0, ctr.getZ()); Vect dir = r0.getDirection(); DOUBLES_EQUAL(-0.408248, dir.getX(), 0.00001); DOUBLES_EQUAL(-0.408248, dir.getY(), 0.00001); DOUBLES_EQUAL(-0.816497, dir.getZ(), 0.00001); }
TEST(MatrixTest, should_add_linearly) { float as[4] = {0.0f, 1.0f, 2.0f, 3.0f}; Matrix *a = new Matrix(2, 2, as); Matrix *b = new Matrix(2, 2, as); Matrix c = a[0] + b[0]; DOUBLES_EQUAL(0.0f,c.getCell(0, 0), 0.001); DOUBLES_EQUAL(2.0f,c.getCell(0, 1), 0.001); DOUBLES_EQUAL(4.0f,c.getCell(1, 0), 0.001); DOUBLES_EQUAL(6.0f,c.getCell(1, 1), 0.001); delete a; delete b; }
TEST(MatrixTest, can_assign) { Matrix a(2, 2); a.setCell(0, 0, 0); a.setCell(0, 1, 1); a.setCell(1, 0, 2); a.setCell(1, 1, 3); Matrix c = a; DOUBLES_EQUAL(0.0f, c.getCell(0, 0), 0.001); DOUBLES_EQUAL(1.0f, c.getCell(0, 1), 0.001); DOUBLES_EQUAL(2.0f, c.getCell(1, 0), 0.001); DOUBLES_EQUAL(3.0f, c.getCell(1, 1), 0.001); }
TEST(MatrixTest, shoud_set_cell) { Matrix *a = new Matrix(2, 2); a->setCell(0, 0, 0); a->setCell(0, 1, 1); a->setCell(1, 0, 2); a->setCell(1, 1, 3); DOUBLES_EQUAL(0.0f, a->getCell(0, 0), 0.001); DOUBLES_EQUAL(1.0f, a->getCell(0, 1), 0.001); DOUBLES_EQUAL(2.0f, a->getCell(1, 0), 0.001); DOUBLES_EQUAL(3.0f, a->getCell(1, 1), 0.001); delete a; }
TEST(Mesh, shouldComputeBoundingBox) { Mesh *m = new MeshMock(values, 2, 2); BoundingBox box = m->getBoundingBox(); DOUBLES_EQUAL(-1, box.getX(), 0.0001); DOUBLES_EQUAL(-3, box.getY(), 0.0001); DOUBLES_EQUAL(3, box.getDX(), 0.0001); DOUBLES_EQUAL(5, box.getDY(), 0.0001); delete m; }
TEST(RayTracer, can_add_camera) { Camera cam; cam.setPos(Vect(10, 10, 10)); cam.setViewDir(Vect(-1, -1, -1)); cam.setOrthoUp(Vect(1, 1, 0)); cam.setVerticalFOV((float)M_PI / 2.0f); RayTracer rt(50, 50); rt.setCamera(cam); Camera c0 = rt.getCamera(); CHECK_EQUAL(10, c0.getX()); DOUBLES_EQUAL(-1/sqrt(3), c0.getViewDir().getZ(), 0.00001); DOUBLES_EQUAL(1/sqrt(2), c0.getOrthoUp().getX(), 0.00001); DOUBLES_EQUAL(1/sqrt(2), c0.getOrthoUp().getY(), 0.00001); DOUBLES_EQUAL((float)M_PI / 2.0f, cam.getVerticalFOV(), 0.000001); }
static int functionThatReturnsAValue() { CHECK(0 == 0); CHECK_TEXT(0 == 0, "Shouldn't fail"); CHECK_TRUE(0 == 0); CHECK_TRUE_TEXT(0 == 0, "Shouldn't fail"); CHECK_FALSE(0 != 0); CHECK_FALSE_TEXT(0 != 0, "Shouldn't fail"); LONGS_EQUAL(1,1); LONGS_EQUAL_TEXT(1, 1, "Shouldn't fail"); BYTES_EQUAL(0xab,0xab); BYTES_EQUAL_TEXT(0xab, 0xab, "Shouldn't fail"); CHECK_EQUAL(100,100); CHECK_EQUAL_TEXT(100, 100, "Shouldn't fail"); STRCMP_EQUAL("THIS", "THIS"); STRCMP_EQUAL_TEXT("THIS", "THIS", "Shouldn't fail"); DOUBLES_EQUAL(1.0, 1.0, .01); DOUBLES_EQUAL_TEXT(1.0, 1.0, .01, "Shouldn't fail"); POINTERS_EQUAL(0, 0); POINTERS_EQUAL_TEXT(0, 0, "Shouldn't fail"); MEMCMP_EQUAL("THIS", "THIS", 5); MEMCMP_EQUAL_TEXT("THIS", "THIS", 5, "Shouldn't fail"); BITS_EQUAL(0x01, (unsigned char )0x01, 0xFF); BITS_EQUAL(0x0001, (unsigned short )0x0001, 0xFFFF); BITS_EQUAL(0x00000001, (unsigned long )0x00000001, 0xFFFFFFFF); BITS_EQUAL_TEXT(0x01, (unsigned char )0x01, 0xFF, "Shouldn't fail"); return 0; }
TEST(Matrix, shouldSetAndGetValues) { Matrix m(4); m.set(0, 0, 1.0); DOUBLES_EQUAL(1.0, m.get(0, 0), 0.0001); }
TEST(Vector, shouldComputeLength) { Vector v( 3, 3, 2 ); DOUBLES_EQUAL( 4.69041576, v.length(), 0.0001 ); }
TEST(Matrix, shouldSetAndGetValuesOfRowVector) { Matrix m(1,2,3,4); m.set(3, 10); DOUBLES_EQUAL(10, m.get(3), 0.0001); }
TEST(Vector, shouldProvideDotProduct) { Vector v1(5, 4, 2); Vector v2(1, 3, 4); DOUBLES_EQUAL( ((5*1)+(4*3)+(2*4)), v1.dot(v2), 0.0001 ); }