Skip to content

Commit

Permalink
test: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iajoiner committed Nov 12, 2024
1 parent 723c8db commit 33c745b
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 87 deletions.
4 changes: 0 additions & 4 deletions crates/proof-of-sql/src/sql/proof/query_proof_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ impl Default for TrivialTestProofPlan {
impl ProverEvaluate for TrivialTestProofPlan {
fn result_evaluate<'a, S: Scalar>(
&self,
_input_length: usize,
alloc: &'a Bump,
_accessor: &'a dyn DataAccessor<S>,
) -> Vec<Column<'a, S>> {
Expand Down Expand Up @@ -212,7 +211,6 @@ impl Default for SquareTestProofPlan {
impl ProverEvaluate for SquareTestProofPlan {
fn result_evaluate<'a, S: Scalar>(
&self,
_table_length: usize,
alloc: &'a Bump,
_accessor: &'a dyn DataAccessor<S>,
) -> Vec<Column<'a, S>> {
Expand Down Expand Up @@ -387,7 +385,6 @@ impl Default for DoubleSquareTestProofPlan {
impl ProverEvaluate for DoubleSquareTestProofPlan {
fn result_evaluate<'a, S: Scalar>(
&self,
_input_length: usize,
alloc: &'a Bump,
_accessor: &'a dyn DataAccessor<S>,
) -> Vec<Column<'a, S>> {
Expand Down Expand Up @@ -592,7 +589,6 @@ struct ChallengeTestProofPlan {}
impl ProverEvaluate for ChallengeTestProofPlan {
fn result_evaluate<'a, S: Scalar>(
&self,
_input_length: usize,
_alloc: &'a Bump,
_accessor: &'a dyn DataAccessor<S>,
) -> Vec<Column<'a, S>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub(super) struct EmptyTestQueryExpr {
impl ProverEvaluate for EmptyTestQueryExpr {
fn result_evaluate<'a, S: Scalar>(
&self,
_input_length: usize,
alloc: &'a Bump,
_accessor: &'a dyn DataAccessor<S>,
) -> Vec<Column<'a, S>> {
Expand Down
21 changes: 12 additions & 9 deletions crates/proof-of-sql/src/sql/proof_exprs/add_subtract_expr_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
base::{
commitment::InnerProductProof,
database::{owned_table_utility::*, Column, OwnedTableTestAccessor},
database::{
owned_table_utility::*, table_utility::*, Column, OwnedTableTestAccessor,
TableTestAccessor,
},
scalar::{test_scalar::TestScalar, Curve25519Scalar},
},
sql::{
Expand Down Expand Up @@ -306,20 +309,20 @@ fn we_can_query_random_tables_using_a_non_zero_offset() {
// b + a - 1
#[test]
fn we_can_compute_the_correct_output_of_an_add_subtract_expr_using_result_evaluate() {
let data = owned_table([
smallint("a", [1_i16, 2, 3, 4]),
int("b", [0_i32, 1, 0, 1]),
varchar("d", ["ab", "t", "efg", "g"]),
bigint("c", [0_i64, 2, 2, 0]),
let alloc = Bump::new();
let data = table([
borrowed_smallint("a", [1_i16, 2, 3, 4], &alloc),
borrowed_int("b", [0_i32, 1, 0, 1], &alloc),
borrowed_varchar("d", ["ab", "t", "efg", "g"], &alloc),
borrowed_bigint("c", [0_i64, 2, 2, 0], &alloc),
]);
let t = "sxt.t".parse().unwrap();
let accessor = OwnedTableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let accessor = TableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let add_subtract_expr: DynProofExpr = add(
column(t, "b", &accessor),
subtract(column(t, "a", &accessor), const_bigint(1)),
);
let alloc = Bump::new();
let res = add_subtract_expr.result_evaluate(4, &alloc, &accessor);
let res = add_subtract_expr.result_evaluate(&alloc, &data);
let expected_res_scalar = [0, 2, 2, 4]
.iter()
.map(|v| Curve25519Scalar::from(*v))
Expand Down
21 changes: 12 additions & 9 deletions crates/proof-of-sql/src/sql/proof_exprs/and_expr_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
base::{
commitment::InnerProductProof,
database::{owned_table_utility::*, Column, OwnedTableTestAccessor},
database::{
owned_table_utility::*, table_utility::*, Column, OwnedTableTestAccessor,
TableTestAccessor,
},
scalar::test_scalar::TestScalar,
},
sql::{
Expand Down Expand Up @@ -153,20 +156,20 @@ fn we_can_query_random_tables_using_a_non_zero_offset() {

#[test]
fn we_can_compute_the_correct_output_of_an_and_expr_using_result_evaluate() {
let data = owned_table([
bigint("a", [1, 2, 3, 4]),
bigint("b", [0, 1, 0, 1]),
varchar("d", ["ab", "t", "efg", "g"]),
bigint("c", [0, 2, 2, 0]),
let alloc = Bump::new();
let data = table([
borrowed_bigint("a", [1, 2, 3, 4], &alloc),
borrowed_bigint("b", [0, 1, 0, 1], &alloc),
borrowed_varchar("d", ["ab", "t", "efg", "g"], &alloc),
borrowed_bigint("c", [0, 2, 2, 0], &alloc),
]);
let t = "sxt.t".parse().unwrap();
let accessor = OwnedTableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let accessor = TableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let and_expr: DynProofExpr = and(
equal(column(t, "b", &accessor), const_int128(1)),
equal(column(t, "d", &accessor), const_varchar("t")),
);
let alloc = Bump::new();
let res = and_expr.result_evaluate(4, &alloc, &accessor);
let res = and_expr.result_evaluate(&alloc, &data);
let expected_res = Column::Boolean(&[false, true, false, false]);
assert_eq!(res, expected_res);
}
20 changes: 12 additions & 8 deletions crates/proof-of-sql/src/sql/proof_exprs/equals_expr_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
base::{
commitment::InnerProductProof,
database::{owned_table_utility::*, Column, OwnedTable, OwnedTableTestAccessor},
database::{
owned_table_utility::*, table_utility::*, Column, OwnedTable, OwnedTableTestAccessor,
TableTestAccessor,
},
scalar::{Curve25519Scalar, Scalar},
},
sql::{
Expand Down Expand Up @@ -388,10 +391,11 @@ fn we_can_query_random_tables_using_a_non_zero_offset() {

#[test]
fn we_can_compute_the_correct_output_of_an_equals_expr_using_result_evaluate() {
let data: OwnedTable<Curve25519Scalar> = owned_table([
bigint("a", [1, 2, 3, 4]),
bigint("b", [0, 5, 0, 5]),
varchar("c", ["t", "ghi", "jj", "f"]),
let alloc = Bump::new();
let data: OwnedTable<Curve25519Scalar> = table([
bigint("a", [1, 2, 3, 4], &alloc),
bigint("b", [0, 5, 0, 5], &alloc),
varchar("c", ["t", "ghi", "jj", "f"], &alloc),
decimal75(
"e",
42,
Expand All @@ -402,16 +406,16 @@ fn we_can_compute_the_correct_output_of_an_equals_expr_using_result_evaluate() {
Curve25519Scalar::ZERO,
Curve25519Scalar::from(-1),
],
&alloc,
),
]);
let t = "sxt.t".parse().unwrap();
let accessor = OwnedTableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let accessor = TableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let equals_expr: DynProofExpr = equal(
column(t, "e", &accessor),
const_scalar::<Curve25519Scalar, _>(Curve25519Scalar::ZERO),
);
let alloc = Bump::new();
let res = equals_expr.result_evaluate(4, &alloc, &accessor);
let res = equals_expr.result_evaluate(&alloc, &data);
let expected_res = Column::Boolean(&[true, false, true, false]);
assert_eq!(res, expected_res);
}
26 changes: 16 additions & 10 deletions crates/proof-of-sql/src/sql/proof_exprs/inequality_expr_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::{
base::{
commitment::InnerProductProof,
database::{
owned_table_utility::*, Column, LiteralValue, OwnedTable, OwnedTableTestAccessor,
TestAccessor,
owned_table_utility::*, table_utility::*, Column, LiteralValue, OwnedTable,
OwnedTableTestAccessor, TableTestAccessor, TestAccessor,
},
scalar::{Curve25519Scalar, Scalar, ScalarExt},
},
Expand Down Expand Up @@ -560,30 +560,36 @@ fn we_can_query_random_tables_using_a_non_zero_offset() {

#[test]
fn we_can_compute_the_correct_output_of_a_lte_inequality_expr_using_result_evaluate() {
let data = owned_table([bigint("a", [-1, 9, 1]), bigint("b", [1, 2, 3])]);
let mut accessor = OwnedTableTestAccessor::<InnerProductProof>::new_empty_with_setup(());
let alloc = Bump::new();
let data = table([
borrowed_bigint("a", [-1, 9, 1], &alloc),
borrowed_bigint("b", [1, 2, 3], &alloc),
]);
let mut accessor = TableTestAccessor::<InnerProductProof>::new_empty_with_setup(());
let t = "sxt.t".parse().unwrap();
accessor.add_table(t, data, 0);
let lhs_expr: DynProofExpr = column(t, "a", &accessor);
let rhs_expr = column(t, "b", &accessor);
let lte_expr = lte(lhs_expr, rhs_expr);
let alloc = Bump::new();
let res = lte_expr.result_evaluate(3, &alloc, &accessor);
let res = lte_expr.result_evaluate(&alloc, &data);
let expected_res = Column::Boolean(&[true, false, true]);
assert_eq!(res, expected_res);
}

#[test]
fn we_can_compute_the_correct_output_of_a_gte_inequality_expr_using_result_evaluate() {
let data = owned_table([bigint("a", [-1, 9, 1]), bigint("b", [1, 2, 3])]);
let mut accessor = OwnedTableTestAccessor::<InnerProductProof>::new_empty_with_setup(());
let alloc = Bump::new();
let data = table([
borrowed_bigint("a", [-1, 9, 1], &alloc),
borrowed_bigint("b", [1, 2, 3], &alloc),
]);
let mut accessor = TableTestAccessor::<InnerProductProof>::new_empty_with_setup(());
let t = "sxt.t".parse().unwrap();
accessor.add_table(t, data, 0);
let col_expr: DynProofExpr = column(t, "a", &accessor);
let lit_expr = const_bigint(1);
let gte_expr = gte(col_expr, lit_expr);
let alloc = Bump::new();
let res = gte_expr.result_evaluate(3, &alloc, &accessor);
let res = gte_expr.result_evaluate(&alloc, &data);
let expected_res = Column::Boolean(&[false, true, true]);
assert_eq!(res, expected_res);
}
13 changes: 8 additions & 5 deletions crates/proof-of-sql/src/sql/proof_exprs/literal_expr_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use super::{DynProofExpr, ProofExpr};
use crate::{
base::{
commitment::InnerProductProof,
database::{owned_table_utility::*, Column, OwnedTableTestAccessor},
database::{
owned_table_utility::*, table_utility::*, Column, OwnedTableTestAccessor,
TableTestAccessor,
},
},
sql::{
proof::{exercise_verification, VerifiableQueryResult},
Expand Down Expand Up @@ -118,12 +121,12 @@ fn we_can_prove_a_query_with_a_single_non_selected_row() {

#[test]
fn we_can_compute_the_correct_output_of_a_literal_expr_using_result_evaluate() {
let data = owned_table([bigint("a", [123_i64, 456, 789, 1011])]);
let alloc = Bump::new();
let data = table([borrowed_bigint("a", [123_i64, 456, 789, 1011], &alloc)]);
let t = "sxt.t".parse().unwrap();
let accessor = OwnedTableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let accessor = TableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let literal_expr: DynProofExpr = const_bool(true);
let alloc = Bump::new();
let res = literal_expr.result_evaluate(4, &alloc, &accessor);
let res = literal_expr.result_evaluate(&alloc, &data);
let expected_res = Column::Boolean(&[true, true, true, true]);
assert_eq!(res, expected_res);
}
21 changes: 12 additions & 9 deletions crates/proof-of-sql/src/sql/proof_exprs/multiply_expr_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
base::{
commitment::InnerProductProof,
database::{owned_table_utility::*, Column, OwnedTableTestAccessor},
database::{
owned_table_utility::*, table_utility::*, Column, OwnedTableTestAccessor,
TableTestAccessor,
},
scalar::{test_scalar::TestScalar, Curve25519Scalar},
},
sql::{
Expand Down Expand Up @@ -332,20 +335,20 @@ fn we_can_query_random_tables_using_a_non_zero_offset() {
// b * (a - 1.5)
#[test]
fn we_can_compute_the_correct_output_of_a_multiply_expr_using_result_evaluate() {
let data = owned_table([
smallint("a", [1_i16, 2, 3, 4]),
int("b", [0_i32, 1, 5, 1]),
varchar("d", ["ab", "t", "efg", "g"]),
bigint("c", [0_i64, 2, 2, 0]),
let alloc = Bump::new();
let data = table([
borrowed_smallint("a", [1_i16, 2, 3, 4], &alloc),
borrowed_int("b", [0_i32, 1, 5, 1], &alloc),
borrowed_varchar("d", ["ab", "t", "efg", "g"], &alloc),
borrowed_bigint("c", [0_i64, 2, 2, 0], &alloc),
]);
let t = "sxt.t".parse().unwrap();
let accessor = OwnedTableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let accessor = TableTestAccessor::<InnerProductProof>::new_from_table(t, data, 0, ());
let arithmetic_expr: DynProofExpr = multiply(
column(t, "b", &accessor),
subtract(column(t, "a", &accessor), const_decimal75(2, 1, 15)),
);
let alloc = Bump::new();
let res = arithmetic_expr.result_evaluate(4, &alloc, &accessor);
let res = arithmetic_expr.result_evaluate(&alloc, &data);
let expected_res_scalar = [0, 5, 75, 25]
.iter()
.map(|v| Curve25519Scalar::from(*v))
Expand Down
19 changes: 11 additions & 8 deletions crates/proof-of-sql/src/sql/proof_exprs/not_expr_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
base::{
commitment::InnerProductProof,
database::{owned_table_utility::*, Column, OwnedTableTestAccessor, TestAccessor},
database::{
owned_table_utility::*, table_utility::*, Column, OwnedTableTestAccessor,
TableTestAccessor, TestAccessor,
},
scalar::test_scalar::TestScalar,
},
sql::{
Expand Down Expand Up @@ -109,17 +112,17 @@ fn we_can_query_random_tables_with_a_non_zero_offset() {

#[test]
fn we_can_compute_the_correct_output_of_a_not_expr_using_result_evaluate() {
let data = owned_table([
bigint("a", [123, 456]),
bigint("b", [0, 1]),
varchar("d", ["alfa", "gama"]),
let alloc = Bump::new();
let data = table([
borrowed_bigint("a", [123, 456], &alloc),
borrowed_bigint("b", [0, 1], &alloc),
borrowed_varchar("d", ["alfa", "gama"], &alloc),
]);
let mut accessor = OwnedTableTestAccessor::<InnerProductProof>::new_empty_with_setup(());
let mut accessor = TableTestAccessor::<InnerProductProof>::new_empty_with_setup(());
let t = "sxt.t".parse().unwrap();
accessor.add_table(t, data, 0);
let not_expr: DynProofExpr = not(equal(column(t, "b", &accessor), const_int128(1)));
let alloc = Bump::new();
let res = not_expr.result_evaluate(2, &alloc, &accessor);
let res = not_expr.result_evaluate(&alloc, &data);
let expected_res = Column::Boolean(&[true, false]);
assert_eq!(res, expected_res);
}
21 changes: 12 additions & 9 deletions crates/proof-of-sql/src/sql/proof_exprs/or_expr_test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
base::{
commitment::InnerProductProof,
database::{owned_table_utility::*, Column, OwnedTableTestAccessor, TestAccessor},
database::{
owned_table_utility::*, table_utility::*, Column, OwnedTableTestAccessor,
TableTestAccessor, TestAccessor,
},
},
sql::{
proof::{exercise_verification, VerifiableQueryResult},
Expand Down Expand Up @@ -169,21 +172,21 @@ fn we_can_query_random_tables_with_a_non_zero_offset() {

#[test]
fn we_can_compute_the_correct_output_of_an_or_expr_using_result_evaluate() {
let data = owned_table([
bigint("a", [1, 2, 3, 4]),
bigint("b", [0, 1, 0, 1]),
bigint("c", [0, 2, 2, 0]),
varchar("d", ["ab", "t", "g", "efg"]),
let alloc = Bump::new();
let data = table([
borrowed_bigint("a", [1, 2, 3, 4], &alloc),
borrowed_bigint("b", [0, 1, 0, 1], &alloc),
borrowed_bigint("c", [0, 2, 2, 0], &alloc),
borrowed_varchar("d", ["ab", "t", "g", "efg"], &alloc),
]);
let mut accessor = OwnedTableTestAccessor::<InnerProductProof>::new_empty_with_setup(());
let mut accessor = TableTestAccessor::<InnerProductProof>::new_empty_with_setup(());
let t = "sxt.t".parse().unwrap();
accessor.add_table(t, data, 0);
let and_expr: DynProofExpr = or(
equal(column(t, "b", &accessor), const_int128(1)),
equal(column(t, "d", &accessor), const_varchar("g")),
);
let alloc = Bump::new();
let res = and_expr.result_evaluate(4, &alloc, &accessor);
let res = and_expr.result_evaluate(&alloc, &data);
let expected_res = Column::Boolean(&[false, true, true, true]);
assert_eq!(res, expected_res);
}
Loading

0 comments on commit 33c745b

Please sign in to comment.