2#include "../bool/bool.hpp"
7#include <gtest/gtest.h>
18template <
typename Builder>
class stdlib_array :
public testing::Test {
29 constexpr size_t ARRAY_LEN = 10;
33 constexpr size_t filled = 6;
34 for (
size_t i = 0; i < filled; i++) {
38 auto filled_len = array_length<Builder>(values_ct);
39 EXPECT_EQ(filled_len.get_value(), filled);
41 info(
"num gates = ",
builder.get_estimated_num_finalized_gates());
43 EXPECT_EQ(proof_result,
true);
51 auto filled_len = array_length<Builder>(values_ct);
52 EXPECT_EQ(filled_len.get_value(), 0);
53 EXPECT_TRUE(filled_len.is_constant());
55 info(
"num gates = ",
builder.get_estimated_num_finalized_gates());
57 EXPECT_EQ(proof_result,
true);
64 constexpr size_t ARRAY_LEN = 10;
68 constexpr size_t filled = 6;
69 for (
size_t i = 0; i < filled; i++) {
78 array_length<Builder>(values_ct);
80 EXPECT_EQ(
builder.failed(),
true);
81 EXPECT_EQ(
builder.err(),
"Once we've hit the first zero, there must only be zeros thereafter!");
88 constexpr size_t ARRAY_LEN = 10;
92 constexpr size_t filled = 6;
93 for (
size_t i = 0; i < filled; i++) {
97 auto popped = array_pop<Builder>(values_ct);
98 EXPECT_EQ(popped.get_value(), values[filled - 1]);
100 info(
"num gates = ",
builder.get_estimated_num_finalized_gates());
102 EXPECT_EQ(proof_result,
true);
109 constexpr size_t ARRAY_LEN = 10;
113 constexpr size_t filled = 0;
114 for (
size_t i = 0; i < filled; i++) {
118 for (
size_t i = filled; i < ARRAY_LEN; i++) {
123 auto popped = array_pop<Builder>(values_ct);
124 EXPECT_EQ(popped.get_value(), 0);
126 EXPECT_EQ(
builder.failed(),
true);
127 EXPECT_EQ(
builder.err(),
"array_pop cannot pop from an empty array");
134 constexpr size_t ARRAY_LEN = 10;
138 constexpr size_t filled = 6;
139 for (
size_t i = 0; i < filled; i++) {
143 for (
size_t i = filled; i < ARRAY_LEN; i++) {
149 array_push<Builder>(values_ct, value_ct);
150 EXPECT_EQ(value_ct.get_value(), values_ct[filled].get_value());
152 info(
"num gates = ",
builder.get_estimated_num_finalized_gates());
154 EXPECT_EQ(proof_result,
true);
161 constexpr size_t ARRAY_LEN = 10;
166 for (
size_t i = 0; i < ARRAY_LEN; i++) {
172 size_t num_pushes = 0;
173 for (
size_t i = 0; i < ARRAY_LEN; i++) {
175 size_t idx = array_push<Builder>(values_ct,
value);
176 EXPECT_TRUE(values_ct[idx].has_value());
177 EXPECT_EQ(values_ct[idx].
value().get_value(),
value.get_value());
184 array_push<Builder>(values_ct,
value);
185 FAIL() <<
"array_push should have thrown an exception when trying to push to a full array";
186 }
catch (std::runtime_error& e) {
187 EXPECT_EQ(e.what(), std::string(
"array_push cannot push to a full array"));
190 EXPECT_EQ(num_pushes, ARRAY_LEN);
192 info(
"num gates = ",
builder.get_estimated_num_finalized_gates());
194 EXPECT_EQ(proof_result,
true);
199 constexpr size_t ARRAY_LEN = 5;
201 for (
size_t i = 0; i < arr.size(); ++i) {
206 for (
size_t i = 0; i < arr.size(); ++i) {
212 EXPECT_THROW(array_push<Builder>(arr, new_value), std::runtime_error);
215 for (
size_t i = 0; i < arr.size(); ++i) {
216 EXPECT_NE(arr[i], new_value);
224 constexpr size_t ARRAY_LEN = 10;
229 constexpr size_t filled = 3;
230 for (
size_t i = 0; i < filled; i++) {
234 for (
size_t i = filled; i < ARRAY_LEN; i++) {
238 auto is_empty = is_array_empty<Builder>(values_ct);
239 EXPECT_EQ(is_empty.get_value(),
false);
242 for (
size_t i = 0; i < ARRAY_LEN; i++) {
246 is_empty = is_array_empty<Builder>(values_ct);
247 EXPECT_EQ(is_empty.get_value(),
true);
249 info(
"num gates = ",
builder.get_estimated_num_finalized_gates());
251 EXPECT_EQ(proof_result,
true);
254 template <
size_t size_1,
size_t size_2>
259 bool const expect_fail =
false)
263 for (
size_t i = 0; i < source.size(); i++) {
266 for (
size_t i = 0; i < target.size(); i++) {
270 push_array_to_array<Builder>(source_ct, target_ct);
274 for (
size_t i = 0; i < target.size(); i++) {
275 EXPECT_EQ(target_ct[i].get_value(), expected_target[i]);
279 bool proof_result =
false;
281 info(
"num gates = ",
builder.get_estimated_num_finalized_gates());
296 for (
size_t i = 0; i < source.max_size(); ++i) {
299 expected_target[i] = i + 1;
300 expected_target[i + source.max_size()] = i + 1;
306 EXPECT_TRUE(proof_result);
320 EXPECT_TRUE(proof_result);
334 EXPECT_TRUE(proof_result);
348 EXPECT_TRUE(proof_result);
362 EXPECT_TRUE(proof_result);
377 EXPECT_TRUE(proof_result);
391 EXPECT_FALSE(proof_result);
392 EXPECT_EQ(error,
"push_array_to_array target array capacity exceeded");
406 EXPECT_TRUE(proof_result);
420 EXPECT_TRUE(proof_result);
434 EXPECT_FALSE(proof_result);
435 EXPECT_EQ(error,
"push_array_to_array target array capacity exceeded");
447 bool expect_fail =
true;
448 std::tie(proof_result, error) =
451 EXPECT_FALSE(proof_result);
452 EXPECT_EQ(error,
"push_array_to_array target array capacity exceeded");
464 bool expect_fail =
true;
465 std::tie(proof_result, error) =
468 EXPECT_FALSE(proof_result);
469 EXPECT_EQ(error,
"Once we've hit the first source zero, there must only be zeros thereafter!");
481 bool expect_fail =
true;
482 std::tie(proof_result, error) =
485 EXPECT_FALSE(proof_result);
486 EXPECT_EQ(error,
"Once we've hit the first source zero, there must only be zeros thereafter!");
498 bool expect_fail =
true;
499 std::tie(proof_result, error) =
502 EXPECT_FALSE(proof_result);
503 EXPECT_EQ(error,
"Once we've hit the first zero, there must only be zeros thereafter!");
515 bool expect_fail =
true;
516 std::tie(proof_result, error) =
519 EXPECT_FALSE(proof_result);
521 EXPECT_EQ(error,
"Once we've hit the first zero, there must only be zeros thereafter!");
554 constexpr size_t SIZE = 5;
563 EXPECT_EQ(arr[0].get_values().first.get_value(), 1);
564 EXPECT_EQ(arr[0].get_values().second.get_value(), 10);
565 EXPECT_EQ(arr[1].get_values().first.get_value(), 2);
566 EXPECT_EQ(arr[1].get_values().second.get_value(), 20);
567 EXPECT_EQ(arr[2].get_values().first.get_value(), 3);
568 EXPECT_EQ(arr[2].get_values().second.get_value(), 30);
570 info(
"num gates = ",
builder.get_estimated_num_finalized_gates());
572 EXPECT_EQ(proof_result,
true);
579 constexpr size_t SIZE = 5;
592 EXPECT_EQ(
builder.failed(),
true);
593 EXPECT_EQ(
builder.err(),
"array_push cannot push to a full array");
603 TestFixture::test_array_length();
607 TestFixture::test_array_length_null();
611 TestFixture::test_array_length_fails();
615 TestFixture::test_array_pop();
619 TestFixture::test_array_pop_from_empty();
623 TestFixture::test_array_push();
627 TestFixture::test_array_push_optional();
631 TestFixture::test_array_push_generic();
635 TestFixture::test_array_push_generic_full();
640 TestFixture::test_pata_large_bench();
644 TestFixture::test_pata_same_size_not_full_to_not_full();
648 TestFixture::test_pata_same_size_not_full_to_not_full_2();
652 TestFixture::test_pata_same_size_not_full_to_empty();
656 TestFixture::test_pata_smaller_source_full_to_not_full();
660 TestFixture::test_pata_null_source();
664 TestFixture::test_pata_null_target_fails();
668 TestFixture::test_pata_singletons_full_to_not_full();
672 TestFixture::test_pata_singletons_not_full_to_full();
676 TestFixture::test_pata_singletons_full_to_full();
680 TestFixture::test_pata_same_size_full_to_full_fails();
684 TestFixture::test_pata_nonzero_after_zero_source_fails();
688 TestFixture::test_pata_nonzero_after_zero_source_fails_2();
692 TestFixture::test_pata_nonzero_after_zero_target_fails();
696 TestFixture::test_pata_nonzero_after_zero_target_fails_2();
testing::Types< bb::UltraCircuitBuilder > CircuitTypes
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
Implements boolean logic in-circuit.
static field_t conditional_assign(const bool_t< Builder > &predicate, const field_t &lhs, const field_t &rhs)
If predicate == true then return lhs, else return rhs.
MockClass(field_ct a, field_ct b)
std::pair< field_ct, field_ct > get_values()
void conditional_select(bool_ct const &condition, MockClass const &other)
static void test_pata_same_size_not_full_to_not_full_2()
stdlib::field_t< Builder > field_ct
static void test_pata_null_target_fails()
static void test_pata_nonzero_after_zero_source_fails_2()
stdlib::witness_t< Builder > witness_ct
static void test_pata_smaller_source_full_to_not_full()
static void test_pata_null_source()
static void test_array_length_null()
static void test_is_array_empty()
static auto test_push_array_to_array_helper(Builder &builder, std::array< fr, size_1 > const &source, std::array< fr, size_2 > const &target, std::array< fr, size_2 > const &expected_target, bool const expect_fail=false)
static void test_pata_same_size_not_full_to_empty()
static void test_pata_large_bench()
static void test_pata_nonzero_after_zero_source_fails()
void test_array_push_generic_full()
static void test_array_pop_from_empty()
static void test_array_length()
void test_array_push_generic()
static void test_array_push()
static void test_pata_same_size_not_full_to_not_full()
static void test_pata_singletons_full_to_not_full()
static void test_pata_singletons_not_full_to_full()
static void test_pata_singletons_full_to_full()
static void test_array_length_fails()
static void test_array_push_shared_ptr()
static void test_pata_same_size_full_to_full_fails()
static void test_pata_nonzero_after_zero_target_fails()
static void test_array_pop()
static void test_array_push_optional()
static void test_pata_nonzero_after_zero_target_fails_2()
ECCVMCircuitBuilder Builder
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Entry point for Barretenberg command-line interface.
TYPED_TEST_SUITE(ShpleminiTest, TestSettings)
TYPED_TEST(ShpleminiTest, CorrectnessOfMultivariateClaimBatching)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
testing::Types< bb::UltraCircuitBuilder > CircuitTypes
static field random_element(numeric::RNG *engine=nullptr) noexcept