This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Add test to lookup builder #148
Closed
motemotech
wants to merge
5
commits into
privacy-scaling-explorations:main
from
motemotech:motemotech/add_lookup_builder_test
Closed
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5078bdc
add test to lb.rs
motemotech cd32028
Merge branch 'main' into motemotech/add_lookup_builder_test
motemotech ffa7f23
Merge branch 'main' into motemotech/add_lookup_builder_test
leolara 1f764a0
Merge branch 'main' into motemotech/add_lookup_builder_test
leolara aac1d91
Merge branch 'main' into motemotech/add_lookup_builder_test
leolara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -201,3 +201,187 @@ impl<F: Clone + Debug> LookupBuilder<F> for LookupTableBuilder<F> { | |
table.build(self.src, self.enable) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
|
||
use halo2_proofs::halo2curves::bn256::Fr; | ||
use halo2curves::ff::Field; | ||
|
||
use crate::ast::StepType; | ||
use crate::ast::Expr; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_in_place_lookup_builder_build() { | ||
let in_place_lookup_builder = InPlaceLookupBuilder::<Fr>::default(); | ||
let annotation = in_place_lookup_builder.lookup.annotation; | ||
let exprs = in_place_lookup_builder.lookup.exprs; | ||
let enable = in_place_lookup_builder.lookup.enable; | ||
assert_eq!(annotation, ""); | ||
assert_eq!(format!("{:?}",exprs), "[]"); | ||
assert_eq!(format!("{:?}", enable), "None"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @motemotech cannot you compare to value None without converting to string? |
||
} | ||
|
||
#[test] | ||
fn test_in_place_lookup_builder_add() { | ||
let mut in_place_lookup_builder = InPlaceLookupBuilder::<Fr>::default(); | ||
let constraint = Constraint::from(Expr::Const(Fr::ONE)); | ||
in_place_lookup_builder = in_place_lookup_builder.add( | ||
constraint, | ||
Expr::Const(Fr::ONE), | ||
); | ||
let annotation = &in_place_lookup_builder.lookup.annotation; | ||
let exprs = &in_place_lookup_builder.lookup.exprs; | ||
let enable = &in_place_lookup_builder.lookup.enable; | ||
assert_eq!(annotation, "match(0x1 => 0x1) "); | ||
assert_eq!(format!("{:?}",exprs), "[(Constraint { annotation: \"0x1\", expr: 0x1 }, 0x1)]"); | ||
assert_eq!(format!("{:?}", enable), "None"); | ||
} | ||
|
||
#[test] | ||
fn test_in_place_lookup_builder_enable() { | ||
let mut in_place_lookup_builder = InPlaceLookupBuilder::<Fr>::default(); | ||
let constraint = Constraint::from(Expr::Const(Fr::ONE)); | ||
in_place_lookup_builder = in_place_lookup_builder.enable( | ||
constraint | ||
); | ||
let annotation = &in_place_lookup_builder.lookup.annotation; | ||
let exprs = &in_place_lookup_builder.lookup.exprs; | ||
let enable = &in_place_lookup_builder.lookup.enable; | ||
assert_eq!(annotation, "if 0x1, "); | ||
assert_eq!(format!("{:?}",exprs), "[]"); | ||
assert_eq!(format!("{:?}", enable), "Some(Constraint { annotation: \"0x1\", expr: 0x1 })"); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_store_add() { | ||
let lookup_table_store = LookupTableStore::<Fr>::default(); | ||
let copied = lookup_table_store.add(Expr::Const(Fr::ONE)).clone(); | ||
assert_eq!(format!("{:?}", copied.dest[0]), "0x1"); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_store_uuid() { | ||
let lookup_table_store = LookupTableStore::<Fr>::default(); | ||
let copied = lookup_table_store.clone(); | ||
let uuid = lookup_table_store.uuid(); | ||
assert_eq!(uuid, copied.id); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_store_build_none_enable() { | ||
let lookup_table_store = LookupTableStore::<Fr>::default(); | ||
let copied = lookup_table_store.add(Expr::Const(Fr::ONE)).clone(); | ||
let constraint = Constraint::from(Expr::Const(Fr::ONE)); | ||
let built_lookup = copied.build(vec!(constraint), None); | ||
assert_eq!(built_lookup.annotation, "match(0x1 => 0x1) "); | ||
assert_eq!(format!("{:?}", built_lookup.exprs), "[(Constraint { annotation: \"0x1\", expr: 0x1 }, 0x1)]"); | ||
assert_eq!(format!("{:?}", built_lookup.enable), "None"); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_store_build_enalbed() { | ||
let lookup_table_store = LookupTableStore::<Fr>::default(); | ||
let copied = lookup_table_store.add(Expr::Const(Fr::ONE)).clone(); | ||
let constraint = Constraint::from(Expr::Const(Fr::ONE)); | ||
let copied_constraint = constraint.clone(); | ||
let built_lookup = copied.build(vec!(constraint), Some(copied_constraint)); | ||
assert_eq!(built_lookup.annotation, "if 0x1, match(0x1 => 0x1) "); | ||
assert_eq!(format!("{:?}", built_lookup.exprs), "[(Constraint { annotation: \"0x1\", expr: (0x1 * 0x1) }, 0x1)]"); | ||
assert_eq!(format!("{:?}", built_lookup.enable), "Some(Constraint { annotation: \"0x1\", expr: 0x1 })"); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_registry_add() { | ||
let lookup_table_store = LookupTableStore::<Fr>::default(); | ||
let stored_uuid = lookup_table_store.uuid(); | ||
let lookup_table_registry = LookupTableRegistry::<Fr>::default(); | ||
lookup_table_registry.add(lookup_table_store); | ||
let stored_lookup_table = lookup_table_registry.get(stored_uuid); | ||
assert!(format!("{:?}", stored_lookup_table).contains(&format!("LookupTableStore {{ id: {}, dest: [] }}", stored_uuid))); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_registry_clone() { | ||
let lookup_table_store = LookupTableStore::<Fr>::default(); | ||
let stored_uuid = lookup_table_store.uuid(); | ||
let lookup_table_registry = LookupTableRegistry::<Fr>::default(); | ||
lookup_table_registry.add(lookup_table_store); | ||
let copied_lookup_table = lookup_table_registry.clone(); | ||
let stored_lookup_table = lookup_table_registry.get(stored_uuid); | ||
let stored_lookup_table_in_copy = copied_lookup_table.get(stored_uuid); | ||
assert_eq!(format!("{:?}", stored_lookup_table), format!("{:?}", stored_lookup_table_in_copy)); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_apply() { | ||
let constraint = Constraint::from(Expr::Const(Fr::ONE)); | ||
let lookup_table = LookupTable { uuid: 1u128 }; | ||
let applied_lookup_table = lookup_table.apply(constraint); | ||
let id = applied_lookup_table.id; | ||
let src = applied_lookup_table.src; | ||
let enable = applied_lookup_table.enable; | ||
assert_eq!(format!("{:?}", id), "1"); | ||
assert_eq!(format!("{:?}", src), "[0x1]"); | ||
assert_eq!(format!("{:?}", enable), "None"); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_when() { | ||
let enable = Constraint::from(Expr::Const(Fr::ONE)); | ||
let lookup_table = LookupTable { uuid: 1u128 }; | ||
let applied_lookup_table = lookup_table.when(enable); | ||
let id = applied_lookup_table.id; | ||
let src = applied_lookup_table.src; | ||
let enable = applied_lookup_table.enable; | ||
assert_eq!(format!("{:?}", id), "1"); | ||
assert_eq!(format!("{:?}", src), "[]"); | ||
assert_eq!(format!("{:?}", enable), "Some(0x1)"); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_builder_new() { | ||
let mut lookup_table_builder = LookupTableBuilder::<Fr>::new(1u128); | ||
let constraint = Constraint::from(Expr::Const(Fr::ONE)); | ||
let constraint2 = Constraint::from(Expr::Const(Fr::ZERO)); | ||
lookup_table_builder = lookup_table_builder.apply(constraint); | ||
lookup_table_builder = lookup_table_builder.apply(constraint2); | ||
let id = lookup_table_builder.id; | ||
let src = lookup_table_builder.src; | ||
assert_eq!(format!("{:?}", id), "1"); | ||
assert_eq!(format!("{:?}", src), "[0x1, 0x]"); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_builder_when() { | ||
let mut lookup_table_builder = LookupTableBuilder::<Fr>::new(1u128); | ||
let constraint = Constraint::from(Expr::Const(Fr::ONE)); | ||
lookup_table_builder = lookup_table_builder.when(constraint); | ||
let enable = lookup_table_builder.enable; | ||
assert_eq!(format!("{:?}", enable), "Some(0x1)"); | ||
} | ||
|
||
#[test] | ||
fn test_lookup_table_builder_build() { | ||
let lookup_table_store = LookupTableStore::<Fr>::default(); | ||
let stored_uuid = lookup_table_store.uuid(); | ||
let lookup_table_builder = LookupTableBuilder::<Fr>::new(stored_uuid); | ||
let lookup_table_registry = LookupTableRegistry::<Fr>::default(); | ||
lookup_table_registry.add(lookup_table_store); | ||
let mut step_type = StepType::<Fr>::new(0u128, "test step type".to_string()); | ||
let step_type_setup_context = StepTypeSetupContext { | ||
step_type: &mut step_type, | ||
tables: lookup_table_registry | ||
}; | ||
let result = lookup_table_builder.build(&step_type_setup_context); | ||
let annotation = result.annotation.clone(); | ||
let exprs = result.exprs.clone(); | ||
let enable = result.enable.clone(); | ||
assert_eq!(annotation, ""); | ||
assert_eq!(format!("{:?}",exprs), "[]"); | ||
assert_eq!(format!("{:?}", enable), "None"); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@motemotech I think you can check exprs.len() eq 0, without converting to string