1#include "../Inc/Utils/LUT.h"
12 const float SEA_LEVEL_PRESSURE_MB = 1013.25;
14 float result = pow(pressure_mb / SEA_LEVEL_PRESSURE_MB, 1 / 5.255);
15 return 44330 * (1 - result);
21 TEST(uninitialized_table, {
23 "table is initialized");
29 "cannot sample outside of domain (0 mb)",
30 "can sample outside of domain (0 mb)");
32 "can sample outside of domain (300 mb)");
42 TEST(initialized_table, {
44 "table is uninitialized");
48 "min is first point in table",
"min is not first point in table");
52 "max is last point in table",
"max is not last point in table");
54 "cannot sample outside of domain (0 mb)",
55 "can sample outside of domain (0 mb)");
57 "cannot sample outside of domain (300 mb)");
64 float min_reference_pressure_mb = 300;
65 float max_reference_pressure_mb = 1100;
66 float min_reference_altitude_m =
68 float max_reference_altitude_m =
70 float altitude_m = 0.0;
72 TEST(sampling_min_reference_point, {
74 ASSERT_EQ(altitude_m, min_reference_altitude_m,
"altitude",
75 "reference altitude");
78 TEST(sampling_max_reference_point, {
80 ASSERT_EQ(altitude_m, max_reference_altitude_m,
"altitude",
81 "reference altitude");
88 float reference_pressure_mb = 600;
90 float altitude_m = 0.0;
92 TEST(sampling_reference_point, {
94 ASSERT_EQ(altitude_m, reference_altitude_m,
"altitude",
95 "reference altitude");
102 float pressure_mb = 650;
104 float altitude_m = 0.0;
106 TEST(sampling_unknown_point, {
108 float percent_error =
109 (altitude_m - expected_altitude_m) / expected_altitude_m * 100;
111 "expected altitude");
116 table pressure_mb_to_altitude_m;
117 assert(
table_init(&pressure_mb_to_altitude_m, 9));
123 for (
unsigned int reference_pressure_mb = 300; reference_pressure_mb <= 1100;
124 reference_pressure_mb += 100) {
126 &pressure_mb_to_altitude_m, reference_pressure_mb,
bool table_is_initialized(table *table)
Checks if the table has been fully initialized, with all reference points added.
bool table_sample(table *table, float in, float *out)
Samples a output value from the table for an input value.
bool table_init(table *table, uint16_t count)
Initializes the table.
const point * table_min_point(table *table)
Retrieves the point in the table with the least input value.
bool table_can_sample(table *table, float in)
Checks if the input input is valid for the table.
const point * table_max_point(table *table)
Retrieves the point in the table with the greatest input value.
bool table_add_reference_point(table *table, float in, float out)
Adds a reference point to the table.
void test_sampling_reference_point(table *table)
void test_uninitialized_table(table *table)
void test_sampling_endpoints(table *table)
void test_initialized_table(table *table)
float altitude_m_at_pressure_mb(float pressure_mb)
void test_sampling_unknown_point(table *table)
point points_[TABLE_CAPACITY]
#define ASSERT_OK(BOOL, LABEL)
#define ASSERT_IN_ERROR(GOT, WANT, GOT_LABEL, WANT_LABEL)
#define ASSERT_EQ(GOT, WANT, GOT_LABEL, WANT_LABEL)
#define ASSERT(BOOL, OK, ERR)