Skip to content

Commit

Permalink
Merge pull request #2459 from o1-labs/dw/turshi-helper-tests
Browse files Browse the repository at this point in the history
Turshi/tests: move helpers into subdirectory
  • Loading branch information
dannywillems authored Jul 30, 2024
2 parents 894ec44 + 0981414 commit 33beff8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
34 changes: 0 additions & 34 deletions turshi/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,37 +46,3 @@ impl<F: Field> CairoFieldHelpers<F> for F {
hex::encode(bytes)
}
}

#[cfg(test)]
mod tests {
use super::*;
use ark_ec::AffineCurve;
use mina_curves::pasta::Pallas as CurvePoint;
use o1_utils::FieldHelpers;

/// Base field element type
pub type BaseField = <CurvePoint as AffineCurve>::BaseField;

#[test]
fn test_field_to_bits() {
let fe = BaseField::from(256u32);
let bits = fe.to_bits();
println!("{:?}", &bits[0..16]);
}

#[test]
fn test_field_to_chunks() {
let fe = BaseField::from(0x480680017fff8000u64);
let chunk = fe.u16_chunk(1);
assert_eq!(chunk, BaseField::from(0x7fff));
}

#[test]
fn test_hex_and_u64() {
let fe = BaseField::from(0x480680017fff8000u64);
let change = BaseField::from_hex(&fe.to_hex()).unwrap();
assert_eq!(fe, change);
let word = change.to_u64();
assert_eq!(word, 0x480680017fff8000u64);
}
}
30 changes: 30 additions & 0 deletions turshi/tests/helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use ark_ec::AffineCurve;
use mina_curves::pasta::Pallas as CurvePoint;
use o1_utils::FieldHelpers;
use turshi::helper::CairoFieldHelpers;

/// Base field element type
pub type BaseField = <CurvePoint as AffineCurve>::BaseField;

#[test]
fn test_field_to_bits() {
let fe = BaseField::from(256u32);
let bits = fe.to_bits();
println!("{:?}", &bits[0..16]);
}

#[test]
fn test_field_to_chunks() {
let fe = BaseField::from(0x480680017fff8000u64);
let chunk = fe.u16_chunk(1);
assert_eq!(chunk, BaseField::from(0x7fff));
}

#[test]
fn test_hex_and_u64() {
let fe = BaseField::from(0x480680017fff8000u64);
let change = BaseField::from_hex(&fe.to_hex()).unwrap();
assert_eq!(fe, change);
let word = change.to_u64();
assert_eq!(word, 0x480680017fff8000u64);
}

0 comments on commit 33beff8

Please sign in to comment.