Merge pull request #1269 from pkendall64/crsf-max-output
[ExpressLRS.git] / src / test / fhss_native / test_fhss.cpp
blob8b954f949265a490a359fd82d20b493134648737
1 #include <cstdint>
2 #include <FHSS.h>
3 #include <unity.h>
4 #include <set>
6 void test_fhss_first(void)
8 FHSSrandomiseFHSSsequence(0x01020304L);
9 TEST_ASSERT_EQUAL(GetInitialFreq(), FHSSfreqs[sync_channel]);
12 void test_fhss_assignment(void)
14 FHSSrandomiseFHSSsequence(0x01020304L);
16 const uint32_t numFhss = FHSSgetChannelCount();
17 uint32_t initFreq = GetInitialFreq();
19 uint32_t freq = initFreq;
20 for (unsigned int i = 0; i < 512; i++) {
21 if ((i % numFhss) == 0) {
22 TEST_ASSERT_EQUAL(initFreq, freq);
23 } else {
24 TEST_ASSERT_NOT_EQUAL(initFreq, freq);
26 freq = FHSSgetNextFreq();
30 void test_fhss_unique(void)
32 FHSSrandomiseFHSSsequence(0x01020304L);
34 const uint32_t numFhss = FHSSgetChannelCount();
35 std::set<uint32_t> freqs;
37 for (unsigned int i = 0; i < 256; i++) {
38 uint32_t freq = FHSSgetNextFreq();
40 if ((i % numFhss) == 0) {
41 freqs.clear();
42 freqs.insert(freq);
43 } else {
44 bool inserted = freqs.insert(freq).second;
45 TEST_ASSERT_TRUE_MESSAGE(inserted, "Should only see a frequency one time per number initial value");
50 void test_fhss_same(void)
52 FHSSrandomiseFHSSsequence(0x01020304L);
54 const uint32_t numFhss = FHSSgetSequenceCount();
56 uint32_t fhss[numFhss];
58 for (unsigned int i = 0; i < FHSSgetSequenceCount(); i++) {
59 uint32_t freq = FHSSgetNextFreq();
60 fhss[i] = freq;
63 FHSSrandomiseFHSSsequence(0x01020304L);
65 for (unsigned int i = 0; i < FHSSgetSequenceCount(); i++) {
66 uint32_t freq = FHSSgetNextFreq();
67 TEST_ASSERT_EQUAL(fhss[i],freq);
71 int main(int argc, char **argv)
73 UNITY_BEGIN();
74 RUN_TEST(test_fhss_first);
75 RUN_TEST(test_fhss_assignment);
76 RUN_TEST(test_fhss_unique);
77 RUN_TEST(test_fhss_same);
78 UNITY_END();
80 return 0;