summaryrefslogtreecommitdiff
path: root/tests/unit/common/test_hound_transmission_policy.cpp
blob: 5a71417bd6d296b327142c731d71efc449e6caa8 (plain)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <QtTest/QtTest>

#include "HoundTransmissionPolicy.hpp"

class TestHoundTransmissionPolicy final : public QObject
{
  Q_OBJECT

private slots:
  void planFoxReportReply_data ();
  void planFoxReportReply ();
  void planInitialCallingFrequency_data ();
  void planInitialCallingFrequency ();
  void planReplyTransmission_data ();
  void planReplyTransmission ();
};

void TestHoundTransmissionPolicy::planFoxReportReply_data ()
{
  QTest::addColumn<int> ("protocol");
  QTest::addColumn<bool> ("tune");
  QTest::addColumn<bool> ("autoEnabled");
  QTest::addColumn<int> ("priorReplyState");
  QTest::addColumn<bool> ("applyReply");
  QTest::addColumn<bool> ("enableAuto");
  QTest::addColumn<int> ("frequencyAction");
  QTest::addColumn<int> ("nextReplyState");

  using namespace HoundTransmissionPolicy;
  QTest::newRow ("classic") << int (Protocol::Classic) << false << false
    << int (ReplyState::None) << true << true << int (FrequencyAction::Set)
    << int (ReplyState::FirstReplyPending);
  QTest::newRow ("auto already enabled") << int (Protocol::Classic) << false << true
    << int (ReplyState::None) << true << false << int (FrequencyAction::Set)
    << int (ReplyState::FirstReplyPending);
  QTest::newRow ("SuperHound") << int (Protocol::SuperFox) << false << false
    << int (ReplyState::None) << true << true << int (FrequencyAction::Keep)
    << int (ReplyState::FirstReplyPending);
  QTest::newRow ("tune") << int (Protocol::Classic) << true << false
    << int (ReplyState::FirstReplySent) << false << false << int (FrequencyAction::Keep)
    << int (ReplyState::FirstReplySent);
}

void TestHoundTransmissionPolicy::planFoxReportReply ()
{
  QFETCH (int, protocol);
  QFETCH (bool, tune);
  QFETCH (bool, autoEnabled);
  QFETCH (int, priorReplyState);
  QFETCH (bool, applyReply);
  QFETCH (bool, enableAuto);
  QFETCH (int, frequencyAction);
  QFETCH (int, nextReplyState);

  using namespace HoundTransmissionPolicy;
  State state;
  state.replyState = static_cast<ReplyState> (priorReplyState);
  state.foxFrequency = 321;
  ReplyInput input;
  input.protocol = static_cast<Protocol> (protocol);
  input.tune = tune;
  input.autoEnabled = autoEnabled;
  input.sentReport = -17;
  input.decodedFoxFrequency = 654;
  input.trPeriod = 15.0;

  auto const plan = HoundTransmissionPolicy::planFoxReportReply (state, input);
  QCOMPARE (plan.applyReply, applyReply);
  QCOMPARE (plan.enableAuto, enableAuto);
  QCOMPARE (int (plan.frequencyDecision.action), frequencyAction);
  QCOMPARE (int (plan.nextState.replyState), nextReplyState);
  QCOMPARE (plan.nextState.foxFrequency, 654);
  if (applyReply)
    {
      QCOMPARE (int (plan.txMessage), int (TxMessage::Tx3));
      QCOMPARE (plan.report, -17);
      QCOMPARE (plan.timeoutMilliseconds, 165000);
      if (FrequencyAction::Set == plan.frequencyDecision.action)
        {
          QCOMPARE (plan.frequencyDecision.frequency, 654);
        }
    }
  else
    {
      QCOMPARE (int (plan.txMessage), int (TxMessage::None));
      QCOMPARE (plan.timeoutMilliseconds, 0);
    }
}

