Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
barycentric.test.cpp
Go to the documentation of this file.
2#include "univariate.hpp"
3#include <gtest/gtest.h>
4
5using namespace bb;
6
7template <class FF> class BarycentricDataTests : public testing::Test {};
8
9using FieldTypes = testing::Types<bb::fr>;
11
12#define BARYCENTIC_DATA_TESTS_TYPE_ALIASES using FF = TypeParam;
13
19TYPED_TEST(BarycentricDataTests, CompileTimeComputation)
20{
22 const size_t domain_size(2);
23 const size_t num_evals(10);
24
26}
27
29{
31 const size_t domain_size(2);
32 const size_t num_evals(10);
33 auto f = Univariate<FF, domain_size>({ 1, 2 });
34 auto expected_result = Univariate<FF, num_evals>({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
35 auto result = f.template extend_to<num_evals>();
36 EXPECT_EQ(result, expected_result);
37}
38
40{
42 static constexpr size_t initial_size(2);
43 static constexpr size_t domain_size(10);
44 auto f = Univariate<FF, domain_size>({ 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 });
45 auto expected_result = Univariate<FF, domain_size>({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
46 f.template self_extend_from<initial_size>();
47 EXPECT_EQ(f, expected_result);
48}
49
51{
53 const size_t domain_size(2);
54 auto f = Univariate<FF, domain_size>({ 1, 2 });
55 FF u = 5;
57 auto result = f.evaluate(u);
58 EXPECT_EQ(result, expected_result);
59}
60
61TYPED_TEST(BarycentricDataTests, BarycentricData2to3)
62{
64
65 const size_t domain_size = 2;
66 const size_t num_evals = 3;
68 std::array<FF, 3> expected_big_domain{ { 0, 1, 2 } };
69 std::array<FF, 2> expected_denominators{ { -1, 1 } };
70 std::array<FF, 3> expected_full_numerator_values{ { 0, 0, 2 } };
71 EXPECT_EQ(barycentric.big_domain, expected_big_domain);
72 EXPECT_EQ(barycentric.lagrange_denominators, expected_denominators);
73 EXPECT_EQ(barycentric.full_numerator_values, expected_full_numerator_values);
74
75 // e1(X) = 1*(1-X) + 2*X = 1 + X
76 Univariate<FF, 2> e1{ { 1, 2 } };
78 FF calculated_val_at_u = e1.evaluate(u);
79 EXPECT_EQ(u + 1, calculated_val_at_u);
80
81 Univariate<FF, 3> ext1 = e1.template extend_to<num_evals>();
82 Univariate<FF, 3> expected{ { 1, 2, 3 } };
83 EXPECT_EQ(ext1, expected);
84}
85
86TYPED_TEST(BarycentricDataTests, BarycentricData5to6)
87{
89
90 const size_t domain_size = 5;
91 const size_t num_evals = 6;
92
93 // Note: we are able to represent a degree 4 polynomial with 5 points thus this
94 // extension will succeed. It would fail for values on a polynomial of degree > 4.
95 Univariate<FF, domain_size> e1{ { 1, 3, 25, 109, 321 } }; // X^4 + X^3 + 1
96 Univariate<FF, num_evals> ext1 = e1.template extend_to<num_evals>();
97 Univariate<FF, num_evals> expected{ { 1, 3, 25, 109, 321, 751 } };
98 EXPECT_EQ(ext1, expected);
99}
#define BARYCENTIC_DATA_TESTS_TYPE_ALIASES
A univariate polynomial represented by its values on {0, 1,..., domain_end - 1}.
bool expected_result
testing::Types< bb::fr > FieldTypes
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
TYPED_TEST_SUITE(ShpleminiTest, TestSettings)
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
std::conditional_t< is_field_type_v< Fr >, BarycentricDataCompileTime< Fr, domain_end, num_evals >, BarycentricDataRunTime< Fr, domain_end, num_evals > > BarycentricData
Exposes BarycentricData with compile time arrays if the type is bberg::field and runtime arrays other...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept