Skip to content

Commit c371912

Browse files
committed
LatchedParameter: operator= and unit tests
1 parent db28ab7 commit c371912

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tests/parameter_tests.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "doctest.h"
2+
#include "util/parameter.hh"
3+
4+
TEST_CASE("basic usage") {
5+
6+
//
7+
LatchedParam<float, 1, 4096> x;
8+
LatchedParam<float, 1, 4096> y;
9+
10+
x = 2.4f;
11+
CHECK(x.val == 2.4f);
12+
CHECK(x.changed == false);
13+
14+
x.store_changed(10.f);
15+
CHECK(x.val == 10.f);
16+
CHECK(x.changed == true);
17+
18+
CHECK(y.val == 0.f);
19+
CHECK(y.changed == false);
20+
y = x;
21+
CHECK(y.val == 10.f);
22+
CHECK(y.changed == true);
23+
24+
CHECK(y.did_change());
25+
CHECK_FALSE(y.did_change());
26+
}

util/parameter.hh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ struct LatchedParam {
3232
void operator=(T x) {
3333
val = x;
3434
}
35+
36+
LatchedParam &operator=(LatchedParam const &x) {
37+
val = x.val;
38+
changed = x.changed;
39+
return *this;
40+
}
41+
3542
operator T() {
3643
return val;
3744
}

0 commit comments

Comments
 (0)