1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "config.h"
#include "ntp_stdlib.h"
#include "ntp_calendar.h"
#include "unity.h"
#include "lfptest.h"
void test_PositiveInteger(void);
void test_NegativeInteger(void);
void test_PositiveFraction(void);
void test_NegativeFraction(void);
void test_IllegalNumberOfInteger(void);
void test_IllegalChar(void);
void
test_PositiveInteger(void) {
const char *str = "00001000.00000000";
l_fp actual;
l_fp expected = {{4096}, 0}; /* 16^3, no fraction part. */
TEST_ASSERT_TRUE(hextolfp(str, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
}
void
test_NegativeInteger(void) {
const char *str = "ffffffff.00000000"; /* -1 decimal */
l_fp actual;
l_fp expected = {{-1}, 0};
TEST_ASSERT_TRUE(hextolfp(str, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
}
void
test_PositiveFraction(void) {
const char *str = "00002000.80000000"; /* 8196.5 decimal */
l_fp actual;
l_fp expected = {{8192}, HALF};
TEST_ASSERT_TRUE(hextolfp(str, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
}
void
test_NegativeFraction(void) {
const char *str = "ffffffff.40000000"; /* -1 + 0.25 decimal */
l_fp actual;
l_fp expected = {{-1}, QUARTER}; /* -1 + 0.25 */
TEST_ASSERT_TRUE(hextolfp(str, &actual));
TEST_ASSERT_TRUE(IsEqual(expected, actual));
}
void
test_IllegalNumberOfInteger(void) {
const char *str = "1000000.00000000"; /* Missing one digit in integral part. */
l_fp actual;
TEST_ASSERT_FALSE(hextolfp(str, &actual));
}
void
test_IllegalChar(void) {
const char *str = "10000000.0000h000"; /* Illegal character h. */
l_fp actual;
TEST_ASSERT_FALSE(hextolfp(str, &actual));
}
|