summaryrefslogtreecommitdiff
path: root/src/mongo/crypto/fle_crypto_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/crypto/fle_crypto_test.cpp')
-rw-r--r--src/mongo/crypto/fle_crypto_test.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/mongo/crypto/fle_crypto_test.cpp b/src/mongo/crypto/fle_crypto_test.cpp
index 51abc96fba2..dacfb81baef 100644
--- a/src/mongo/crypto/fle_crypto_test.cpp
+++ b/src/mongo/crypto/fle_crypto_test.cpp
@@ -2463,4 +2463,72 @@ TEST(EdgeCalcTest, SparsityConstraints) {
ASSERT_THROWS_CODE(getEdgesDouble(1.0, 0.0, 8.0, -1), AssertionException, 6775101);
}
+template <typename T>
+struct MinCoverTestVector {
+ std::function<std::vector<std::string>(T, T, boost::optional<T>, boost::optional<T>, int)> algo;
+ T rangeMin, rangeMax;
+ boost::optional<T> min, max;
+ int sparsity;
+ std::vector<std::string> expect;
+
+ bool validate() const {
+ auto result = algo(rangeMin, rangeMax, min, max, sparsity);
+ if (std::equal(result.begin(), result.end(), expect.begin())) {
+ return true;
+ }
+
+ LOGV2_ERROR(6860020,
+ "MinCover algorithm produced unexpected result",
+ "rangeMin"_attr = rangeMin,
+ "rangeMax"_attr = rangeMax,
+ "min"_attr = min,
+ "max"_attr = max,
+ "sparsity"_attr = sparsity,
+ "expect"_attr = expect,
+ "got"_attr = result);
+ return false;
+ }
+};
+
+
+#pragma clang optimize off
+
+TEST(MinCoverCalcTest, Int32_TestVectors) {
+ const MinCoverTestVector<int32_t> testVectors[] = {
+#include "test_vectors/mincover_int32.cstruct"
+ };
+ for (const auto& testVector : testVectors) {
+ ASSERT_TRUE(testVector.validate());
+ }
+}
+
+TEST(MinCoverCalcTest, Int64_TestVectors) {
+ const MinCoverTestVector<int64_t> testVectors[] = {
+#include "test_vectors/mincover_int64.cstruct"
+ };
+ for (const auto& testVector : testVectors) {
+ ASSERT_TRUE(testVector.validate());
+ }
+}
+
+// TODO SERVER-68959 uncomment and update vectors
+//
+// TEST(MinCoverCalcTest, Double_TestVectors) {
+// MinCoverTestVector<double> testVectors[] = {
+// #include "test_vectors/mincover_double.cstruct"
+// };
+// for (const auto& testVector : testVectors) {
+// ASSERT_TRUE(testVector.validate());
+// }
+// }
+
+#pragma clang optimize on
+
+TEST(MinCoverCalcTest, MinCoverConstraints) {
+ ASSERT_THROWS_CODE(minCoverInt32(2, 1, 0, 7, 1), AssertionException, 6860001);
+ ASSERT_THROWS_CODE(minCoverInt64(2, 1, 0, 7, 1), AssertionException, 6860001);
+ ASSERT_THROWS_CODE(minCoverDouble(2, 1, 0, 7, 1), AssertionException, 6860001);
+}
+
+
} // namespace mongo