00001
00002 #include <check.h>
00003 #include <stdio.h>
00004 #include "single_diff.h"
00005
00006 navigation_measurement_t nm1 = {.prn = 1};
00007 navigation_measurement_t nm2 = {.prn = 2};
00008 navigation_measurement_t nm3 = {.prn = 3};
00009 navigation_measurement_t nm4 = {.prn = 4};
00010
00011 navigation_measurement_t nms_no_match1[2];
00012 navigation_measurement_t nms_no_match2[2];
00013
00014 START_TEST(test_no_match)
00015 {
00016 sdiff_t sds_out[6];
00017
00018
00019 memcpy(&nms_no_match1[0], &nm1, sizeof(navigation_measurement_t));
00020 memcpy(&nms_no_match2[0], &nm2, sizeof(navigation_measurement_t));
00021 memcpy(&nms_no_match1[1], &nm3, sizeof(navigation_measurement_t));
00022 memcpy(&nms_no_match2[1], &nm4, sizeof(navigation_measurement_t));
00023
00024 u8 num_match = single_diff(2, nms_no_match1,
00025 2, nms_no_match2,
00026 sds_out);
00027
00028 fail_unless(num_match == 0);
00029
00030
00031 memcpy(&nms_no_match1[0], &nm1, sizeof(navigation_measurement_t));
00032 memcpy(&nms_no_match1[1], &nm2, sizeof(navigation_measurement_t));
00033 memcpy(&nms_no_match2[0], &nm3, sizeof(navigation_measurement_t));
00034 memcpy(&nms_no_match2[1], &nm4, sizeof(navigation_measurement_t));
00035
00036 num_match = single_diff(2, nms_no_match1,
00037 2, nms_no_match2,
00038 sds_out);
00039
00040 fail_unless(num_match == 0);
00041
00042
00043 memcpy(&nms_no_match2[0], &nm1, sizeof(navigation_measurement_t));
00044 memcpy(&nms_no_match2[1], &nm2, sizeof(navigation_measurement_t));
00045 memcpy(&nms_no_match1[0], &nm3, sizeof(navigation_measurement_t));
00046 memcpy(&nms_no_match1[1], &nm4, sizeof(navigation_measurement_t));
00047
00048 num_match = single_diff(2, nms_no_match1,
00049 2, nms_no_match2,
00050 sds_out);
00051
00052 fail_unless(num_match == 0);
00053 }
00054 END_TEST
00055
00056 START_TEST(test_beginning_matches)
00057 {
00058 sdiff_t sds_out[3];
00059
00060
00061 memcpy(&nms_no_match1[0], &nm1, sizeof(navigation_measurement_t));
00062 memcpy(&nms_no_match1[1], &nm2, sizeof(navigation_measurement_t));
00063 memcpy(&nms_no_match2[0], &nm1, sizeof(navigation_measurement_t));
00064 memcpy(&nms_no_match2[1], &nm3, sizeof(navigation_measurement_t));
00065
00066 u8 num_match = single_diff(2, nms_no_match1,
00067 2, nms_no_match2,
00068 sds_out);
00069
00070 fail_unless(num_match == 1);
00071 fail_unless(sds_out[0].prn == 1);
00072
00073
00074 memcpy(&nms_no_match1[0], &nm1, sizeof(navigation_measurement_t));
00075 memcpy(&nms_no_match1[1], &nm3, sizeof(navigation_measurement_t));
00076 memcpy(&nms_no_match2[0], &nm1, sizeof(navigation_measurement_t));
00077 memcpy(&nms_no_match2[1], &nm2, sizeof(navigation_measurement_t));
00078
00079 num_match = single_diff(2, nms_no_match1,
00080 2, nms_no_match2,
00081 sds_out);
00082
00083 fail_unless(num_match == 1);
00084 fail_unless(sds_out[0].prn == 1);
00085
00086
00087 memcpy(&nms_no_match1[0], &nm1, sizeof(navigation_measurement_t));
00088 memcpy(&nms_no_match2[0], &nm1, sizeof(navigation_measurement_t));
00089 memcpy(&nms_no_match2[1], &nm2, sizeof(navigation_measurement_t));
00090
00091 num_match = single_diff(1, nms_no_match1,
00092 2, nms_no_match2,
00093 sds_out);
00094
00095 fail_unless(num_match == 1);
00096 fail_unless(sds_out[0].prn == 1);
00097
00098
00099 memcpy(&nms_no_match1[0], &nm1, sizeof(navigation_measurement_t));
00100 memcpy(&nms_no_match1[1], &nm2, sizeof(navigation_measurement_t));
00101 memcpy(&nms_no_match2[0], &nm1, sizeof(navigation_measurement_t));
00102
00103 num_match = single_diff(2, nms_no_match1,
00104 1, nms_no_match2,
00105 sds_out);
00106
00107 fail_unless(num_match == 1);
00108 fail_unless(sds_out[0].prn == 1);
00109 }
00110 END_TEST
00111
00112 START_TEST(test_end_matches)
00113 {
00114 sdiff_t sds_out[3];
00115
00116
00117 memcpy(&nms_no_match1[0], &nm1, sizeof(navigation_measurement_t));
00118 memcpy(&nms_no_match1[1], &nm3, sizeof(navigation_measurement_t));
00119 memcpy(&nms_no_match2[0], &nm2, sizeof(navigation_measurement_t));
00120 memcpy(&nms_no_match2[1], &nm3, sizeof(navigation_measurement_t));
00121
00122 u8 num_match = single_diff(2, nms_no_match1,
00123 2, nms_no_match2,
00124 sds_out);
00125
00126 fail_unless(num_match == 1);
00127 fail_unless(sds_out[0].prn == 3);
00128
00129
00130 memcpy(&nms_no_match1[0], &nm2, sizeof(navigation_measurement_t));
00131 memcpy(&nms_no_match1[1], &nm3, sizeof(navigation_measurement_t));
00132 memcpy(&nms_no_match2[0], &nm1, sizeof(navigation_measurement_t));
00133 memcpy(&nms_no_match2[1], &nm3, sizeof(navigation_measurement_t));
00134
00135 num_match = single_diff(2, nms_no_match1,
00136 2, nms_no_match2,
00137 sds_out);
00138
00139 fail_unless(num_match == 1);
00140 fail_unless(sds_out[0].prn == 3);
00141
00142
00143 memcpy(&nms_no_match1[0], &nm2, sizeof(navigation_measurement_t));
00144 memcpy(&nms_no_match2[0], &nm1, sizeof(navigation_measurement_t));
00145 memcpy(&nms_no_match2[1], &nm2, sizeof(navigation_measurement_t));
00146
00147 num_match = single_diff(1, nms_no_match1,
00148 2, nms_no_match2,
00149 sds_out);
00150
00151 fail_unless(num_match == 1);
00152 fail_unless(sds_out[0].prn == 2);
00153
00154
00155 memcpy(&nms_no_match1[0], &nm1, sizeof(navigation_measurement_t));
00156 memcpy(&nms_no_match1[1], &nm2, sizeof(navigation_measurement_t));
00157 memcpy(&nms_no_match2[0], &nm2, sizeof(navigation_measurement_t));
00158
00159 num_match = single_diff(2, nms_no_match1,
00160 1, nms_no_match2,
00161 sds_out);
00162
00163 fail_unless(num_match == 1);
00164 fail_unless(sds_out[0].prn == 2);
00165 }
00166 END_TEST
00167
00168
00169 Suite* sdiff_test_suite(void)
00170 {
00171 Suite *s = suite_create("Single Differences");
00172
00173 TCase *tc_core = tcase_create("Core");
00174 tcase_add_test(tc_core, test_no_match);
00175 tcase_add_test(tc_core, test_beginning_matches);
00176 tcase_add_test(tc_core, test_end_matches);
00177 suite_add_tcase(s, tc_core);
00178
00179 return s;
00180 }
00181