tests: keys: Add compatibility layer tests
This commit is contained in:
@@ -54,3 +54,45 @@ BOOST_AUTO_TEST_CASE(test_key_component_iterator) {
|
||||
|
||||
BOOST_REQUIRE(i == end);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_legacy_ordering_for_non_composite_key) {
|
||||
schema s({}, "", "", {{"c1", bytes_type}}, {}, {}, {}, utf8_type);
|
||||
|
||||
auto to_key = [&s] (sstring value) {
|
||||
return partition_key::from_single_value(s, to_bytes(value));
|
||||
};
|
||||
|
||||
auto cmp = [&s] (const partition_key& k1, const partition_key& k2) {
|
||||
return k1.legacy_tri_compare(s, k2);
|
||||
};
|
||||
|
||||
BOOST_REQUIRE(cmp(to_key("A"), to_key("B")) < 0);
|
||||
BOOST_REQUIRE(cmp(to_key("AA"), to_key("B")) < 0);
|
||||
BOOST_REQUIRE(cmp(to_key("B"), to_key("AB")) > 0);
|
||||
BOOST_REQUIRE(cmp(to_key("B"), to_key("A")) > 0);
|
||||
BOOST_REQUIRE(cmp(to_key("A"), to_key("A")) == 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_legacy_ordering_for_composite_keys) {
|
||||
schema s({}, "", "", {{"c1", bytes_type}, {"c2", bytes_type}}, {}, {}, {}, utf8_type);
|
||||
|
||||
auto to_key = [&s] (sstring v1, sstring v2) {
|
||||
return partition_key::from_exploded(s, std::vector<bytes>{to_bytes(v1), to_bytes(v2)});
|
||||
};
|
||||
|
||||
auto cmp = [&s] (const partition_key& k1, const partition_key& k2) {
|
||||
return k1.legacy_tri_compare(s, k2);
|
||||
};
|
||||
|
||||
BOOST_REQUIRE(cmp(to_key("A", "B"), to_key("A", "B")) == 0);
|
||||
BOOST_REQUIRE(cmp(to_key("A", "B"), to_key("A", "C")) < 0);
|
||||
BOOST_REQUIRE(cmp(to_key("A", "B"), to_key("B", "B")) < 0);
|
||||
BOOST_REQUIRE(cmp(to_key("A", "C"), to_key("B", "B")) < 0);
|
||||
BOOST_REQUIRE(cmp(to_key("B", "A"), to_key("A", "A")) > 0);
|
||||
|
||||
BOOST_REQUIRE(cmp(to_key("AA", "B"), to_key("B", "B")) > 0);
|
||||
BOOST_REQUIRE(cmp(to_key("A", "AA"), to_key("A", "A")) > 0);
|
||||
|
||||
BOOST_REQUIRE(cmp(to_key("", "A"), to_key("A", "A")) < 0);
|
||||
BOOST_REQUIRE(cmp(to_key("A", ""), to_key("A", "A")) < 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user