diff options
| author | sergey.galtsev <sergey.galtsev@mongodb.com> | 2022-08-18 12:47:12 -0700 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-23 15:58:20 +0000 |
| commit | 64651e53659956dc67bfc06735a49dafbb319602 (patch) | |
| tree | 0ef9ba9ad5897be5365bee1798bfaefdf1fe8ecf /src/mongo/crypto/fle_crypto_test.cpp | |
| parent | 38a62b9fcdef11cabef80fde18f124e5f7c0f751 (diff) | |
| download | mongo-64651e53659956dc67bfc06735a49dafbb319602.tar.gz | |
SERVER-68600 implement minCover algorithmr6.2.0-alpha
Diffstat (limited to 'src/mongo/crypto/fle_crypto_test.cpp')
| -rw-r--r-- | src/mongo/crypto/fle_crypto_test.cpp | 68 |
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 |
