context_test.cc 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2020 Google LLC.
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * https://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. #include "context.h"
  16. #include <gmock/gmock.h>
  17. #include <gtest/gtest.h>
  18. #include "absl/numeric/int128.h"
  19. #include "constants.h"
  20. #include "integral_types.h"
  21. #include "montgomery.h"
  22. #include "status_macros.h"
  23. #include "testing/parameters.h"
  24. #include "testing/status_testing.h"
  25. namespace {
  26. template <typename ModularInt>
  27. class ContextTest : public ::testing::Test {};
  28. TYPED_TEST_SUITE(ContextTest, rlwe::testing::ModularIntTypes);
  29. TYPED_TEST(ContextTest, CreateWorks) {
  30. for (const auto& params :
  31. rlwe::testing::ContextParameters<TypeParam>::Value()) {
  32. ASSERT_OK_AND_ASSIGN(auto context,
  33. rlwe::RlweContext<TypeParam>::Create(params));
  34. }
  35. }
  36. TYPED_TEST(ContextTest, ParametersMatch) {
  37. for (const auto& params :
  38. rlwe::testing::ContextParameters<TypeParam>::Value()) {
  39. ASSERT_OK_AND_ASSIGN(auto context,
  40. rlwe::RlweContext<TypeParam>::Create(params));
  41. ASSERT_EQ(context->GetLogN(), params.log_n);
  42. ASSERT_EQ(context->GetN(), context->GetNttParams()->number_coeffs);
  43. ASSERT_EQ(context->GetLogT(), params.log_t);
  44. ASSERT_EQ(context->GetModulus(), params.modulus);
  45. ASSERT_EQ(context->GetModulus(), context->GetModulusParams()->modulus);
  46. ASSERT_EQ(context->GetVariance(), params.variance);
  47. }
  48. }
  49. } // namespace