TEST(vector_operations, Vect_write_should_change_only_value_index){ vect->v[0] = 4.0; vect->v[1] = 4.0; vect->v[2] = 4.0; Vect_write(vect, 1, 2.0); TEST_ASSERT_EQUAL_DOUBLE(2.0, vect->v[0]); TEST_ASSERT_EQUAL_DOUBLE(4.0, vect->v[1]); TEST_ASSERT_EQUAL_DOUBLE(4.0, vect->v[2]); }
TEST(vector_operations, Vect_multiply_with_const_should_work){ uint8_t i; for(i=1; i < 10; i++){ Vect_set_all_values_to(vect, 0); Vect_set_all_values_to(vect_1, 0); Vect_write_three_values(vect, 1.0, 2.0, 3.0); Vect_times_const(vect, (_FLOAT_)i, vect_1); TEST_ASSERT_EQUAL_DOUBLE(1.0 * (_FLOAT_)i, Vect_read(vect_1, 1)); TEST_ASSERT_EQUAL_DOUBLE(2.0 * (_FLOAT_)i, Vect_read(vect_1, 2)); TEST_ASSERT_EQUAL_DOUBLE(3.0 * (_FLOAT_)i, Vect_read(vect_1, 3)); } }
TEST(vector_operations, Vect_write_three_values_should_work){ uint8_t i; uint8_t j; uint8_t k; for(i = 0; i <= 5; i++){ for(j = 0; j <= 5; j++){ for(k = 0; k <= 5; k++){ Vect_write_three_values(vect, (_FLOAT_)i,(_FLOAT_)j,(_FLOAT_)k); TEST_ASSERT_EQUAL_DOUBLE((_FLOAT_)i, Vect_read(vect, 1)); TEST_ASSERT_EQUAL_DOUBLE((_FLOAT_)j, Vect_read(vect, 2)); TEST_ASSERT_EQUAL_DOUBLE((_FLOAT_)k, Vect_read(vect, 3)); } } } }
TEST(vector_operations, Vect_length_should_return_one_with_vector_magnitude_1){ uint8_t i; for(i=1; i<=3; i++){ Vect_set_all_values_to(vect, 0.0); Vect_write(vect, i, 1.0); printf("vect: %f \n", Vect_length(vect)); TEST_ASSERT_EQUAL_DOUBLE(1.0, Vect_length(vect)); } }
void test_OffsetCalculationPositiveOffset(void) { struct pkt rpkt; rpkt.precision = -16; // 0,000015259 rpkt.rootdelay = HTONS_FP(DTOUFP(0.125)); rpkt.rootdisp = HTONS_FP(DTOUFP(0.25)); // Synch Distance: (0.125+0.25)/2.0 == 0.1875 l_fp reftime; get_systime(&reftime); HTONL_FP(&reftime, &rpkt.reftime); l_fp tmp; // T1 - Originate timestamp tmp.l_ui = 1000000000UL; tmp.l_uf = 0UL; HTONL_FP(&tmp, &rpkt.org); // T2 - Receive timestamp tmp.l_ui = 1000000001UL; tmp.l_uf = 2147483648UL; HTONL_FP(&tmp, &rpkt.rec); // T3 - Transmit timestamp tmp.l_ui = 1000000002UL; tmp.l_uf = 0UL; HTONL_FP(&tmp, &rpkt.xmt); // T4 - Destination timestamp as standard timeval tmp.l_ui = 1000000001UL; tmp.l_uf = 0UL; struct timeval dst; TSTOTV(&tmp, &dst); dst.tv_sec -= JAN_1970; double offset, precision, synch_distance; offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance); TEST_ASSERT_EQUAL_DOUBLE(1.25, offset); TEST_ASSERT_EQUAL_DOUBLE(1. / ULOGTOD(16), precision); // 1.1250150000000001 ? TEST_ASSERT_EQUAL_DOUBLE(1.125015, synch_distance); }
void test_OffsetCalculationNegativeOffset(void) { struct pkt rpkt; l_fp reftime, tmp; struct timeval dst; double offset, precision, synch_distance; rpkt.precision = -1; rpkt.rootdelay = HTONS_FP(DTOUFP(0.5)); rpkt.rootdisp = HTONS_FP(DTOUFP(0.5)); /* Synch Distance is (0.5+0.5)/2.0, or 0.5 */ get_systime(&reftime); HTONL_FP(&reftime, &rpkt.reftime); /* T1 - Originate timestamp */ tmp.l_ui = 1000000001UL; tmp.l_uf = 0UL; HTONL_FP(&tmp, &rpkt.org); /* T2 - Receive timestamp */ tmp.l_ui = 1000000000UL; tmp.l_uf = 2147483648UL; HTONL_FP(&tmp, &rpkt.rec); /*/ T3 - Transmit timestamp */ tmp.l_ui = 1000000001UL; tmp.l_uf = 2147483648UL; HTONL_FP(&tmp, &rpkt.xmt); /* T4 - Destination timestamp as standard timeval */ tmp.l_ui = 1000000003UL; tmp.l_uf = 0UL; TSTOTV(&tmp, &dst); dst.tv_sec -= JAN_1970; offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance); TEST_ASSERT_EQUAL_DOUBLE(-1, offset); TEST_ASSERT_EQUAL_DOUBLE(1. / ULOGTOD(1), precision); TEST_ASSERT_EQUAL_DOUBLE(1.3333483333333334, synch_distance); }
TEST(vector_operations, Vect_add_should_add_first_component){ uint8_t i; for(i = 0; i < 10; i++){ Vect_write(vect_1, 1, (_FLOAT_)(i)); Vect_write(vect_2, 1, (_FLOAT_)(i)); Vect_add(vect_1, vect_2, vect); TEST_ASSERT_EQUAL_DOUBLE((_FLOAT_)2*i, Vect_read(vect,1)); } }
static void cjson_add_number_should_add_number(void) { cJSON *root = cJSON_CreateObject(); cJSON *number = NULL; cJSON_AddNumberToObject(root, "number", 42); TEST_ASSERT_NOT_NULL(number = cJSON_GetObjectItemCaseSensitive(root, "number")); TEST_ASSERT_EQUAL_INT(number->type, cJSON_Number); TEST_ASSERT_EQUAL_DOUBLE(number->valuedouble, 42); TEST_ASSERT_EQUAL_INT(number->valueint, 42); cJSON_Delete(root); }
TEST(vector_operations, Vect_cross_multiply_index_3_should_follow_rule){ _FLOAT_ i; _FLOAT_ j; _FLOAT_ k; _FLOAT_ l; for(i = 0.0; i <= 6.0; i = i+1.0){ for(j = 0.0; j <= 6.0; j = j+1.0){ k = i+1; l = j+1; Vect_set_all_values_to(vect, 0); Vect_write_three_values(vect_1, i, j, 0); Vect_write_three_values(vect_2, k, l, 0); Vect_cross_multiply(vect_1, vect_2, vect); TEST_ASSERT_EQUAL_DOUBLE(Vect_read(vect, 3), i*l - k*j); } } }
TEST(vector_operations, Vect_write_at_y_index_should){ vect->v[2]= 0; Vect_write(vect, 3, 2.0); TEST_ASSERT_EQUAL_DOUBLE(2.0, Vect_read(vect, 3)); }
TEST(vector_operations, Vect_write_at_x_index_should_work){ vect->v[0] = 0; Vect_write(vect, 1, 1.0); TEST_ASSERT_EQUAL_DOUBLE(1.0, Vect_read(vect, 1)); }
_STATIC_ void Test_vect_values_equal_to(Vector_t *vect, _FLOAT_ value){ TEST_ASSERT_EQUAL_DOUBLE(value , vect->v[0]); TEST_ASSERT_EQUAL_DOUBLE(value , vect->v[1]); TEST_ASSERT_EQUAL_DOUBLE(value , vect->v[2]); }
TEST(vector_operations, Vect_length_should_return_5_with_components_3_and_4){ Vect_write(vect, 1, 3.0); Vect_write(vect, 2, 4.0); TEST_ASSERT_EQUAL_DOUBLE(5.00, Vect_length(vect)); }