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)
112TEST(Polynomial, EvaluateMleEmptyPointsRejectsMultiCoefficient)
114 GTEST_FLAG_SET(death_test_style,
"threadsafe");
125TEST(Polynomial, FullPreservesCoefficients)
128 const size_t virtual_size = 16;
129 const size_t start = 3;
130 const size_t size = 5;
132 for (
size_t i = 0; i < size; ++i) {
133 poly.at(start + i) =
FF(i + 100);
135 auto full = poly.full();
136 EXPECT_EQ(full.start_index(), 0UL);
137 EXPECT_EQ(full.end_index(), virtual_size);
138 for (
size_t i = 0; i < virtual_size; ++i) {
139 const bool in_backed_range = i >= start && i < start + size;
140 const FF expected = in_backed_range ?
FF(i - start + 100) :
FF(0);
141 EXPECT_EQ(full[i], expected) <<
"mismatch at index " << i;
147TEST(Polynomial, AddScaledEdgeConditions)
150 GTEST_FLAG_SET(death_test_style,
"threadsafe");
152 auto test_subset_good = []() {
157 ASSERT_NO_FATAL_FAILURE(test_subset_good());
158 auto test_subset_bad1 = []() {
164 auto test_subset_bad2 = []() {
172TEST(Polynomial, OperatorAddEdgeConditions)
175 GTEST_FLAG_SET(death_test_style,
"threadsafe");
177 auto test_subset_good = []() {
182 ASSERT_NO_FATAL_FAILURE(test_subset_good());
183 auto test_subset_bad1 = []() {
189 auto test_subset_bad2 = []() {
197TEST(Polynomial, OperatorSubtractEdgeConditions)
200 GTEST_FLAG_SET(death_test_style,
"threadsafe");
202 auto test_subset_good = []() {
207 ASSERT_NO_FATAL_FAILURE(test_subset_good());
208 auto test_subset_bad1 = []() {
214 auto test_subset_bad2 = []() {
226 GTEST_FLAG_SET(death_test_style,
"threadsafe");
228 size_t degree_plus_1 = 10;
229 auto full_good = [=]() {
234 ASSERT_NO_FATAL_FAILURE(full_good());
235 auto no_full_bad = [=]() {
245TEST(Polynomial, RandomStartIndexExceedsSizeAsserts)
247 GTEST_FLAG_SET(death_test_style,
"threadsafe");
253TEST(Polynomial, ShrinkEndIndexBelowStartIndexAsserts)
255 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)