2#include <gtest/gtest.h>
8TEST(Polynomial, Shifted)
12 const size_t SIZE = 10;
13 auto poly = Polynomial::random(SIZE, 1);
16 auto poly_shifted = poly.shifted();
18 EXPECT_EQ(poly_shifted.size(), poly.size());
21 for (
size_t i = 0; i < poly_shifted.size() - 1; ++i) {
22 EXPECT_EQ(poly_shifted.get(i), poly.get(i + 1));
27 for (
size_t i = 0; i < poly_shifted.size() - 1; ++i) {
28 EXPECT_EQ(poly_shifted.get(i), poly.get(i + 1));
37 const size_t SIZE = 10;
38 const size_t VIRTUAL_SIZE = 20;
39 const size_t START_IDX = 2;
40 const size_t END_IDX = SIZE + START_IDX;
41 auto poly = Polynomial::random(SIZE, VIRTUAL_SIZE, START_IDX);
44 auto poly_reversed = poly.reverse();
46 EXPECT_EQ(poly_reversed.size(), poly.size());
47 EXPECT_EQ(poly_reversed.virtual_size(), poly.end_index());
50 for (
size_t i = 0; i < END_IDX; ++i) {
51 EXPECT_EQ(poly_reversed.get(END_IDX - 1 - i), poly.get(i));
55 FF initial_value = poly.at(3);
57 EXPECT_EQ(poly_reversed.at(END_IDX - 4), initial_value);
65 const size_t SIZE = 10;
66 auto poly = Polynomial::random(SIZE);
69 auto poly_clone = poly.share();
72 EXPECT_EQ(poly_clone, poly);
76 EXPECT_EQ(poly_clone, poly);
78 poly_clone.at(2) = 13;
79 EXPECT_EQ(poly_clone, poly);
83 auto poly2 = Polynomial::random(SIZE);
86 EXPECT_NE(poly_clone, poly);
93 EXPECT_TRUE(poly.is_shiftable());
94 EXPECT_EQ((*poly.indices().begin()), poly.start_index());
95 EXPECT_EQ(
std::get<0>(*poly.indexed_values().begin()), poly.start_index());
96 EXPECT_EQ(
std::get<1>(*poly.indexed_values().begin()), poly[poly.start_index()]);
100TEST(Polynomial, EvaluateMleSingleCoefficientEmptyPoints)
111TEST(Polynomial, FullPreservesCoefficients)
114 const size_t virtual_size = 16;
115 const size_t start = 3;
116 const size_t size = 5;
118 for (
size_t i = 0; i < size; ++i) {
119 poly.at(start + i) =
FF(i + 100);
121 auto full = poly.full();
122 EXPECT_EQ(full.start_index(), 0UL);
123 EXPECT_EQ(full.end_index(), virtual_size);
124 for (
size_t i = 0; i < virtual_size; ++i) {
125 const bool in_backed_range = i >= start && i < start + size;
126 const FF expected = in_backed_range ?
FF(i - start + 100) :
FF(0);
127 EXPECT_EQ(full[i], expected) <<
"mismatch at index " << i;
133TEST(Polynomial, AddScaledEdgeConditions)
136 GTEST_FLAG_SET(death_test_style,
"threadsafe");
138 auto test_subset_good = []() {
143 ASSERT_NO_FATAL_FAILURE(test_subset_good());
144 auto test_subset_bad1 = []() {
150 auto test_subset_bad2 = []() {
158TEST(Polynomial, OperatorAddEdgeConditions)
161 GTEST_FLAG_SET(death_test_style,
"threadsafe");
163 auto test_subset_good = []() {
168 ASSERT_NO_FATAL_FAILURE(test_subset_good());
169 auto test_subset_bad1 = []() {
175 auto test_subset_bad2 = []() {
183TEST(Polynomial, OperatorSubtractEdgeConditions)
186 GTEST_FLAG_SET(death_test_style,
"threadsafe");
188 auto test_subset_good = []() {
193 ASSERT_NO_FATAL_FAILURE(test_subset_good());
194 auto test_subset_bad1 = []() {
200 auto test_subset_bad2 = []() {
212 GTEST_FLAG_SET(death_test_style,
"threadsafe");
214 size_t degree_plus_1 = 10;
215 auto full_good = [=]() {
220 ASSERT_NO_FATAL_FAILURE(full_good());
221 auto no_full_bad = [=]() {
231TEST(Polynomial, RandomStartIndexExceedsSizeAsserts)
233 GTEST_FLAG_SET(death_test_style,
"threadsafe");
239TEST(Polynomial, ShrinkEndIndexBelowStartIndexAsserts)
241 GTEST_FLAG_SET(death_test_style,
"threadsafe");
#define ASSERT_THROW_OR_ABORT(statement, matcher)
bb::field< bb::Bn254FrParams > FF
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
static Polynomial random(size_t size, size_t start_index=0)
Fr evaluate_mle(std::span< const Fr > evaluation_points, bool shift=false) const
evaluate multi-linear extension p(X_0,…,X_{n-1}) = \sum_i a_i*L_i(X_0,…,X_{n-1}) at u = (u_0,...
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
field< Bn254FrParams > fr
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
TEST(Polynomial, Shifted)