Test a bit substring function
-
05-11-2019 - |
Pergunta
How do we test the following function?
bits(bitstring, i, j)
which returns a copy of the substring from i
to j
of some bitstring
.
Consider the fixed 32-bit value:
bitstring=0x12345678
We could manually pre-determine the correct return values for ~500 different combinations of i
and j
. But this only covers 0x12345678
.
There are 232 ≈ 4 billion different strings like 0x12345678
.
Even for a non-exhaustive test, manually recording the constants we expect to get from any combination of (bitstring
, i
, j
) does not seem like the best solution.
I imagine we can use the fact that bit strings map to unsigned integers and do some arithmetic to compare the return value of bits
to bitstring
.
Any help with vocabulary or classifying this validation problem would be appreciated, too.
Technical side note: My uncertainty lies in whether the bit manipulations are being performed correctly, since the bit substring does not necessarily begin or end on a byte boundary.
Another note: After a few edits I have realized the important question here is what are the different ways we can check that one bit string is a substring of another? But the original question has a broader scope so I will leave it as it is.
Nenhuma solução correta