operator== fixes

This commit is contained in:
2021-04-01 20:56:44 +02:00
parent 2d54e68596
commit be48b74d7f
2 changed files with 7 additions and 11 deletions

View File

@ -49,14 +49,10 @@ public:
return (value & mask) == expected;
}
constexpr friend bool operator==(const T value, const basic_bit_pattern &pattern)
constexpr friend bool operator==(const basic_bit_pattern &l, const basic_bit_pattern &r)
{
return pattern.match(value);
}
constexpr friend bool operator==(const basic_bit_pattern &pattern, const T value)
{
return pattern.match(value);
return l.expected == r.expected &&
l.mask == r.mask;
}
};

View File

@ -19,10 +19,10 @@ private slots:
constexpr cpputils::bit_pattern pattern{"10XXX10"};
QCOMPARE(pattern.expected, 0b1000010);
QCOMPARE(pattern.mask, 0b1100011);
QVERIFY(0b1001010 == pattern);
QVERIFY(0b1010110 == pattern);
QVERIFY(!(0b1000000 == pattern));
QVERIFY(!(0b1100010 == pattern));
QVERIFY(pattern.match(0b1001010));
QVERIFY(pattern.match(0b1010110));
QVERIFY(!pattern.match(0b1000000));
QVERIFY(!pattern.match(0b1100010));
}
void test_copy()