void TestHoundTransmissionPolicy::planInitialCallingFrequency_data ()
{
  using namespace HoundTransmissionPolicy;
  QTest::addColumn<bool> ("autoEnabled");
  QTest::addColumn<bool> ("tune");
  QTest::addColumn<int> ("selectedTxMessage");
  QTest::addColumn<int> ("currentTxFrequency");
  QTest::addColumn<int> ("frequencyAction");

  QTest::newRow ("eligible at 998 Hz") << true << false << 1 << 998
    << int (FrequencyAction::RandomizeCalling);
  QTest::newRow ("Auto off") << false << false << 1 << 998 << int (FrequencyAction::Keep);
  QTest::newRow ("Tune") << true << true << 1 << 998 << int (FrequencyAction::Keep);
  QTest::newRow ("Tx3") << true << false << 3 << 998 << int (FrequencyAction::Keep);
  QTest::newRow ("999 Hz") << true << false << 1 << 999 << int (FrequencyAction::Keep);
}

void TestHoundTransmissionPolicy::planInitialCallingFrequency ()
{
  QFETCH (bool, autoEnabled);
  QFETCH (bool, tune);
  QFETCH (int, selectedTxMessage);
  QFETCH (int, currentTxFrequency);
  QFETCH (int, frequencyAction);

  using namespace HoundTransmissionPolicy;
  ClassicTxStartInput input;
  input.autoEnabled = autoEnabled;
  input.tune = tune;
  input.selectedTxMessage = selectedTxMessage;
  input.currentTxFrequency = currentTxFrequency;
  auto const plan = planClassicTxStart (State {}, input);
  QCOMPARE (int (plan.frequencyDecision.action), frequencyAction);
}

void TestHoundTransmissionPolicy::planReplyTransmission_data ()
{
  QTest::addColumn<int> ("replyState");
  QTest::addColumn<int> ("foxFrequency");
  QTest::addColumn<int> ("selectedTxMessage");
  QTest::addColumn<bool> ("tune");
  QTest::addColumn<int> ("frequencyAction");
  QTest::addColumn<int> ("frequency");
  QTest::addColumn<int> ("nextReplyState");

  using namespace HoundTransmissionPolicy;
  QTest::newRow ("first reply") << int (ReplyState::FirstReplyPending) << 600 << 3 << false
    << int (FrequencyAction::Keep) << 0 << int (ReplyState::FirstReplySent);
  QTest::newRow ("retry at 600 Hz") << int (ReplyState::FirstReplySent) << 600 << 3 << false
    << int (FrequencyAction::Set) << 900 << int (ReplyState::FirstReplySent);
  QTest::newRow ("retry at 601 Hz") << int (ReplyState::FirstReplySent) << 601 << 3 << false
    << int (FrequencyAction::Set) << 301 << int (ReplyState::FirstReplySent);
  QTest::newRow ("non-Tx3 retry") << int (ReplyState::FirstReplySent) << 600 << 2 << false
    << int (FrequencyAction::Keep) << 0 << int (ReplyState::FirstReplySent);
  QTest::newRow ("Tune retry") << int (ReplyState::FirstReplySent) << 600 << 3 << true
    << int (FrequencyAction::Set) << 900 << int (ReplyState::FirstReplySent);
  QTest::newRow ("non-Tx3 advances pending") << int (ReplyState::FirstReplyPending) << 600 << 2 << true
    << int (FrequencyAction::Keep) << 0 << int (ReplyState::FirstReplySent);
}

void TestHoundTransmissionPolicy::planReplyTransmission ()
{
  QFETCH (int, replyState);
  QFETCH (int, foxFrequency);
  QFETCH (int, selectedTxMessage);
  QFETCH (bool, tune);
  QFETCH (int, frequencyAction);
  QFETCH (int, frequency);
  QFETCH (int, nextReplyState);

  using namespace HoundTransmissionPolicy;
  State state;
  state.replyState = static_cast<ReplyState> (replyState);
  state.foxFrequency = foxFrequency;
  ClassicTxStartInput input;
  input.autoEnabled = true;
  input.tune = tune;
  input.selectedTxMessage = selectedTxMessage;
  input.currentTxFrequency = 1500;

  auto const plan = planClassicTxStart (state, input);
  QCOMPARE (int (plan.frequencyDecision.action), frequencyAction);
  QCOMPARE (plan.frequencyDecision.frequency, frequency);
  QCOMPARE (int (plan.nextState.replyState), nextReplyState);
  QCOMPARE (plan.nextState.foxFrequency, foxFrequency);
}

QTEST_GUILESS_MAIN (TestHoundTransmissionPolicy)

#include "test_hound_transmission_policy.moc"