check_ambiguity_test.c
Go to the documentation of this file.
00001 
00002 #include <check.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <math.h>
00006 
00007 #include <ambiguity_test.h>
00008 
00009 #include "check_utils.h"
00010 
00011 
00012 // assure that when the sdiffs match amb_test's sats, amb_test's sats are unchanged
00013 START_TEST(test_update_sats_same_sats)
00014 {
00015   ambiguity_test_t amb_test = {.sats = {.num_sats = 4,
00016                                         .prns = {3,1,2,4}}};
00017   sdiff_t sdiffs[4] = {{.prn = 1},
00018                        {.prn = 2},
00019                        {.prn = 3},
00020                        {.prn = 4}};
00021   u8 num_sdiffs = 4;
00022 
00023   ambiguity_update_sats(&amb_test, num_sdiffs, sdiffs, NULL, NULL, NULL, NULL);
00024 
00025   fail_unless(amb_test.sats.prns[0] == 3);
00026   fail_unless(amb_test.sats.prns[1] == 1);
00027   fail_unless(amb_test.sats.prns[2] == 2);
00028   fail_unless(amb_test.sats.prns[3] == 4);
00029 }
00030 END_TEST
00031 
00032 //assure that when we've lost the reference, we choose a new one and rebase everything
00033 START_TEST(test_update_sats_rebase)
00034 {
00035   ambiguity_test_t amb_test;
00036   create_ambiguity_test(&amb_test);
00037 
00038   amb_test.sats.num_sats = 4;
00039   amb_test.sats.prns[0] = 3;
00040   amb_test.sats.prns[1] = 1;
00041   amb_test.sats.prns[2] = 2;
00042   amb_test.sats.prns[3] = 4;
00043 
00044   sdiff_t sdiffs[3] = {{.prn = 1, .snr = 0},
00045                        {.prn = 2, .snr = 0}, 
00046                       // {.prn = 3, .snr = 0}, 
00047                        {.prn = 4, .snr = 1}};
00048   u8 num_sdiffs = 3;
00049   
00050   hypothesis_t *hyp = (hypothesis_t *)memory_pool_add(amb_test.pool);
00051   hyp->N[0] = 0;
00052   hyp->N[1] = 1;
00053   hyp->N[2] = 2;
00054 
00055   sats_management_t float_sats = {.num_sats = 3};
00056 
00057   ambiguity_update_sats(&amb_test, num_sdiffs, sdiffs, &float_sats, NULL, NULL, NULL);
00058   fail_unless(amb_test.sats.num_sats == 3);
00059   fail_unless(amb_test.sats.prns[0] == 4);
00060   fail_unless(amb_test.sats.prns[1] == 1);
00061   fail_unless(amb_test.sats.prns[2] == 2);
00062   fail_unless(hyp->N[0] == -2);
00063   fail_unless(hyp->N[1] == -1);
00064 }
00065 END_TEST
00066 
00067 //void ambiguity_update_reference(ambiguity_test_t *amb_test, u8 num_sdiffs, sdiff_t *sdiffs, sdiff_t *sdiffs_with_ref_first);
00068 START_TEST(test_ambiguity_update_reference)
00069 {
00070   srandom(1);
00071 
00072   ambiguity_test_t amb_test = {.sats = {.num_sats = 4, 
00073                                         .prns = {3,1,2,4}}};
00074   create_ambiguity_test(&amb_test);
00075 
00076   sdiff_t sdiffs[4] = {{.prn = 1, .snr = 0},
00077                        {.prn = 2, .snr = 0}, 
00078                        // {.prn = 3, .snr = 0}, 
00079                        {.prn = 4, .snr = 1}};
00080   u8 num_sdiffs = 4;
00081 
00082   for (u32 i=0; i<3; i++) {
00083     hypothesis_t *hyp = (hypothesis_t *)memory_pool_add(amb_test.pool);
00084     fail_unless(hyp != 0, "Null pointer returned by memory_pool_add");
00085     for (u8 j=0; j<amb_test.sats.num_sats-1; j++) {
00086       hyp->N[j] = sizerand(5);
00087     }
00088     hyp->ll = frand(0, 1);
00089   }
00090 
00091   u8 num_dds = MAX(0,amb_test.sats.num_sats - 1);
00092   printf("Before rebase:\n");
00093   memory_pool_map(amb_test.pool, &num_dds, &print_hyp);
00094 
00095   sdiff_t sdiffs_with_ref_first[4];
00096   ambiguity_update_reference(&amb_test, num_sdiffs, sdiffs, sdiffs_with_ref_first);
00097 
00098   printf("After rebase:\n");
00099   memory_pool_map(amb_test.pool, &num_dds, &print_hyp);
00100 }
00101 END_TEST
00102 
00103 //s8 sats_match(ambiguity_test_t *amb_test, u8 num_sdiffs, sdiff_t *sdiffs);
00104 START_TEST(test_sats_match)
00105 {
00106   ambiguity_test_t amb_test = {.sats = {.num_sats = 3,
00107                                         .prns = {3,1,2}}};
00108   sdiff_t sdiffs[4] = {{.prn = 1},
00109                        {.prn = 2},
00110                        {.prn = 3},
00111                        {.prn = 4}};
00112   u8 num_sdiffs = 4;
00113   fail_unless(!sats_match(&amb_test, num_sdiffs, sdiffs));
00114 
00115   num_sdiffs = 3;
00116   fail_unless(sats_match(&amb_test, num_sdiffs, sdiffs));
00117 
00118   sdiffs[0].prn = 22;
00119   fail_unless(!sats_match(&amb_test, num_sdiffs, sdiffs));
00120 
00121 }
00122 END_TEST
00123 
00124 
00125 Suite* ambiguity_test_suite(void)
00126 {
00127   Suite *s = suite_create("Ambiguity Test");
00128 
00129   TCase *tc_core = tcase_create("Core");
00130   tcase_add_test(tc_core, test_sats_match);
00131   tcase_add_test(tc_core, test_ambiguity_update_reference);
00132   tcase_add_test(tc_core, test_update_sats_same_sats);
00133   tcase_add_test(tc_core, test_update_sats_rebase);
00134   suite_add_tcase(s, tc_core);
00135 
00136   return s;
00137 }
00138 


swiftnav
Author(s):
autogenerated on Sat Jun 8 2019 18:55:28