#include "config.h"
#include "lfptest.h"
#include "timevalops.h"
#include "unity.h"
#include <math.h>
void test_Seconds(void);
void test_MicrosecondsRounded(void);
void test_MicrosecondsExact(void);
void
test_Seconds(void)
{
struct timeval input = {500, 0};
l_fp expected = {{500}, 0};
l_fp actual;
TVTOTS(&input, &actual);
TEST_ASSERT_TRUE(IsEqual(expected, actual));
}
void
test_MicrosecondsRounded(void)
{
struct timeval input = {0, 500};
l_fp expected = {{0}, HALF_PROMILLE_UP};
l_fp actual;
TVTOTS(&input, &actual);
TEST_ASSERT_TRUE(IsEqual(expected, actual));
}
void
test_MicrosecondsExact(void)
{
const struct timeval input = {10, 500000};
const l_fp expected = {{10}, HALF};
l_fp actual;
TVTOTS(&input, &actual);
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);
TEST_ASSERT_DOUBLE_WITHIN(0.0000005, expectedDouble, actualDouble);
}