test_blendmath.c
1 #include "tp_debug.h" 2 #include "greatest.h" 3 #include "blendmath.h" 4 #include "tp_types.h" 5 #include "math.h" 6 #include "rtapi.h" 7 8 /* Expand to all the definitions that need to be in 9 the test runner's main file. */ 10 GREATEST_MAIN_DEFS(); 11 12 // KLUDGE fix link error the ugly way 13 void rtapi_print_msg(msg_level_t level, const char *fmt, ...) 14 { 15 va_list args; 16 17 va_start(args, fmt); 18 printf(fmt, args); 19 va_end(args); 20 } 21 22 TEST pmCartCartParallel_numerical() { 23 24 PmCartesian u0 = {1,0,0}; 25 PmCartesian u_close = {cos(TP_ANGLE_EPSILON), sin(TP_ANGLE_EPSILON), 0}; 26 27 ASSERT(pmCartCartParallel(&u0, &u0, TP_ANGLE_EPSILON_SQ)); 28 ASSERT_FALSE(pmCartCartParallel(&u0, &u_close, 0.0)); 29 30 // Test that the tolerance makes sense 31 ASSERT_FALSE(pmCartCartParallel(&u0, &u_close, 0.5*TP_ANGLE_EPSILON_SQ)); 32 ASSERT(pmCartCartParallel(&u0, &u_close, 1.5*TP_ANGLE_EPSILON_SQ)); 33 34 // Try a bunch of other angles including anti-parallel 35 for (double k=1; k <= 7; ++k) { 36 PmCartesian u_far = {cos(PM_PI_4 * k), sin(PM_PI_4 * k), 0}; 37 ASSERT_FALSE(pmCartCartParallel(&u0, &u_far, TP_ANGLE_EPSILON_SQ)); 38 } 39 40 PASS(); 41 } 42 43 TEST pmCartCartAntiParallel_numerical() { 44 45 PmCartesian u0 = {1,0,0}; 46 PmCartesian u_close = {-cos(TP_ANGLE_EPSILON), sin(TP_ANGLE_EPSILON), 0}; 47 48 PmCartesian u_opposite; 49 pmCartScalMult(&u0, -1.0, &u_opposite); 50 ASSERT(pmCartCartAntiParallel(&u0, &u_opposite, TP_ANGLE_EPSILON_SQ)); 51 ASSERT_FALSE(pmCartCartAntiParallel(&u0, &u_close, 0.0)); 52 53 // Test that the tolerance makes sense 54 ASSERT_FALSE(pmCartCartAntiParallel(&u0, &u_close, 0.5*TP_ANGLE_EPSILON_SQ)); 55 ASSERT(pmCartCartAntiParallel(&u0, &u_close, 1.5*TP_ANGLE_EPSILON_SQ)); 56 57 // Try a bunch of other angles including anti-parallel 58 for (double k=1; k <= 7; ++k) { 59 PmCartesian u_far = {-cos(PM_PI_4 * k), sin(PM_PI_4 * k), 0}; 60 ASSERT_FALSE(pmCartCartAntiParallel(&u0, &u_far, TP_ANGLE_EPSILON_SQ)); 61 } 62 63 PASS(); 64 } 65 66 67 SUITE(blendmath) { 68 RUN_TEST(pmCartCartParallel_numerical); 69 RUN_TEST(pmCartCartAntiParallel_numerical); 70 71 } 72 73 int main(int argc, char **argv) { 74 GREATEST_MAIN_BEGIN(); /* command-line arguments, initialization. */ 75 RUN_SUITE(blendmath); /* run a suite */ 76 GREATEST_MAIN_END(); /* display results */ 77 }