continued porting of test cases

This commit is contained in:
Henry Schimke
2023-04-09 18:25:59 -05:00
parent 8a1d0b3969
commit 1900e1ca57
10 changed files with 364 additions and 214 deletions

View File

@@ -28,36 +28,40 @@ fn Decode() {
assert_eq!(0x07, expected.data_mask);
assert_eq!(ErrorCorrectionLevel::Q, expected.error_correction_level);
// where the code forgot the mask!
assert_eq!(
expected,
FormatInformation::DecodeQR(UNMASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO2)
);
// assert_eq!(
// expected,
// FormatInformation::DecodeQR(UNMASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO2)
// );
cpp_eq(
&expected,
&FormatInformation::DecodeQR(UNMASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO2),
)
}
#[test]
fn DecodeWithBitDifference() {
let expected = FormatInformation::DecodeQR(MASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO2);
// 1,2,3,4 bits difference
assert_eq!(
expected,
FormatInformation::DecodeQR(
cpp_eq(
&expected,
&FormatInformation::DecodeQR(
MASKED_TEST_FORMAT_INFO ^ 0x01,
MASKED_TEST_FORMAT_INFO2 ^ 0x01
)
MASKED_TEST_FORMAT_INFO2 ^ 0x01,
),
);
assert_eq!(
expected,
FormatInformation::DecodeQR(
cpp_eq(
&expected,
&FormatInformation::DecodeQR(
MASKED_TEST_FORMAT_INFO ^ 0x03,
MASKED_TEST_FORMAT_INFO2 ^ 0x03
)
MASKED_TEST_FORMAT_INFO2 ^ 0x03,
),
);
assert_eq!(
expected,
FormatInformation::DecodeQR(
cpp_eq(
&expected,
&FormatInformation::DecodeQR(
MASKED_TEST_FORMAT_INFO ^ 0x07,
MASKED_TEST_FORMAT_INFO2 ^ 0x07
)
MASKED_TEST_FORMAT_INFO2 ^ 0x07,
),
);
assert!(!FormatInformation::DecodeQR(
MASKED_TEST_FORMAT_INFO ^ 0x0F,
@@ -69,12 +73,12 @@ fn DecodeWithBitDifference() {
#[test]
fn DecodeWithMisread() {
let expected = FormatInformation::DecodeQR(MASKED_TEST_FORMAT_INFO, MASKED_TEST_FORMAT_INFO2);
assert_eq!(
expected,
FormatInformation::DecodeQR(
cpp_eq(
&expected,
&FormatInformation::DecodeQR(
MASKED_TEST_FORMAT_INFO ^ 0x03,
MASKED_TEST_FORMAT_INFO2 ^ 0x0F
)
MASKED_TEST_FORMAT_INFO2 ^ 0x0F,
),
);
}
@@ -102,17 +106,17 @@ fn DecodeMicroWithBitDifference() {
let expected = FormatInformation::DecodeMQR(MICRO_MASKED_TEST_FORMAT_INFO);
// 1,2,3 bits difference
assert_eq!(
expected,
FormatInformation::DecodeMQR(MICRO_MASKED_TEST_FORMAT_INFO ^ 0x01)
cpp_eq(
&expected,
&FormatInformation::DecodeMQR(MICRO_MASKED_TEST_FORMAT_INFO ^ 0x01),
);
assert_eq!(
expected,
FormatInformation::DecodeMQR(MICRO_MASKED_TEST_FORMAT_INFO ^ 0x03)
cpp_eq(
&expected,
&FormatInformation::DecodeMQR(MICRO_MASKED_TEST_FORMAT_INFO ^ 0x03),
);
assert_eq!(
expected,
FormatInformation::DecodeMQR(MICRO_MASKED_TEST_FORMAT_INFO ^ 0x07)
cpp_eq(
&expected,
&FormatInformation::DecodeMQR(MICRO_MASKED_TEST_FORMAT_INFO ^ 0x07),
);
// Bigger bit differences can return valid FormatInformation objects but the data mask and error
@@ -122,3 +126,7 @@ fn DecodeMicroWithBitDifference() {
// EXPECT_NE(expected.errorCorrectionLevel(),
// FormatInformation::DecodeFormatInformation(MICRO_MASKED_TEST_FORMAT_INFO ^ 0x3f).errorCorrectionLevel());
}
fn cpp_eq(rhs: &FormatInformation, lhs: &FormatInformation) {
assert!(rhs.cpp_eq(lhs))
}