1
+ #include < boost/ut.hpp>
2
+ #include < gnuradio-4.0/basic/And.hpp>
3
+ // #include <limits>
4
+
5
+ using namespace gr ::basic;
6
+ using namespace boost ::ut;
7
+
8
+ const suite AndTests = [] {
9
+ " Bitwise AND operations" _test = [] {
10
+ And<uint8_t > andBlock;
11
+ // Basic bitwise AND operation
12
+ expect (eq (andBlock.processOne (0xFF , 0x0F ), 0x0F )); // 0xFF & 0x0F = 0x0F
13
+ expect (eq (andBlock.processOne (0x00 , 0xFF ), 0x00 ));
14
+ expect (eq (andBlock.processOne (0xAB , 0x22 ), 0x22 ));
15
+ };
16
+
17
+ " Edge cases" _test = [] {
18
+ And<uint8_t > andBlock;
19
+ // Edge cases for boundary values (max and min values)
20
+ expect (eq (andBlock.processOne (0xFF , 0xFF ), 0xFF )); // 0xFF & 0xFF = 0xFF
21
+ expect (eq (andBlock.processOne (0x00 , 0x00 ), 0x00 )); // 0x00 & 0x00 = 0x00
22
+ };
23
+
24
+ " int16_t support" _test = [] {
25
+ And<int16_t > andBlock;
26
+ // Test with int16_t values
27
+ expect (eq (andBlock.processOne (0x7FFF , 0x00FF ), 0x00FF )); // 0x7FFF & 0x00FF = 0x0101
28
+ expect (eq (andBlock.processOne (static_cast <int16_t >(-1 ), static_cast <int16_t >(0xAABB )), static_cast <int16_t >(0xAABB ))); // -1 & 0xAABB = 0xAABB
29
+ };
30
+
31
+ " int32_t support" _test = [] {
32
+ And<int32_t > andBlock;
33
+ // Test bitwise AND on int32_t values (max and min values)
34
+ expect (eq (andBlock.processOne (0xFFFF , 0x0F0F ), 0x0F0F )); // 0xFFFF (1111111111111111) & 0x0F0F (0000111100001111) = 0x0F0F
35
+ expect (eq (andBlock.processOne (-1 , 0x0000 ), 0x0000 )); // -1 & 0x0000 = 0x0000
36
+ };
37
+
38
+ " Boundary cases" _test = [] {
39
+ And<int32_t > andBlock;
40
+ // Boundary test cases for int32_t limits
41
+ expect (eq (andBlock.processOne (std::numeric_limits<int32_t >::max (), std::numeric_limits<int32_t >::min ()), 0 )); // MAX & MIN = 0
42
+ expect (eq (andBlock.processOne (std::numeric_limits<int32_t >::max (), -1 ), std::numeric_limits<int32_t >::max ())); // MAX & -1 = MAX
43
+ };
44
+
45
+ " Negative values" _test = [] {
46
+ And<int16_t > andBlock;
47
+ // Test with negative values for int16_t
48
+ expect (eq (andBlock.processOne (static_cast <int16_t >(-1 ), static_cast <int16_t >(-1 )), static_cast <int16_t >(-1 ))); // -1 & -1 = -1
49
+
50
+ /*
51
+ 1111 1111 1111 1011 (-5 in two's complement)
52
+ & 0000 0000 0000 0011 (3 in binary)
53
+ --------------------
54
+ 0000 0000 0000 0011 (Result = 3)
55
+ */
56
+ expect (eq (andBlock.processOne (static_cast <int16_t >(-5 ), static_cast <int16_t >(3 )), static_cast <int16_t >(3 ))); // -5 & 3 = 3
57
+
58
+ };
59
+ };
60
+
61
+ int main () { return boost::ut::cfg<boost::ut::override >.run (); }
0 commit comments