bitwise: add bitfield tests
This commit is contained in:
parent
cf268a1960
commit
5d76fb7792
@ -1,4 +1,5 @@
|
||||
#include "bitwise.hpp"
|
||||
#include "std.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
|
||||
@ -52,6 +53,30 @@ test_reverse (cruft::TAP::logger &tap)
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
test_bitfield (cruft::TAP::logger &tap)
|
||||
{
|
||||
union {
|
||||
/// * lo is set to 1 and hi is set to 0 to establish bit ordering
|
||||
/// * mid pattern tests behaviour across byte boundaries
|
||||
u16 raw = 0b0111'0011'0000'0001;
|
||||
// | |mid^---^ |
|
||||
// highest^ | lowest^
|
||||
// high^--^
|
||||
cruft::bitfield<u16, 0,1> lowest;
|
||||
cruft::bitfield<u16,15,1> highest;
|
||||
cruft::bitfield<u16,12,4> high;
|
||||
cruft::bitfield<u16, 6,4> mid;
|
||||
};
|
||||
|
||||
tap.expect_eq (lowest, u16 { 0b1}, "bitfield lowest bit");
|
||||
tap.expect_eq (highest, u16 { 0b0}, "bitfield highest bit");
|
||||
tap.expect_eq (high, u16 {0b0111}, "bitfield high bits");
|
||||
tap.expect_eq (mid, u16 {0b1100}, "bitfield byte boundary bits");
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
int
|
||||
main (int, char**)
|
||||
@ -60,6 +85,7 @@ main (int, char**)
|
||||
|
||||
test_rotate (tap);
|
||||
test_reverse (tap);
|
||||
test_bitfield (tap);
|
||||
|
||||
return tap.status ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user