Esempio n. 1
0
void
test_IntegerAndFractionalBuffer(void)
{
#ifndef SYS_WINNT
	const struct timeval input = {5, 500000}; /* 5.5 */
	const l_fp expected = {{5 + JAN_1970}, HALF};
	double expectedDouble, actualDouble;
	l_fp actual;

	TEST_ASSERT_TRUE(buftvtots((const char*)(&input), &actual));

	/* Compare the fractional part with an absolute error given. */
	TEST_ASSERT_EQUAL(expected.l_ui, actual.l_ui);

	M_LFPTOD(0, expected.l_uf, expectedDouble);
	M_LFPTOD(0, actual.l_uf, actualDouble);

	/* The error should be less than 0.5 us */
	TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
#else
	TEST_IGNORE_MESSAGE("Test only for Windows, skipping...");
#endif

	return;
}
Esempio n. 2
0
void
test_MicrosecondsExact(void)
{
	/* 0.5 can be represented exact in both l_fp and timeval. */
	const struct timeval input = {10, 500000}; /* 0.5 exact */
	const l_fp expected = {{10}, HALF};        /* 0.5 exact */
	l_fp actual;

	TVTOTS(&input, &actual);

	/* Compare the fractional part with an absolute error given. */
	TEST_ASSERT_EQUAL_UINT(expected.l_ui, actual.l_ui);

	double expectedDouble, actualDouble;
	M_LFPTOD(0, expected.l_uf, expectedDouble);
	M_LFPTOD(0, actual.l_uf, actualDouble);

	/* The error should be less than 0.5 us */
	TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
}
Esempio n. 3
0
//----------------------------------------------------------------------
// fp -> double -> fp rountrip test
//----------------------------------------------------------------------
void
test_FDF_RoundTrip(void)
{
	size_t idx = 0;

	// since a l_fp has 64 bits in it's mantissa and a double has
	// only 54 bits available (including the hidden '1') we have to
	// make a few concessions on the roundtrip precision. The 'eps()'
	// function makes an educated guess about the avilable precision
	// and checks the difference in the two 'l_fp' values against
	// that limit.

	for (idx = 0; idx < addsub_cnt; ++idx) {
		l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
		double op2 = l_fp_convert_to_double(op1);
		l_fp op3 = l_fp_init_from_double(op2); 

		l_fp temp = l_fp_subtract(op1, op3);
		double d = l_fp_convert_to_double(temp);
		TEST_ASSERT_DOUBLE_WITHIN(eps(op2), 0.0, fabs(d));
	}

	return;
}
TEST(vector_operations, Vect_length_should_return_1_with_each_component_sqrt_3){
    _FLOAT_ sqrt_val = 1/sqrt(3);
    Vect_set_all_values_to(vect, sqrt_val);
    TEST_ASSERT_DOUBLE_WITHIN(0.000001, 1.0, Vect_length(vect));
}
TEST(vector_operations, Vect_uniform_should_return_a_vector_with_length_1){
    Vect_set_all_values_to(vect_1, 5.0);
    Vect_uniform(vect_1, vect);
    TEST_ASSERT_DOUBLE_WITHIN(0.000001, 1.0, Vect_length(vect));
}