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 static constexpr size_t skip_count(0);
45 auto f = Univariate<FF, domain_size, skip_count>({ 1, 2, 0, 0, 0, 0, 0, 0, 0, 0 });
46 auto expected_result = Univariate<FF, domain_size, skip_count>({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
47 f.template self_extend_from<initial_size>();
48 EXPECT_EQ(f, expected_result);
49}
50
52{
54 const size_t domain_size(2);
55 auto f = Univariate<FF, domain_size>({ 1, 2 });
56 FF u = 5;
58 auto result = f.evaluate(u);
59 EXPECT_EQ(result, expected_result);
60}
61
62TYPED_TEST(BarycentricDataTests, BarycentricData2to3)
63{
65
66 const size_t domain_size = 2;
67 const size_t num_evals = 3;
69 std::array<FF, 3> expected_big_domain{ { 0, 1, 2 } };
70 std::array<FF, 2> expected_denominators{ { -1, 1 } };
71 std::array<FF, 3> expected_full_numerator_values{ { 0, 0, 2 } };
72 EXPECT_EQ(barycentric.big_domain, expected_big_domain);
73 EXPECT_EQ(barycentric.lagrange_denominators, expected_denominators);
74 EXPECT_EQ(barycentric.full_numerator_values, expected_full_numerator_values);
75
76 // e1(X) = 1*(1-X) + 2*X = 1 + X
77 Univariate<FF, 2> e1{ { 1, 2 } };
78 FF u = FF::random_element();
79 FF calculated_val_at_u = e1.evaluate(u);
80 EXPECT_EQ(u + 1, calculated_val_at_u);
81
82 Univariate<FF, 3> ext1 = e1.template extend_to<num_evals>();
83 Univariate<FF, 3> expected{ { 1, 2, 3 } };
84 EXPECT_EQ(ext1, expected);
85}
86
87TYPED_TEST(BarycentricDataTests, BarycentricData5to6)
88{
90
91 const size_t domain_size = 5;
92 const size_t num_evals = 6;
93
94 // Note: we are able to represent a degree 4 polynomial with 5 points thus this
95 // extension will succeed. It would fail for values on a polynomial of degree > 4.
96 Univariate<FF, domain_size> e1{ { 1, 3, 25, 109, 321 } }; // X^4 + X^3 + 1
97 Univariate<FF, num_evals> ext1 = e1.template extend_to<num_evals>();
98 Univariate<FF, num_evals> expected{ { 1, 3, 25, 109, 321, 751 } };
99 EXPECT_EQ(ext1, expected);
100}
#define BARYCENTIC_DATA_TESTS_TYPE_ALIASES
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
Fr evaluate(const Fr &u) const
Evaluate a univariate at a point u not known at compile time and assumed not to be in the domain (els...
bool expected_result
testing::Types< bb::fr > FieldTypes
Entry point for Barretenberg command-line interface.
std::conditional_t< is_field_type_v< Fr >, BarycentricDataCompileTime< Fr, domain_end, num_evals, domain_start >, BarycentricDataRunTime< Fr, domain_end, num_evals, domain_start > > BarycentricData
Exposes BarycentricData with compile time arrays if the type is bberg::field and runtime arrays other...
TYPED_TEST_SUITE(ShpleminiTest, TestSettings)
typename Flavor::FF FF
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13