From 8533fa9b870dc36911432e978c1345ebe77917f2 Mon Sep 17 00:00:00 2001 From: Abinand P Date: Sat, 19 Oct 2024 14:56:40 +0530 Subject: [PATCH] modified the non-testfiles in database directory Signed-off-by: Abinand P --- .../arrow_array_to_column_conversion.rs | 114 ++-- .../proof-of-sql/src/base/database/column.rs | 73 ++- .../src/base/database/column_operation.rs | 354 +++++------ .../src/base/database/owned_column.rs | 73 ++- .../base/database/owned_column_operation.rs | 574 +++++++----------- .../database/scalar_and_i256_conversions.rs | 106 ++-- 6 files changed, 583 insertions(+), 711 deletions(-) diff --git a/crates/proof-of-sql/src/base/database/arrow_array_to_column_conversion.rs b/crates/proof-of-sql/src/base/database/arrow_array_to_column_conversion.rs index b78373a5d..9311f2e20 100644 --- a/crates/proof-of-sql/src/base/database/arrow_array_to_column_conversion.rs +++ b/crates/proof-of-sql/src/base/database/arrow_array_to_column_conversion.rs @@ -63,9 +63,9 @@ pub trait ArrayRefExt { /// It should only be used during testing. #[cfg(any(test, feature = "test"))] #[cfg(feature = "blitzar")] - fn to_curve25519_scalars( + fn to_test_scalars( &self, - ) -> Result, ArrowArrayToColumnConversionError>; + ) -> Result, ArrowArrayToColumnConversionError>; /// Convert an [`ArrayRef`] into a Proof of SQL Column type /// @@ -91,9 +91,10 @@ pub trait ArrayRefExt { impl ArrayRefExt for ArrayRef { #[cfg(any(test, feature = "test"))] #[cfg(feature = "blitzar")] - fn to_curve25519_scalars( + fn to_test_scalars( &self, - ) -> Result, ArrowArrayToColumnConversionError> { + ) -> Result, ArrowArrayToColumnConversionError> + { if self.null_count() != 0 { return Err(ArrowArrayToColumnConversionError::ArrayContainsNulls); } @@ -184,7 +185,7 @@ impl ArrayRefExt for ArrayRef { /// # Parameters /// - `alloc`: Reference to a `Bump` allocator used for memory allocation during the conversion. /// - `range`: Reference to a `Range` specifying the slice of the array to convert. - /// - `precomputed_scals`: Optional reference to a slice of `Curve25519Scalar` values. + /// - `precomputed_scals`: Optional reference to a slice of `TestScalars` values. /// `VarChar` columns store hashes to their values as scalars, which can be provided here. /// /// # Supported types @@ -386,7 +387,7 @@ impl ArrayRefExt for ArrayRef { mod tests { use super::*; - use crate::{base::scalar::Curve25519Scalar, proof_primitive::dory::DoryScalar}; + use crate::{base::scalar::test_scalar::TestScalar, proof_primitive::dory::DoryScalar}; use alloc::sync::Arc; use arrow::array::Decimal256Builder; use core::str::FromStr; @@ -400,7 +401,7 @@ mod tests { Some("Z"), )); - let result = array.to_column::(&alloc, &(1..3), None); + let result = array.to_column::(&alloc, &(1..3), None); assert_eq!( result.unwrap(), Column::TimestampTZ(PoSQLTimeUnit::Second, PoSQLTimeZone::Utc, &data[1..3]) @@ -450,7 +451,7 @@ mod tests { Some("Utc"), )); - let result = array.to_column::(&alloc, &(3..5), None); + let result = array.to_column::(&alloc, &(3..5), None); assert_eq!( result, Err(ArrowArrayToColumnConversionError::IndexOutOfBounds { len: 3, index: 5 }) @@ -488,10 +489,9 @@ mod tests { fn we_can_convert_utf8_array_normal_range() { let alloc = Bump::new(); let array: ArrayRef = Arc::new(StringArray::from(vec!["hello", "world", "test"])); - let result = array.to_column::(&alloc, &(1..3), None); + let result = array.to_column::(&alloc, &(1..3), None); let expected_vals = vec!["world", "test"]; - let expected_scals: Vec = - expected_vals.iter().map(|&v| v.into()).collect(); + let expected_scals: Vec = expected_vals.iter().map(|&v| v.into()).collect(); assert_eq!( result.unwrap(), @@ -511,7 +511,7 @@ mod tests { fn we_can_convert_utf8_array_with_nulls() { let alloc = Bump::new(); let array: ArrayRef = Arc::new(StringArray::from(vec![Some("hello"), None, Some("test")])); - let result = array.to_column::(&alloc, &(0..3), None); + let result = array.to_column::(&alloc, &(0..3), None); assert!(matches!( result, Err(ArrowArrayToColumnConversionError::ArrayContainsNulls) @@ -545,7 +545,7 @@ mod tests { builder.append_value(i256::from_str("4200000000000000000000000000000000000000").unwrap()); let array: ArrayRef = Arc::new(builder.finish().with_precision_and_scale(76, 0).unwrap()); - let result = array.to_column::(&alloc, &(1..3), None); + let result = array.to_column::(&alloc, &(1..3), None); assert!(result.is_err()); } @@ -558,8 +558,8 @@ mod tests { builder.append_value(i256::from_str("4200000000000000000000000000000000000000").unwrap()); let array: ArrayRef = Arc::new(builder.finish().with_precision_and_scale(75, 0).unwrap()); - let result = array.to_column::(&alloc, &(1..3), None); - let expected_scalars: Vec = vec![ + let result = array.to_column::(&alloc, &(1..3), None); + let expected_scalars: Vec = vec![ convert_i256_to_scalar( &i256::from_str("-300000000000000000000000000000000000000").unwrap(), ) @@ -584,7 +584,7 @@ mod tests { builder.append_value(i256::from_str("4200000000000000000000000000000000000000").unwrap()); let array: ArrayRef = Arc::new(builder.finish().with_precision_and_scale(75, 0).unwrap()); - let result = array.to_column::(&alloc, &(1..1), None); + let result = array.to_column::(&alloc, &(1..1), None); assert_eq!( result.unwrap(), Column::Decimal75(Precision::new(75).unwrap(), 0, &[]) @@ -616,7 +616,7 @@ mod tests { builder.append_value(i256::from_str("4200000000000000000000000000000000000000").unwrap()); let array: ArrayRef = Arc::new(builder.finish().with_precision_and_scale(75, 0).unwrap()); - let result = array.to_column::(&alloc, &(0..3), None); + let result = array.to_column::(&alloc, &(0..3), None); assert!(matches!( result, Err(ArrowArrayToColumnConversionError::ArrayContainsNulls) @@ -647,7 +647,7 @@ mod tests { .unwrap(), ); - let result = array.to_column::(&alloc, &(2..4), None); + let result = array.to_column::(&alloc, &(2..4), None); assert_eq!( result, Err(ArrowArrayToColumnConversionError::IndexOutOfBounds { len: 3, index: 4 }) @@ -681,7 +681,7 @@ mod tests { .unwrap(), ); - let result = array.to_column::(&alloc, &(1..3), None); + let result = array.to_column::(&alloc, &(1..3), None); assert_eq!(result.unwrap(), Column::Int128(&data[1..3])); } @@ -705,7 +705,7 @@ mod tests { Some(false), Some(true), ])); - let result = array.to_column::(&alloc, &(1..1), None); + let result = array.to_column::(&alloc, &(1..1), None); assert_eq!(result.unwrap(), Column::Boolean(&[])); } @@ -730,7 +730,7 @@ mod tests { fn we_can_convert_boolean_array_with_nulls() { let alloc = Bump::new(); let array: ArrayRef = Arc::new(BooleanArray::from(vec![Some(true), None, Some(true)])); - let result = array.to_column::(&alloc, &(0..3), None); + let result = array.to_column::(&alloc, &(0..3), None); assert!(matches!( result, Err(ArrowArrayToColumnConversionError::ArrayContainsNulls) @@ -757,7 +757,7 @@ mod tests { fn we_can_convert_int8_array_empty_range() { let alloc = Bump::new(); let array: ArrayRef = Arc::new(Int8Array::from(vec![1, -3, 42])); - let result = array.to_column::(&alloc, &(1..1), None); + let result = array.to_column::(&alloc, &(1..1), None); assert_eq!(result.unwrap(), Column::TinyInt(&[])); } @@ -765,7 +765,7 @@ mod tests { fn we_can_convert_int16_array_empty_range() { let alloc = Bump::new(); let array: ArrayRef = Arc::new(Int16Array::from(vec![1, -3, 42])); - let result = array.to_column::(&alloc, &(1..1), None); + let result = array.to_column::(&alloc, &(1..1), None); assert_eq!(result.unwrap(), Column::SmallInt(&[])); } @@ -799,7 +799,7 @@ mod tests { fn we_can_convert_int8_array_with_nulls() { let alloc = Bump::new(); let array: ArrayRef = Arc::new(Int8Array::from(vec![Some(1), None, Some(42)])); - let result = array.to_column::(&alloc, &(0..3), None); + let result = array.to_column::(&alloc, &(0..3), None); assert!(matches!( result, Err(ArrowArrayToColumnConversionError::ArrayContainsNulls) @@ -810,7 +810,7 @@ mod tests { fn we_can_convert_int16_array_with_nulls() { let alloc = Bump::new(); let array: ArrayRef = Arc::new(Int16Array::from(vec![Some(1), None, Some(42)])); - let result = array.to_column::(&alloc, &(0..3), None); + let result = array.to_column::(&alloc, &(0..3), None); assert!(matches!( result, Err(ArrowArrayToColumnConversionError::ArrayContainsNulls) @@ -829,7 +829,7 @@ mod tests { fn we_can_convert_int32_array_empty_range() { let alloc = Bump::new(); let array: ArrayRef = Arc::new(Int32Array::from(vec![1, -3, 42])); - let result = array.to_column::(&alloc, &(1..1), None); + let result = array.to_column::(&alloc, &(1..1), None); assert_eq!(result.unwrap(), Column::Int(&[])); } @@ -850,7 +850,7 @@ mod tests { fn we_can_convert_int32_array_with_nulls() { let alloc = Bump::new(); let array: ArrayRef = Arc::new(Int32Array::from(vec![Some(1), None, Some(42)])); - let result = array.to_column::(&alloc, &(0..3), None); + let result = array.to_column::(&alloc, &(0..3), None); assert!(matches!( result, Err(ArrowArrayToColumnConversionError::ArrayContainsNulls) @@ -902,7 +902,7 @@ mod tests { ); let array1: ArrayRef = Arc::new(arrow::array::Int16Array::from(vec![1, -3])); - let result1 = array1.to_column::(&alloc, &(5..5), None); + let result1 = array1.to_column::(&alloc, &(5..5), None); assert_eq!( result1, Err(ArrowArrayToColumnConversionError::IndexOutOfBounds { len: 2, index: 5 }) @@ -916,7 +916,7 @@ mod tests { ); let array3: ArrayRef = Arc::new(arrow::array::Int64Array::from(vec![1, -3])); - let result3 = array3.to_column::(&alloc, &(5..5), None); + let result3 = array3.to_column::(&alloc, &(5..5), None); assert_eq!( result3, Err(ArrowArrayToColumnConversionError::IndexOutOfBounds { len: 2, index: 5 }) @@ -938,7 +938,7 @@ mod tests { let alloc = Bump::new(); let array: ArrayRef = Arc::new(arrow::array::Int8Array::from(vec![1, -3])); let result = array - .to_column::(&alloc, &(2..2), None) + .to_column::(&alloc, &(2..2), None) .unwrap(); assert_eq!(result, Column::TinyInt(&[])); } @@ -948,7 +948,7 @@ mod tests { let alloc = Bump::new(); let array: ArrayRef = Arc::new(arrow::array::Int16Array::from(vec![1, -3])); let result = array - .to_column::(&alloc, &(2..2), None) + .to_column::(&alloc, &(2..2), None) .unwrap(); assert_eq!(result, Column::SmallInt(&[])); } @@ -968,7 +968,7 @@ mod tests { let alloc = Bump::new(); let array: ArrayRef = Arc::new(arrow::array::Int64Array::from(vec![1, -3])); let result = array - .to_column::(&alloc, &(2..2), None) + .to_column::(&alloc, &(2..2), None) .unwrap(); assert_eq!(result, Column::BigInt(&[])); } @@ -998,7 +998,7 @@ mod tests { let array: ArrayRef = Arc::new(arrow::array::StringArray::from(data.clone())); assert_eq!( array - .to_column::(&alloc, &(1..1), None) + .to_column::(&alloc, &(1..1), None) .unwrap(), Column::VarChar((&[], &[])) ); @@ -1021,7 +1021,7 @@ mod tests { let alloc = Bump::new(); let data = vec!["ab", "-f34"]; let array: ArrayRef = Arc::new(arrow::array::StringArray::from(data)); - let result = array.to_column::(&alloc, &(0..3), None); + let result = array.to_column::(&alloc, &(0..3), None); assert_eq!( result, Err(ArrowArrayToColumnConversionError::IndexOutOfBounds { len: 2, index: 3 }) @@ -1042,7 +1042,7 @@ mod tests { let array: ArrayRef = Arc::new(arrow::array::Int16Array::from(vec![1, -3])); assert_eq!( array - .to_column::(&alloc, &(0..2), None) + .to_column::(&alloc, &(0..2), None) .unwrap(), Column::SmallInt(&[1, -3]) ); @@ -1050,7 +1050,7 @@ mod tests { let array: ArrayRef = Arc::new(arrow::array::Int32Array::from(vec![1, -3])); assert_eq!( array - .to_column::(&alloc, &(0..2), None) + .to_column::(&alloc, &(0..2), None) .unwrap(), Column::Int(&[1, -3]) ); @@ -1058,7 +1058,7 @@ mod tests { let array: ArrayRef = Arc::new(arrow::array::Int64Array::from(vec![1, -3])); assert_eq!( array - .to_column::(&alloc, &(0..2), None) + .to_column::(&alloc, &(0..2), None) .unwrap(), Column::BigInt(&[1, -3]) ); @@ -1085,7 +1085,7 @@ mod tests { let array: ArrayRef = Arc::new(arrow::array::BooleanArray::from(data.clone())); assert_eq!( array - .to_column::(&alloc, &(0..2), None) + .to_column::(&alloc, &(0..2), None) .unwrap(), Column::Boolean(&data[..]) ); @@ -1101,7 +1101,7 @@ mod tests { )); let result = array - .to_column::(&alloc, &(0..2), None) + .to_column::(&alloc, &(0..2), None) .unwrap(); assert_eq!( result, @@ -1138,7 +1138,7 @@ mod tests { let array: ArrayRef = Arc::new(arrow::array::Int16Array::from(vec![0, 1, 545])); assert_eq!( array - .to_column::(&alloc, &(1..3), None) + .to_column::(&alloc, &(1..3), None) .unwrap(), Column::SmallInt(&[1, 545]) ); @@ -1146,7 +1146,7 @@ mod tests { let array: ArrayRef = Arc::new(arrow::array::Int32Array::from(vec![0, 1, 545])); assert_eq!( array - .to_column::(&alloc, &(1..3), None) + .to_column::(&alloc, &(1..3), None) .unwrap(), Column::Int(&[1, 545]) ); @@ -1154,7 +1154,7 @@ mod tests { let array: ArrayRef = Arc::new(arrow::array::Int64Array::from(vec![0, 1, 545])); assert_eq!( array - .to_column::(&alloc, &(1..3), None) + .to_column::(&alloc, &(1..3), None) .unwrap(), Column::BigInt(&[1, 545]) ); @@ -1173,7 +1173,7 @@ mod tests { // Test using a range smaller than the array size assert_eq!( array - .to_column::(&alloc, &(1..3), None) + .to_column::(&alloc, &(1..3), None) .unwrap(), Column::TimestampTZ(PoSQLTimeUnit::Second, PoSQLTimeZone::Utc, &data[1..3]) ); @@ -1203,7 +1203,7 @@ mod tests { let array: ArrayRef = Arc::new(arrow::array::StringArray::from(data.clone())); assert_eq!( array - .to_column::(&alloc, &(0..2), Some(&scals)) + .to_column::(&alloc, &(0..2), Some(&scals)) .unwrap(), Column::VarChar((&data[..], &scals[..])) ); @@ -1242,11 +1242,11 @@ mod tests { let data = vec![false, true]; let array: ArrayRef = Arc::new(arrow::array::BooleanArray::from(data.clone())); assert_eq!( - array.to_curve25519_scalars(), + array.to_test_scalars(), Ok(data .iter() .map(core::convert::Into::into) - .collect::>()) + .collect::>()) ); } @@ -1259,11 +1259,11 @@ mod tests { )); assert_eq!( - array.to_curve25519_scalars(), + array.to_test_scalars(), Ok(data .iter() - .map(|&v| Curve25519Scalar::from(v)) - .collect::>()) + .map(|&v| TestScalar::from(v)) + .collect::>()) ); } @@ -1273,31 +1273,31 @@ mod tests { let array: ArrayRef = Arc::new(Int16Array::from(data.clone())); assert_eq!( - array.to_curve25519_scalars(), + array.to_test_scalars(), Ok(data .iter() .map(core::convert::Into::into) - .collect::>()) + .collect::>()) ); let data = vec![1, -3]; let array: ArrayRef = Arc::new(Int32Array::from(data.clone())); assert_eq!( - array.to_curve25519_scalars(), + array.to_test_scalars(), Ok(data .iter() .map(core::convert::Into::into) - .collect::>()) + .collect::>()) ); let data = vec![1, -3]; let array: ArrayRef = Arc::new(Int64Array::from(data.clone())); assert_eq!( - array.to_curve25519_scalars(), + array.to_test_scalars(), Ok(data .iter() .map(core::convert::Into::into) - .collect::>()) + .collect::>()) ); } @@ -1306,11 +1306,11 @@ mod tests { let data = vec!["ab", "-f34"]; let array: ArrayRef = Arc::new(arrow::array::StringArray::from(data.clone())); assert_eq!( - array.to_curve25519_scalars(), + array.to_test_scalars(), Ok(data .iter() .map(core::convert::Into::into) - .collect::>()) + .collect::>()) ); } } diff --git a/crates/proof-of-sql/src/base/database/column.rs b/crates/proof-of-sql/src/base/database/column.rs index b4db556c0..b3b8d2456 100644 --- a/crates/proof-of-sql/src/base/database/column.rs +++ b/crates/proof-of-sql/src/base/database/column.rs @@ -41,7 +41,7 @@ pub enum Column<'a, S: Scalar> { /// i128 columns Int128(&'a [i128]), /// Decimal columns with a max width of 252 bits - /// - the backing store maps to the type [`crate::base::scalar::Curve25519Scalar`] + /// - the backing store maps to the type [`crate::base::scalar::test_scalar::TestScalar`] Decimal75(Precision, i8, &'a [S]), /// Scalar columns Scalar(&'a [S]), @@ -263,7 +263,7 @@ pub enum ColumnType { /// Mapped to i64 #[serde(alias = "TIMESTAMP", alias = "timestamp")] TimestampTZ(PoSQLTimeUnit, PoSQLTimeZone), - /// Mapped to [`Curve25519Scalar`](crate::base::scalar::Curve25519Scalar) + /// Mapped to [`TestScalar`](crate::base::scalar::test_scalar::TestScalar) #[serde(alias = "SCALAR", alias = "scalar")] Scalar, } @@ -584,7 +584,7 @@ impl From<&ColumnField> for Field { #[cfg(test)] mod tests { use super::*; - use crate::{base::scalar::Curve25519Scalar, proof_primitive::dory::DoryScalar}; + use crate::{base::scalar::test_scalar::TestScalar, proof_primitive::dory::DoryScalar}; use alloc::{string::String, vec}; #[test] @@ -897,9 +897,9 @@ mod tests { let scale = 2; let scalar_values = [ - Curve25519Scalar::from(1), - Curve25519Scalar::from(2), - Curve25519Scalar::from(3), + TestScalar::from(1), + TestScalar::from(2), + TestScalar::from(3), ]; // Test non-empty columns @@ -911,15 +911,15 @@ mod tests { assert_eq!(column.len(), 3); assert!(!column.is_empty()); - let column = Column::::SmallInt(&[1, 2, 3]); + let column = Column::::SmallInt(&[1, 2, 3]); assert_eq!(column.len(), 3); assert!(!column.is_empty()); - let column = Column::::Int(&[1, 2, 3]); + let column = Column::::Int(&[1, 2, 3]); assert_eq!(column.len(), 3); assert!(!column.is_empty()); - let column = Column::::BigInt(&[1, 2, 3]); + let column = Column::::BigInt(&[1, 2, 3]); assert_eq!(column.len(), 3); assert!(!column.is_empty()); @@ -936,9 +936,9 @@ mod tests { assert!(!column.is_empty()); let decimal_data = [ - Curve25519Scalar::from(1), - Curve25519Scalar::from(2), - Curve25519Scalar::from(3), + TestScalar::from(1), + TestScalar::from(2), + TestScalar::from(3), ]; let precision = Precision::new(precision).unwrap(); @@ -955,15 +955,15 @@ mod tests { assert_eq!(column.len(), 0); assert!(column.is_empty()); - let column = Column::::SmallInt(&[]); + let column = Column::::SmallInt(&[]); assert_eq!(column.len(), 0); assert!(column.is_empty()); - let column = Column::::Int(&[]); + let column = Column::::Int(&[]); assert_eq!(column.len(), 0); assert!(column.is_empty()); - let column = Column::::BigInt(&[]); + let column = Column::::BigInt(&[]); assert_eq!(column.len(), 0); assert!(column.is_empty()); @@ -971,7 +971,7 @@ mod tests { assert_eq!(column.len(), 0); assert!(column.is_empty()); - let column = Column::::Int128(&[]); + let column = Column::::Int128(&[]); assert_eq!(column.len(), 0); assert!(column.is_empty()); @@ -979,7 +979,7 @@ mod tests { assert_eq!(column.len(), 0); assert!(column.is_empty()); - let column: Column<'_, Curve25519Scalar> = Column::Decimal75(precision, scale, &[]); + let column: Column<'_, TestScalar> = Column::Decimal75(precision, scale, &[]); assert_eq!(column.len(), 0); assert!(column.is_empty()); } @@ -988,16 +988,16 @@ mod tests { fn we_can_convert_owned_columns_to_columns_round_trip() { let alloc = Bump::new(); // Integers - let owned_col: OwnedColumn = OwnedColumn::Int128(vec![1, 2, 3, 4, 5]); - let col = Column::::from_owned_column(&owned_col, &alloc); + let owned_col: OwnedColumn = OwnedColumn::Int128(vec![1, 2, 3, 4, 5]); + let col = Column::::from_owned_column(&owned_col, &alloc); assert_eq!(col, Column::Int128(&[1, 2, 3, 4, 5])); let new_owned_col = (&col).into(); assert_eq!(owned_col, new_owned_col); // Booleans - let owned_col: OwnedColumn = + let owned_col: OwnedColumn = OwnedColumn::Boolean(vec![true, false, true, false, true]); - let col = Column::::from_owned_column(&owned_col, &alloc); + let col = Column::::from_owned_column(&owned_col, &alloc); assert_eq!(col, Column::Boolean(&[true, false, true, false, true])); let new_owned_col = (&col).into(); assert_eq!(owned_col, new_owned_col); @@ -1010,23 +1010,22 @@ mod tests { "Spațiu și Timp", "Spazju u Ħin", ]; - let scalars = strs.iter().map(Curve25519Scalar::from).collect::>(); + let scalars = strs.iter().map(TestScalar::from).collect::>(); let owned_col = OwnedColumn::VarChar( strs.iter() .map(ToString::to_string) .collect::>(), ); - let col = Column::::from_owned_column(&owned_col, &alloc); + let col = Column::::from_owned_column(&owned_col, &alloc); assert_eq!(col, Column::VarChar((&strs, &scalars))); let new_owned_col = (&col).into(); assert_eq!(owned_col, new_owned_col); // Decimals - let scalars: Vec = - [1, 2, 3, 4, 5].iter().map(Curve25519Scalar::from).collect(); - let owned_col: OwnedColumn = + let scalars: Vec = [1, 2, 3, 4, 5].iter().map(TestScalar::from).collect(); + let owned_col: OwnedColumn = OwnedColumn::Decimal75(Precision::new(75).unwrap(), 127, scalars.clone()); - let col = Column::::from_owned_column(&owned_col, &alloc); + let col = Column::::from_owned_column(&owned_col, &alloc); assert_eq!( col, Column::Decimal75(Precision::new(75).unwrap(), 127, &scalars) @@ -1041,19 +1040,19 @@ mod tests { assert_eq!(column.column_type().byte_size(), 1); assert_eq!(column.column_type().bit_size(), 8); - let column = Column::::TinyInt(&[1, 2, 3, 4]); + let column = Column::::TinyInt(&[1, 2, 3, 4]); assert_eq!(column.column_type().byte_size(), 1); assert_eq!(column.column_type().bit_size(), 8); - let column = Column::::SmallInt(&[1, 2, 3, 4]); + let column = Column::::SmallInt(&[1, 2, 3, 4]); assert_eq!(column.column_type().byte_size(), 2); assert_eq!(column.column_type().bit_size(), 16); - let column = Column::::Int(&[1, 2, 3]); + let column = Column::::Int(&[1, 2, 3]); assert_eq!(column.column_type().byte_size(), 4); assert_eq!(column.column_type().bit_size(), 32); - let column = Column::::BigInt(&[1]); + let column = Column::::BigInt(&[1]); assert_eq!(column.column_type().byte_size(), 8); assert_eq!(column.column_type().bit_size(), 64); @@ -1062,9 +1061,9 @@ mod tests { assert_eq!(column.column_type().bit_size(), 128); let scalar_values = [ - Curve25519Scalar::from(1), - Curve25519Scalar::from(2), - Curve25519Scalar::from(3), + TestScalar::from(1), + TestScalar::from(2), + TestScalar::from(3), ]; let column = Column::VarChar((&["a", "b", "c", "d", "e"], &scalar_values)); @@ -1078,9 +1077,9 @@ mod tests { let precision = 10; let scale = 2; let decimal_data = [ - Curve25519Scalar::from(1), - Curve25519Scalar::from(2), - Curve25519Scalar::from(3), + TestScalar::from(1), + TestScalar::from(2), + TestScalar::from(3), ]; let precision = Precision::new(precision).unwrap(); diff --git a/crates/proof-of-sql/src/base/database/column_operation.rs b/crates/proof-of-sql/src/base/database/column_operation.rs index 9a18e8e07..10945b511 100644 --- a/crates/proof-of-sql/src/base/database/column_operation.rs +++ b/crates/proof-of-sql/src/base/database/column_operation.rs @@ -965,7 +965,7 @@ where #[cfg(test)] mod test { use super::*; - use crate::base::scalar::Curve25519Scalar; + use crate::base::scalar::test_scalar::TestScalar; #[test] fn we_can_add_numeric_types() { @@ -1606,7 +1606,7 @@ mod test { let lhs = [1_i8, -2, 3]; let rhs = [100_i8, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::TinyInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); @@ -1617,7 +1617,7 @@ mod test { let lhs = [1_i16, -2, 3]; let rhs = [100_i16, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::SmallInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); @@ -1629,7 +1629,7 @@ mod test { let lhs = [400_i64, -82, -200]; let rhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::BigInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); @@ -1640,11 +1640,11 @@ mod test { // lhs and rhs are both decimals with nonnegative scale let lhs = [4_i16, -80, 230] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -8, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 3); let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); @@ -1655,11 +1655,11 @@ mod test { // lhs is decimal with negative scale and rhs is decimal with nonnegative scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, 150_000, -20000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), 2); @@ -1670,11 +1670,11 @@ mod test { // lhs is decimal with nonnegative scale and rhs is decimal with negative scale let lhs = [71_i64, 150_000, -20000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), 2); let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); @@ -1685,11 +1685,11 @@ mod test { // lhs and rhs are both decimals with negative scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, 150_000, -20000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -50); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), -46); @@ -1700,11 +1700,11 @@ mod test { // lhs and rhs are decimals with extreme differences in scale let lhs = [4_i16, 0, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, 0, -20000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -50); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), 26); @@ -1738,7 +1738,7 @@ mod test { let lhs = [1_i8, -2, 3]; let rhs = [100_i8, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::TinyInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); @@ -1749,7 +1749,7 @@ mod test { let lhs = [1_i16, -2, 3]; let rhs = [100_i16, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::SmallInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); @@ -1761,7 +1761,7 @@ mod test { let lhs = [400_i64, -82, -199]; let rhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::BigInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); @@ -1772,11 +1772,11 @@ mod test { // lhs and rhs are both decimals with nonnegative scale let lhs = [4_i16, -80, 230] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -8, 22] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 3); let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); @@ -1787,11 +1787,11 @@ mod test { // lhs is decimal with negative scale and rhs is decimal with nonnegative scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, 150_000, -30000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), 2); @@ -1802,11 +1802,11 @@ mod test { // lhs is decimal with nonnegative scale and rhs is decimal with negative scale let lhs = [71_i64, 150_000, -19000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), 2); let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); @@ -1817,11 +1817,11 @@ mod test { // lhs and rhs are both decimals with negative scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71000_i64, 150_000, -21000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -50); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), -46); @@ -1832,11 +1832,11 @@ mod test { // lhs and rhs are decimals with extreme differences in scale let lhs = [1_i16, 1, 1, 0, 0, 0, -1, -1, -1] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [1_i64, 0, -1, 1, 0, -1, 1, 0, -1] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -50); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), 26); @@ -1870,7 +1870,7 @@ mod test { let lhs = [1_i8, -2, 3]; let rhs = [100_i8, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::TinyInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); @@ -1881,7 +1881,7 @@ mod test { let lhs = [1_i16, -2, 3]; let rhs = [100_i16, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::SmallInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); @@ -1893,7 +1893,7 @@ mod test { let lhs = [400_i64, -82, 199]; let rhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::BigInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); @@ -1904,11 +1904,11 @@ mod test { // lhs and rhs are both decimals with nonnegative scale let lhs = [4_i16, -80, 230] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -8, -22] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 3); let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); @@ -1919,11 +1919,11 @@ mod test { // lhs is decimal with negative scale and rhs is decimal with nonnegative scale let lhs = [-4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, 150_000, -30000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), 2); @@ -1934,11 +1934,11 @@ mod test { // lhs is decimal with nonnegative scale and rhs is decimal with negative scale let lhs = [71_i64, 150_000, -19000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), 2); let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); @@ -1949,11 +1949,11 @@ mod test { // lhs and rhs are both decimals with negative scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71000_i64, 150_000, -21000] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -50); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), -46); @@ -1964,11 +1964,11 @@ mod test { // lhs and rhs are decimals with extreme differences in scale let lhs = [1_i16, 1, 1, 0, 0, 0, -1, -1, -1] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [1_i64, 0, -1, 1, 0, -1, 1, 0, -1] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -50); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), 26); @@ -2022,16 +2022,16 @@ mod test { let lhs = [1_i8, -2, 3]; let rhs = [4_i8, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::TinyInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_add_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(104), - Curve25519Scalar::from(-195), - Curve25519Scalar::from(298), + TestScalar::from(104), + TestScalar::from(-195), + TestScalar::from(298), ]; let expected = (Precision::new(11).unwrap(), 2, expected_scalars); assert_eq!(expected, actual); @@ -2039,16 +2039,16 @@ mod test { let lhs = [1_i16, -2, 3]; let rhs = [4_i16, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::SmallInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_add_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(104), - Curve25519Scalar::from(-195), - Curve25519Scalar::from(298), + TestScalar::from(104), + TestScalar::from(-195), + TestScalar::from(298), ]; let expected = (Precision::new(11).unwrap(), 2, expected_scalars); assert_eq!(expected, actual); @@ -2056,17 +2056,17 @@ mod test { // lhs is decimal with negative scale and rhs is integer let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23]; let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); let right_column_type = ColumnType::BigInt; - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_add_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(471), - Curve25519Scalar::from(1418), - Curve25519Scalar::from(-177), + TestScalar::from(471), + TestScalar::from(1418), + TestScalar::from(-177), ]; let expected = (Precision::new(20).unwrap(), 0, expected_scalars); assert_eq!(expected, actual); @@ -2074,20 +2074,20 @@ mod test { // lhs and rhs are both decimals with nonnegative scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(12).unwrap(), 2); let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 3); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_add_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(111), - Curve25519Scalar::from(68), - Curve25519Scalar::from(3), + TestScalar::from(111), + TestScalar::from(68), + TestScalar::from(3), ]; let expected = (Precision::new(14).unwrap(), 3, expected_scalars); assert_eq!(expected, actual); @@ -2096,20 +2096,20 @@ mod test { // and with result having maximum precision let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(69).unwrap(), -2); let right_column_type = ColumnType::Decimal75(Precision::new(50).unwrap(), 3); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_add_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(400_071), - Curve25519Scalar::from(1_499_918), - Curve25519Scalar::from(-199_977), + TestScalar::from(400_071), + TestScalar::from(1_499_918), + TestScalar::from(-199_977), ]; let expected = (Precision::new(75).unwrap(), 3, expected_scalars); assert_eq!(expected, actual); @@ -2118,20 +2118,20 @@ mod test { // and with result having maximum precision and minimum scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(74).unwrap(), -128); let right_column_type = ColumnType::Decimal75(Precision::new(74).unwrap(), -128); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_add_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(75), - Curve25519Scalar::from(-67), - Curve25519Scalar::from(21), + TestScalar::from(75), + TestScalar::from(-67), + TestScalar::from(21), ]; let expected = (Precision::new(75).unwrap(), -128, expected_scalars); assert_eq!(expected, actual); @@ -2201,16 +2201,16 @@ mod test { let lhs = [1_i8, -2, 3]; let rhs = [4_i8, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::TinyInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_subtract_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(96), - Curve25519Scalar::from(-205), - Curve25519Scalar::from(302), + TestScalar::from(96), + TestScalar::from(-205), + TestScalar::from(302), ]; let expected = (Precision::new(11).unwrap(), 2, expected_scalars); assert_eq!(expected, actual); @@ -2218,16 +2218,16 @@ mod test { let lhs = [1_i16, -2, 3]; let rhs = [4_i16, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::SmallInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_subtract_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(96), - Curve25519Scalar::from(-205), - Curve25519Scalar::from(302), + TestScalar::from(96), + TestScalar::from(-205), + TestScalar::from(302), ]; let expected = (Precision::new(11).unwrap(), 2, expected_scalars); assert_eq!(expected, actual); @@ -2235,17 +2235,17 @@ mod test { // lhs is decimal with negative scale and rhs is integer let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23]; let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); let right_column_type = ColumnType::BigInt; - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_subtract_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(329), - Curve25519Scalar::from(1582), - Curve25519Scalar::from(-223), + TestScalar::from(329), + TestScalar::from(1582), + TestScalar::from(-223), ]; let expected = (Precision::new(20).unwrap(), 0, expected_scalars); assert_eq!(expected, actual); @@ -2253,20 +2253,20 @@ mod test { // lhs and rhs are both decimals with nonnegative scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(12).unwrap(), 2); let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 3); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_subtract_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(-31), - Curve25519Scalar::from(232), - Curve25519Scalar::from(-43), + TestScalar::from(-31), + TestScalar::from(232), + TestScalar::from(-43), ]; let expected = (Precision::new(14).unwrap(), 3, expected_scalars); assert_eq!(expected, actual); @@ -2275,20 +2275,20 @@ mod test { // and with result having maximum precision let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(69).unwrap(), -2); let right_column_type = ColumnType::Decimal75(Precision::new(50).unwrap(), 3); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_subtract_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(399_929), - Curve25519Scalar::from(1_500_082), - Curve25519Scalar::from(-200_023), + TestScalar::from(399_929), + TestScalar::from(1_500_082), + TestScalar::from(-200_023), ]; let expected = (Precision::new(75).unwrap(), 3, expected_scalars); assert_eq!(expected, actual); @@ -2297,20 +2297,20 @@ mod test { // and with result having maximum precision and minimum scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(74).unwrap(), -128); let right_column_type = ColumnType::Decimal75(Precision::new(74).unwrap(), -128); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_subtract_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(-67), - Curve25519Scalar::from(97), - Curve25519Scalar::from(-25), + TestScalar::from(-67), + TestScalar::from(97), + TestScalar::from(-25), ]; let expected = (Precision::new(75).unwrap(), -128, expected_scalars); assert_eq!(expected, actual); @@ -2361,16 +2361,16 @@ mod test { let lhs = [1_i8, -2, 3]; let rhs = [4_i8, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::TinyInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_multiply_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(4), - Curve25519Scalar::from(-10), - Curve25519Scalar::from(-6), + TestScalar::from(4), + TestScalar::from(-10), + TestScalar::from(-6), ]; let expected = (Precision::new(14).unwrap(), 2, expected_scalars); assert_eq!(expected, actual); @@ -2378,16 +2378,16 @@ mod test { let lhs = [1_i16, -2, 3]; let rhs = [4_i16, 5, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::SmallInt; let right_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), 2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_multiply_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(4), - Curve25519Scalar::from(-10), - Curve25519Scalar::from(-6), + TestScalar::from(4), + TestScalar::from(-10), + TestScalar::from(-6), ]; let expected = (Precision::new(16).unwrap(), 2, expected_scalars); assert_eq!(expected, actual); @@ -2395,17 +2395,17 @@ mod test { // lhs is decimal with negative scale and rhs is integer let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23]; let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); let right_column_type = ColumnType::BigInt; - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_multiply_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(284), - Curve25519Scalar::from(-1230), - Curve25519Scalar::from(-46), + TestScalar::from(284), + TestScalar::from(-1230), + TestScalar::from(-46), ]; let expected = (Precision::new(30).unwrap(), -2, expected_scalars); assert_eq!(expected, actual); @@ -2414,20 +2414,20 @@ mod test { // and with result having maximum precision and maximum scale let lhs = [4_i16, 25, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(42).unwrap(), 72); let right_column_type = ColumnType::Decimal75(Precision::new(32).unwrap(), 55); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_multiply_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(284), - Curve25519Scalar::from(-2050), - Curve25519Scalar::from(-46), + TestScalar::from(284), + TestScalar::from(-2050), + TestScalar::from(-46), ]; let expected = (Precision::new(75).unwrap(), 127, expected_scalars); assert_eq!(expected, actual); @@ -2436,20 +2436,20 @@ mod test { // and with result having maximum precision let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(69).unwrap(), -2); let right_column_type = ColumnType::Decimal75(Precision::new(5).unwrap(), 3); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_multiply_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(284), - Curve25519Scalar::from(-1230), - Curve25519Scalar::from(-46), + TestScalar::from(284), + TestScalar::from(-1230), + TestScalar::from(-46), ]; let expected = (Precision::new(75).unwrap(), 1, expected_scalars); assert_eq!(expected, actual); @@ -2458,20 +2458,20 @@ mod test { // and with result having maximum precision and minimum scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(34).unwrap(), -64); let right_column_type = ColumnType::Decimal75(Precision::new(40).unwrap(), -64); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_multiply_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(284), - Curve25519Scalar::from(-1230), - Curve25519Scalar::from(-46), + TestScalar::from(284), + TestScalar::from(-1230), + TestScalar::from(-46), ]; let expected = (Precision::new(75).unwrap(), -128, expected_scalars); assert_eq!(expected, actual); @@ -2541,16 +2541,16 @@ mod test { let lhs = [0_i8, 2, 3]; let rhs = [4_i8, 5, 2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::TinyInt; let right_column_type = ColumnType::Decimal75(Precision::new(3).unwrap(), 2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_divide_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(0_i64), - Curve25519Scalar::from(40_000_000_i64), - Curve25519Scalar::from(150_000_000_i64), + TestScalar::from(0_i64), + TestScalar::from(40_000_000_i64), + TestScalar::from(150_000_000_i64), ]; let expected = (Precision::new(11).unwrap(), 6, expected_scalars); assert_eq!(expected, actual); @@ -2558,16 +2558,16 @@ mod test { let lhs = [0_i16, 2, 3]; let rhs = [4_i16, 5, 2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::SmallInt; let right_column_type = ColumnType::Decimal75(Precision::new(3).unwrap(), 2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_divide_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(0_i64), - Curve25519Scalar::from(40_000_000_i64), - Curve25519Scalar::from(150_000_000_i64), + TestScalar::from(0_i64), + TestScalar::from(40_000_000_i64), + TestScalar::from(150_000_000_i64), ]; let expected = (Precision::new(13).unwrap(), 6, expected_scalars); assert_eq!(expected, actual); @@ -2575,34 +2575,34 @@ mod test { // lhs is decimal with negative scale and rhs is integer let lhs = [4_i8, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23]; let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); let right_column_type = ColumnType::TinyInt; - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_divide_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(5_633_802), - Curve25519Scalar::from(-18_292_682), - Curve25519Scalar::from(-8_695_652), + TestScalar::from(5_633_802), + TestScalar::from(-18_292_682), + TestScalar::from(-8_695_652), ]; let expected = (Precision::new(18).unwrap(), 6, expected_scalars); assert_eq!(expected, actual); let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23]; let left_column_type = ColumnType::Decimal75(Precision::new(10).unwrap(), -2); let right_column_type = ColumnType::SmallInt; - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_divide_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(5_633_802), - Curve25519Scalar::from(-18_292_682), - Curve25519Scalar::from(-8_695_652), + TestScalar::from(5_633_802), + TestScalar::from(-18_292_682), + TestScalar::from(-8_695_652), ]; let expected = (Precision::new(18).unwrap(), 6, expected_scalars); assert_eq!(expected, actual); @@ -2610,20 +2610,20 @@ mod test { // lhs and rhs are both decimals with nonnegative scale let lhs = [4_i16, 2, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [3_i64, -5, 7] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(4).unwrap(), 2); let right_column_type = ColumnType::Decimal75(Precision::new(3).unwrap(), 2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_divide_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(1_333_333), - Curve25519Scalar::from(-400_000), - Curve25519Scalar::from(-285_714), + TestScalar::from(1_333_333), + TestScalar::from(-400_000), + TestScalar::from(-285_714), ]; let expected = (Precision::new(10).unwrap(), 6, expected_scalars); assert_eq!(expected, actual); @@ -2631,20 +2631,20 @@ mod test { // lhs and rhs are both decimals one of which has negative scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(2).unwrap(), -2); let right_column_type = ColumnType::Decimal75(Precision::new(3).unwrap(), 3); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_divide_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(5_633_802_816_i128), - Curve25519Scalar::from(-18_292_682_926_i128), - Curve25519Scalar::from(-8_695_652_173_i128), + TestScalar::from(5_633_802_816_i128), + TestScalar::from(-18_292_682_926_i128), + TestScalar::from(-8_695_652_173_i128), ]; let expected = (Precision::new(13).unwrap(), 6, expected_scalars); assert_eq!(expected, actual); @@ -2652,20 +2652,20 @@ mod test { // lhs and rhs are both decimals with negative scale let lhs = [4_i16, 15, -2] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let rhs = [71_i64, -82, 23] .into_iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let left_column_type = ColumnType::Decimal75(Precision::new(2).unwrap(), -3); let right_column_type = ColumnType::Decimal75(Precision::new(3).unwrap(), -2); - let actual: (Precision, i8, Vec) = + let actual: (Precision, i8, Vec) = try_divide_decimal_columns(&lhs, &rhs, left_column_type, right_column_type).unwrap(); let expected_scalars = vec![ - Curve25519Scalar::from(563_380), - Curve25519Scalar::from(-1_829_268), - Curve25519Scalar::from(-869_565), + TestScalar::from(563_380), + TestScalar::from(-1_829_268), + TestScalar::from(-869_565), ]; let expected = (Precision::new(9).unwrap(), 6, expected_scalars); assert_eq!(expected, actual); diff --git a/crates/proof-of-sql/src/base/database/owned_column.rs b/crates/proof-of-sql/src/base/database/owned_column.rs index cb5cc30f8..0319c3796 100644 --- a/crates/proof-of-sql/src/base/database/owned_column.rs +++ b/crates/proof-of-sql/src/base/database/owned_column.rs @@ -360,20 +360,20 @@ pub(crate) fn compare_indexes_by_owned_columns_with_direction( #[cfg(test)] mod test { use super::*; - use crate::base::{math::decimal::Precision, scalar::Curve25519Scalar}; + use crate::base::{math::decimal::Precision, scalar::test_scalar::TestScalar}; use alloc::vec; use bumpalo::Bump; use proof_of_sql_parser::intermediate_ast::OrderByDirection; #[test] fn we_can_slice_a_column() { - let col: OwnedColumn = OwnedColumn::Int128(vec![1, 2, 3, 4, 5]); + let col: OwnedColumn = OwnedColumn::Int128(vec![1, 2, 3, 4, 5]); assert_eq!(col.slice(1, 4), OwnedColumn::Int128(vec![2, 3, 4])); } #[test] fn we_can_permute_a_column() { - let col: OwnedColumn = OwnedColumn::Int128(vec![1, 2, 3, 4, 5]); + let col: OwnedColumn = OwnedColumn::Int128(vec![1, 2, 3, 4, 5]); let permutation = Permutation::try_new(vec![1, 3, 4, 0, 2]).unwrap(); assert_eq!( col.try_permute(&permutation).unwrap(), @@ -383,19 +383,19 @@ mod test { #[test] fn we_can_compare_columns() { - let col1: OwnedColumn = OwnedColumn::SmallInt(vec![1, 1, 2, 1, 1]); - let col2: OwnedColumn = OwnedColumn::VarChar( + let col1: OwnedColumn = OwnedColumn::SmallInt(vec![1, 1, 2, 1, 1]); + let col2: OwnedColumn = OwnedColumn::VarChar( ["b", "b", "a", "b", "a"] .iter() .map(ToString::to_string) .collect(), ); - let col3: OwnedColumn = OwnedColumn::Decimal75( + let col3: OwnedColumn = OwnedColumn::Decimal75( Precision::new(70).unwrap(), 20, [1, 2, 2, 1, 2] .iter() - .map(|&i| Curve25519Scalar::from(i)) + .map(|&i| TestScalar::from(i)) .collect(), ); let order_by_pairs = vec![ @@ -429,20 +429,20 @@ mod test { fn we_can_convert_columns_to_owned_columns_round_trip() { let alloc = Bump::new(); // Integers - let col: Column<'_, Curve25519Scalar> = Column::Int128(&[1, 2, 3, 4, 5]); - let owned_col: OwnedColumn = (&col).into(); + let col: Column<'_, TestScalar> = Column::Int128(&[1, 2, 3, 4, 5]); + let owned_col: OwnedColumn = (&col).into(); assert_eq!(owned_col, OwnedColumn::Int128(vec![1, 2, 3, 4, 5])); - let new_col = Column::::from_owned_column(&owned_col, &alloc); + let new_col = Column::::from_owned_column(&owned_col, &alloc); assert_eq!(col, new_col); // Booleans - let col: Column<'_, Curve25519Scalar> = Column::Boolean(&[true, false, true, false, true]); - let owned_col: OwnedColumn = (&col).into(); + let col: Column<'_, TestScalar> = Column::Boolean(&[true, false, true, false, true]); + let owned_col: OwnedColumn = (&col).into(); assert_eq!( owned_col, OwnedColumn::Boolean(vec![true, false, true, false, true]) ); - let new_col = Column::::from_owned_column(&owned_col, &alloc); + let new_col = Column::::from_owned_column(&owned_col, &alloc); assert_eq!(col, new_col); // Strings @@ -454,9 +454,9 @@ mod test { "ቦታ እና ጊዜ", "სივრცე და დრო", ]; - let scalars = strs.iter().map(Curve25519Scalar::from).collect::>(); - let col: Column<'_, Curve25519Scalar> = Column::VarChar((&strs, &scalars)); - let owned_col: OwnedColumn = (&col).into(); + let scalars = strs.iter().map(TestScalar::from).collect::>(); + let col: Column<'_, TestScalar> = Column::VarChar((&strs, &scalars)); + let owned_col: OwnedColumn = (&col).into(); assert_eq!( owned_col, OwnedColumn::VarChar( @@ -465,20 +465,19 @@ mod test { .collect::>() ) ); - let new_col = Column::::from_owned_column(&owned_col, &alloc); + let new_col = Column::::from_owned_column(&owned_col, &alloc); assert_eq!(col, new_col); // Decimals - let scalars: Vec = - [1, 2, 3, 4, 5].iter().map(Curve25519Scalar::from).collect(); - let col: Column<'_, Curve25519Scalar> = + let scalars: Vec = [1, 2, 3, 4, 5].iter().map(TestScalar::from).collect(); + let col: Column<'_, TestScalar> = Column::Decimal75(Precision::new(75).unwrap(), -128, &scalars); - let owned_col: OwnedColumn = (&col).into(); + let owned_col: OwnedColumn = (&col).into(); assert_eq!( owned_col, OwnedColumn::Decimal75(Precision::new(75).unwrap(), -128, scalars.clone()) ); - let new_col = Column::::from_owned_column(&owned_col, &alloc); + let new_col = Column::::from_owned_column(&owned_col, &alloc); assert_eq!(col, new_col); } @@ -487,7 +486,7 @@ mod test { // Int let scalars = [1, 2, 3, 4, 5] .iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let column_type = ColumnType::Int128; let owned_col = OwnedColumn::try_from_scalars(&scalars, column_type).unwrap(); @@ -496,7 +495,7 @@ mod test { // Boolean let scalars = [true, false, true, false, true] .iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let column_type = ColumnType::Boolean; let owned_col = OwnedColumn::try_from_scalars(&scalars, column_type).unwrap(); @@ -508,7 +507,7 @@ mod test { // Decimal let scalars = [1, 2, 3, 4, 5] .iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let column_type = ColumnType::Decimal75(Precision::new(75).unwrap(), -128); let owned_col = OwnedColumn::try_from_scalars(&scalars, column_type).unwrap(); @@ -522,7 +521,7 @@ mod test { fn we_cannot_convert_scalars_to_owned_columns_if_varchar() { let scalars = ["a", "b", "c", "d", "e"] .iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let column_type = ColumnType::VarChar; let res = OwnedColumn::try_from_scalars(&scalars, column_type); @@ -534,7 +533,7 @@ mod test { // Int let scalars = [i128::MAX, i128::MAX, i128::MAX, i128::MAX, i128::MAX] .iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let column_type = ColumnType::BigInt; let res = OwnedColumn::try_from_scalars(&scalars, column_type); @@ -546,7 +545,7 @@ mod test { // Boolean let scalars = [i128::MAX, i128::MAX, i128::MAX, i128::MAX, i128::MAX] .iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect::>(); let column_type = ColumnType::Boolean; let res = OwnedColumn::try_from_scalars(&scalars, column_type); @@ -561,7 +560,7 @@ mod test { // Int let option_scalars = [Some(1), Some(2), Some(3), Some(4), Some(5)] .iter() - .map(|s| s.map(Curve25519Scalar::from)) + .map(|s| s.map(TestScalar::from)) .collect::>(); let column_type = ColumnType::Int128; let owned_col = OwnedColumn::try_from_option_scalars(&option_scalars, column_type).unwrap(); @@ -570,7 +569,7 @@ mod test { // Boolean let option_scalars = [Some(true), Some(false), Some(true), Some(false), Some(true)] .iter() - .map(|s| s.map(Curve25519Scalar::from)) + .map(|s| s.map(TestScalar::from)) .collect::>(); let column_type = ColumnType::Boolean; let owned_col = OwnedColumn::try_from_option_scalars(&option_scalars, column_type).unwrap(); @@ -582,11 +581,11 @@ mod test { // Decimal let option_scalars = [Some(1), Some(2), Some(3), Some(4), Some(5)] .iter() - .map(|s| s.map(Curve25519Scalar::from)) + .map(|s| s.map(TestScalar::from)) .collect::>(); let scalars = [1, 2, 3, 4, 5] .iter() - .map(|&i| Curve25519Scalar::from(i)) + .map(|&i| TestScalar::from(i)) .collect::>(); let column_type = ColumnType::Decimal75(Precision::new(75).unwrap(), 127); let owned_col = OwnedColumn::try_from_option_scalars(&option_scalars, column_type).unwrap(); @@ -600,7 +599,7 @@ mod test { fn we_cannot_convert_option_scalars_to_owned_columns_if_varchar() { let option_scalars = ["a", "b", "c", "d", "e"] .iter() - .map(|s| Some(Curve25519Scalar::from(*s))) + .map(|s| Some(TestScalar::from(*s))) .collect::>(); let column_type = ColumnType::VarChar; let res = OwnedColumn::try_from_option_scalars(&option_scalars, column_type); @@ -618,7 +617,7 @@ mod test { Some(i128::MAX), ] .iter() - .map(|s| s.map(Curve25519Scalar::from)) + .map(|s| s.map(TestScalar::from)) .collect::>(); let column_type = ColumnType::BigInt; let res = OwnedColumn::try_from_option_scalars(&option_scalars, column_type); @@ -636,7 +635,7 @@ mod test { Some(i128::MAX), ] .iter() - .map(|s| s.map(Curve25519Scalar::from)) + .map(|s| s.map(TestScalar::from)) .collect::>(); let column_type = ColumnType::Boolean; let res = OwnedColumn::try_from_option_scalars(&option_scalars, column_type); @@ -651,7 +650,7 @@ mod test { // Int let option_scalars = [Some(1), Some(2), None, Some(4), Some(5)] .iter() - .map(|s| s.map(Curve25519Scalar::from)) + .map(|s| s.map(TestScalar::from)) .collect::>(); let column_type = ColumnType::Int128; let res = OwnedColumn::try_from_option_scalars(&option_scalars, column_type); @@ -660,7 +659,7 @@ mod test { // Boolean let option_scalars = [Some(true), Some(false), None, Some(false), Some(true)] .iter() - .map(|s| s.map(Curve25519Scalar::from)) + .map(|s| s.map(TestScalar::from)) .collect::>(); let column_type = ColumnType::Boolean; let res = OwnedColumn::try_from_option_scalars(&option_scalars, column_type); diff --git a/crates/proof-of-sql/src/base/database/owned_column_operation.rs b/crates/proof-of-sql/src/base/database/owned_column_operation.rs index 1fba3f1dc..502be3456 100644 --- a/crates/proof-of-sql/src/base/database/owned_column_operation.rs +++ b/crates/proof-of-sql/src/base/database/owned_column_operation.rs @@ -1395,12 +1395,12 @@ impl Div for OwnedColumn { #[cfg(test)] mod test { use super::*; - use crate::base::{math::decimal::Precision, scalar::Curve25519Scalar}; + use crate::base::{math::decimal::Precision, scalar::test_scalar::TestScalar}; #[test] fn we_cannot_do_binary_operation_on_columns_with_different_lengths() { - let lhs = OwnedColumn::::Boolean(vec![true, false, true]); - let rhs = OwnedColumn::::Boolean(vec![true, false]); + let lhs = OwnedColumn::::Boolean(vec![true, false, true]); + let rhs = OwnedColumn::::Boolean(vec![true, false]); let result = lhs.element_wise_and(&rhs); assert!(matches!( @@ -1426,16 +1426,16 @@ mod test { Err(ColumnOperationError::DifferentColumnLength { .. }) )); - let lhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); - let rhs = OwnedColumn::::TinyInt(vec![1, 2]); + let lhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); + let rhs = OwnedColumn::::TinyInt(vec![1, 2]); let result = lhs.clone() + rhs.clone(); assert!(matches!( result, Err(ColumnOperationError::DifferentColumnLength { .. }) )); - let lhs = OwnedColumn::::SmallInt(vec![1, 2, 3]); - let rhs = OwnedColumn::::SmallInt(vec![1, 2]); + let lhs = OwnedColumn::::SmallInt(vec![1, 2, 3]); + let rhs = OwnedColumn::::SmallInt(vec![1, 2]); let result = lhs.clone() + rhs.clone(); assert!(matches!( result, @@ -1463,8 +1463,8 @@ mod test { #[test] fn we_cannot_do_logical_operation_on_nonboolean_columns() { - let lhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); - let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); + let lhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); + let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); let result = lhs.element_wise_and(&rhs); assert!(matches!( result, @@ -1483,8 +1483,8 @@ mod test { Err(ColumnOperationError::UnaryOperationInvalidColumnType { .. }) )); - let lhs = OwnedColumn::::Int(vec![1, 2, 3]); - let rhs = OwnedColumn::::Int(vec![1, 2, 3]); + let lhs = OwnedColumn::::Int(vec![1, 2, 3]); + let rhs = OwnedColumn::::Int(vec![1, 2, 3]); let result = lhs.element_wise_and(&rhs); assert!(matches!( result, @@ -1506,12 +1506,12 @@ mod test { #[test] fn we_can_do_logical_operation_on_boolean_columns() { - let lhs = OwnedColumn::::Boolean(vec![true, false, true, false]); - let rhs = OwnedColumn::::Boolean(vec![true, true, false, false]); + let lhs = OwnedColumn::::Boolean(vec![true, false, true, false]); + let rhs = OwnedColumn::::Boolean(vec![true, true, false, false]); let result = lhs.element_wise_and(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ + Ok(OwnedColumn::::Boolean(vec![ true, false, false, false ])) ); @@ -1519,7 +1519,7 @@ mod test { let result = lhs.element_wise_or(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ + Ok(OwnedColumn::::Boolean(vec![ true, true, true, false ])) ); @@ -1527,7 +1527,7 @@ mod test { let result = lhs.element_wise_not(); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ + Ok(OwnedColumn::::Boolean(vec![ false, true, false, true ])) ); @@ -1536,34 +1536,30 @@ mod test { #[test] fn we_can_do_eq_operation() { // Integers - let lhs = OwnedColumn::::SmallInt(vec![1, 3, 2]); - let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); + let lhs = OwnedColumn::::SmallInt(vec![1, 3, 2]); + let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); let result = lhs.element_wise_eq(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, false])) ); - let lhs = OwnedColumn::::Int(vec![1, 3, 2]); - let rhs = OwnedColumn::::SmallInt(vec![1, 2, 3]); + let lhs = OwnedColumn::::Int(vec![1, 3, 2]); + let rhs = OwnedColumn::::SmallInt(vec![1, 2, 3]); let result = lhs.element_wise_eq(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, false])) ); // Strings - let lhs = OwnedColumn::::VarChar( + let lhs = OwnedColumn::::VarChar( ["Space", "and", "Time"] .iter() .map(ToString::to_string) .collect(), ); - let rhs = OwnedColumn::::VarChar( + let rhs = OwnedColumn::::VarChar( ["Space", "and", "time"] .iter() .map(ToString::to_string) @@ -1572,218 +1568,172 @@ mod test { let result = lhs.element_wise_eq(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, true, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, true, false])) ); // Booleans - let lhs = OwnedColumn::::Boolean(vec![true, false, true]); - let rhs = OwnedColumn::::Boolean(vec![true, true, false]); + let lhs = OwnedColumn::::Boolean(vec![true, false, true]); + let rhs = OwnedColumn::::Boolean(vec![true, true, false]); let result = lhs.element_wise_eq(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, false])) ); // Decimals - let lhs_scalars = [10, 2, 30].iter().map(Curve25519Scalar::from).collect(); - let rhs_scalars = [1, 2, -3].iter().map(Curve25519Scalar::from).collect(); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 3, lhs_scalars); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs_scalars = [10, 2, 30].iter().map(TestScalar::from).collect(); + let rhs_scalars = [1, 2, -3].iter().map(TestScalar::from).collect(); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 3, lhs_scalars); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = lhs.element_wise_eq(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, false])) ); // Decimals and integers - let lhs_scalars = [10, 2, 30].iter().map(Curve25519Scalar::from).collect(); - let rhs = OwnedColumn::::TinyInt(vec![1, -2, 3]); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 1, lhs_scalars); + let lhs_scalars = [10, 2, 30].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::TinyInt(vec![1, -2, 3]); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 1, lhs_scalars); let result = lhs.element_wise_eq(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, true - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, true])) ); - let lhs_scalars = [10, 2, 30].iter().map(Curve25519Scalar::from).collect(); - let rhs = OwnedColumn::::Int(vec![1, -2, 3]); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 1, lhs_scalars); + let lhs_scalars = [10, 2, 30].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Int(vec![1, -2, 3]); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 1, lhs_scalars); let result = lhs.element_wise_eq(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, true - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, true])) ); } #[test] fn we_can_do_le_operation_on_numeric_and_boolean_columns() { // Booleans - let lhs = OwnedColumn::::Boolean(vec![true, false, true]); - let rhs = OwnedColumn::::Boolean(vec![true, true, false]); + let lhs = OwnedColumn::::Boolean(vec![true, false, true]); + let rhs = OwnedColumn::::Boolean(vec![true, true, false]); let result = lhs.element_wise_le(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, true, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, true, false])) ); // Integers - let lhs = OwnedColumn::::SmallInt(vec![1, 3, 2]); - let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); + let lhs = OwnedColumn::::SmallInt(vec![1, 3, 2]); + let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); let result = lhs.element_wise_le(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, true - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, true])) ); - let lhs = OwnedColumn::::Int(vec![1, 3, 2]); - let rhs = OwnedColumn::::SmallInt(vec![1, 2, 3]); + let lhs = OwnedColumn::::Int(vec![1, 3, 2]); + let rhs = OwnedColumn::::SmallInt(vec![1, 2, 3]); let result = lhs.element_wise_le(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, true - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, true])) ); // Decimals - let lhs_scalars = [10, 2, 30].iter().map(Curve25519Scalar::from).collect(); - let rhs_scalars = [1, 24, -3].iter().map(Curve25519Scalar::from).collect(); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 3, lhs_scalars); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs_scalars = [10, 2, 30].iter().map(TestScalar::from).collect(); + let rhs_scalars = [1, 24, -3].iter().map(TestScalar::from).collect(); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 3, lhs_scalars); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = lhs.element_wise_le(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, true, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, true, false])) ); // Decimals and integers - let lhs_scalars = [10, -2, -30].iter().map(Curve25519Scalar::from).collect(); - let rhs = OwnedColumn::::TinyInt(vec![1, -20, 3]); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), -1, lhs_scalars); + let lhs_scalars = [10, -2, -30].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::TinyInt(vec![1, -20, 3]); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), -1, lhs_scalars); let result = lhs.element_wise_le(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - false, true, true - ])) + Ok(OwnedColumn::::Boolean(vec![false, true, true])) ); - let lhs_scalars = [10, -2, -30].iter().map(Curve25519Scalar::from).collect(); - let rhs = OwnedColumn::::Int(vec![1, -20, 3]); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), -1, lhs_scalars); + let lhs_scalars = [10, -2, -30].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Int(vec![1, -20, 3]); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), -1, lhs_scalars); let result = lhs.element_wise_le(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - false, true, true - ])) + Ok(OwnedColumn::::Boolean(vec![false, true, true])) ); } #[test] fn we_can_do_ge_operation_on_numeric_and_boolean_columns() { // Booleans - let lhs = OwnedColumn::::Boolean(vec![true, false, true]); - let rhs = OwnedColumn::::Boolean(vec![true, true, false]); + let lhs = OwnedColumn::::Boolean(vec![true, false, true]); + let rhs = OwnedColumn::::Boolean(vec![true, true, false]); let result = lhs.element_wise_ge(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, true - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, true])) ); // Integers - let lhs = OwnedColumn::::SmallInt(vec![1, 3, 2]); - let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); + let lhs = OwnedColumn::::SmallInt(vec![1, 3, 2]); + let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); let result = lhs.element_wise_ge(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, true, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, true, false])) ); - let lhs = OwnedColumn::::Int(vec![1, 3, 2]); - let rhs = OwnedColumn::::SmallInt(vec![1, 2, 3]); + let lhs = OwnedColumn::::Int(vec![1, 3, 2]); + let rhs = OwnedColumn::::SmallInt(vec![1, 2, 3]); let result = lhs.element_wise_ge(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, true, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, true, false])) ); // Decimals - let lhs_scalars = [10, 2, 30].iter().map(Curve25519Scalar::from).collect(); - let rhs_scalars = [1, 24, -3].iter().map(Curve25519Scalar::from).collect(); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 3, lhs_scalars); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs_scalars = [10, 2, 30].iter().map(TestScalar::from).collect(); + let rhs_scalars = [1, 24, -3].iter().map(TestScalar::from).collect(); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 3, lhs_scalars); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = lhs.element_wise_ge(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, false, true - ])) + Ok(OwnedColumn::::Boolean(vec![true, false, true])) ); // Decimals and integers - let lhs_scalars = [10, -2, -30].iter().map(Curve25519Scalar::from).collect(); - let rhs = OwnedColumn::::TinyInt(vec![1_i8, -20, 3]); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), -1, lhs_scalars); + let lhs_scalars = [10, -2, -30].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::TinyInt(vec![1_i8, -20, 3]); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), -1, lhs_scalars); let result = lhs.element_wise_ge(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, true, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, true, false])) ); - let lhs_scalars = [10, -2, -30].iter().map(Curve25519Scalar::from).collect(); - let rhs = OwnedColumn::::BigInt(vec![1_i64, -20, 3]); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), -1, lhs_scalars); + let lhs_scalars = [10, -2, -30].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::BigInt(vec![1_i64, -20, 3]); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), -1, lhs_scalars); let result = lhs.element_wise_ge(&rhs); assert_eq!( result, - Ok(OwnedColumn::::Boolean(vec![ - true, true, false - ])) + Ok(OwnedColumn::::Boolean(vec![true, true, false])) ); } #[test] fn we_cannot_do_comparison_on_columns_with_incompatible_types() { // Strings can't be compared with other types - let lhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); - let rhs = OwnedColumn::::VarChar( + let lhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); + let rhs = OwnedColumn::::VarChar( ["Space", "and", "Time"] .iter() .map(ToString::to_string) @@ -1795,8 +1745,8 @@ mod test { Err(ColumnOperationError::BinaryOperationInvalidColumnType { .. }) )); - let lhs = OwnedColumn::::Int(vec![1, 2, 3]); - let rhs = OwnedColumn::::VarChar( + let lhs = OwnedColumn::::Int(vec![1, 2, 3]); + let rhs = OwnedColumn::::VarChar( ["Space", "and", "Time"] .iter() .map(ToString::to_string) @@ -1821,16 +1771,16 @@ mod test { )); // Booleans can't be compared with other types - let lhs = OwnedColumn::::Boolean(vec![true, false, true]); - let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); + let lhs = OwnedColumn::::Boolean(vec![true, false, true]); + let rhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); let result = lhs.element_wise_le(&rhs); assert!(matches!( result, Err(ColumnOperationError::BinaryOperationInvalidColumnType { .. }) )); - let lhs = OwnedColumn::::Boolean(vec![true, false, true]); - let rhs = OwnedColumn::::Int(vec![1, 2, 3]); + let lhs = OwnedColumn::::Boolean(vec![true, false, true]); + let rhs = OwnedColumn::::Int(vec![1, 2, 3]); let result = lhs.element_wise_le(&rhs); assert!(matches!( result, @@ -1838,13 +1788,13 @@ mod test { )); // Strings can not be <= or >= to each other - let lhs = OwnedColumn::::VarChar( + let lhs = OwnedColumn::::VarChar( ["Space", "and", "Time"] .iter() .map(ToString::to_string) .collect(), ); - let rhs = OwnedColumn::::VarChar( + let rhs = OwnedColumn::::VarChar( ["Space", "and", "time"] .iter() .map(ToString::to_string) @@ -1865,16 +1815,16 @@ mod test { #[test] fn we_cannot_do_arithmetic_on_nonnumeric_columns() { - let lhs = OwnedColumn::::VarChar( + let lhs = OwnedColumn::::VarChar( ["Space", "and", "Time"] .iter() .map(ToString::to_string) .collect(), ); - let rhs = OwnedColumn::::Scalar(vec![ - Curve25519Scalar::from(1), - Curve25519Scalar::from(2), - Curve25519Scalar::from(3), + let rhs = OwnedColumn::::Scalar(vec![ + TestScalar::from(1), + TestScalar::from(2), + TestScalar::from(3), ]); let result = lhs.clone() + rhs.clone(); assert!(matches!( @@ -1904,401 +1854,325 @@ mod test { #[test] fn we_can_add_integer_columns() { // lhs and rhs have the same precision - let lhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); - let rhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); + let lhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); + let rhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); let result = lhs + rhs; assert_eq!( result, - Ok(OwnedColumn::::TinyInt(vec![2_i8, 4, 6])) + Ok(OwnedColumn::::TinyInt(vec![2_i8, 4, 6])) ); - let lhs = OwnedColumn::::SmallInt(vec![1_i16, 2, 3]); - let rhs = OwnedColumn::::SmallInt(vec![1_i16, 2, 3]); + let lhs = OwnedColumn::::SmallInt(vec![1_i16, 2, 3]); + let rhs = OwnedColumn::::SmallInt(vec![1_i16, 2, 3]); let result = lhs + rhs; assert_eq!( result, - Ok(OwnedColumn::::SmallInt(vec![2_i16, 4, 6])) + Ok(OwnedColumn::::SmallInt(vec![2_i16, 4, 6])) ); // lhs and rhs have different precisions - let lhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); - let rhs = OwnedColumn::::Int(vec![1_i32, 2, 3]); + let lhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); + let rhs = OwnedColumn::::Int(vec![1_i32, 2, 3]); let result = lhs + rhs; assert_eq!( result, - Ok(OwnedColumn::::Int(vec![2_i32, 4, 6])) + Ok(OwnedColumn::::Int(vec![2_i32, 4, 6])) ); - let lhs = OwnedColumn::::Int128(vec![1_i128, 2, 3]); - let rhs = OwnedColumn::::Int(vec![1_i32, 2, 3]); + let lhs = OwnedColumn::::Int128(vec![1_i128, 2, 3]); + let rhs = OwnedColumn::::Int(vec![1_i32, 2, 3]); let result = lhs + rhs; assert_eq!( result, - Ok(OwnedColumn::::Int128(vec![2_i128, 4, 6])) + Ok(OwnedColumn::::Int128(vec![2_i128, 4, 6])) ); } #[test] fn we_can_try_add_decimal_columns() { // lhs and rhs have the same precision and scale - let lhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs + rhs).unwrap(); - let expected_scalars = [2, 4, 6].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [2, 4, 6].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(6).unwrap(), - 2, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(6).unwrap(), 2, expected_scalars) ); // lhs and rhs have different precisions and scales - let lhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); - let rhs = - OwnedColumn::::Decimal75(Precision::new(51).unwrap(), 3, rhs_scalars); + let lhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); + let rhs = OwnedColumn::::Decimal75(Precision::new(51).unwrap(), 3, rhs_scalars); let result = (lhs + rhs).unwrap(); - let expected_scalars = [11, 22, 33].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [11, 22, 33].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(52).unwrap(), - 3, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(52).unwrap(), 3, expected_scalars) ); // lhs is integer and rhs is decimal - let lhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs = OwnedColumn::::TinyInt(vec![1, 2, 3]); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs + rhs).unwrap(); - let expected_scalars = [101, 202, 303].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [101, 202, 303].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(6).unwrap(), - 2, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(6).unwrap(), 2, expected_scalars) ); - let lhs = OwnedColumn::::Int(vec![1, 2, 3]); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs = OwnedColumn::::Int(vec![1, 2, 3]); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs + rhs).unwrap(); - let expected_scalars = [101, 202, 303].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [101, 202, 303].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(13).unwrap(), - 2, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(13).unwrap(), 2, expected_scalars) ); } #[test] fn we_can_try_subtract_integer_columns() { // lhs and rhs have the same precision - let lhs = OwnedColumn::::TinyInt(vec![4_i8, 5, 2]); - let rhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); + let lhs = OwnedColumn::::TinyInt(vec![4_i8, 5, 2]); + let rhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); let result = lhs - rhs; assert_eq!( result, - Ok(OwnedColumn::::TinyInt(vec![3_i8, 3, -1])) + Ok(OwnedColumn::::TinyInt(vec![3_i8, 3, -1])) ); - let lhs = OwnedColumn::::Int(vec![4_i32, 5, 2]); - let rhs = OwnedColumn::::Int(vec![1_i32, 2, 3]); + let lhs = OwnedColumn::::Int(vec![4_i32, 5, 2]); + let rhs = OwnedColumn::::Int(vec![1_i32, 2, 3]); let result = lhs - rhs; assert_eq!( result, - Ok(OwnedColumn::::Int(vec![3_i32, 3, -1])) + Ok(OwnedColumn::::Int(vec![3_i32, 3, -1])) ); // lhs and rhs have different precisions - let lhs = OwnedColumn::::TinyInt(vec![4_i8, 5, 2]); - let rhs = OwnedColumn::::BigInt(vec![1_i64, 2, 5]); + let lhs = OwnedColumn::::TinyInt(vec![4_i8, 5, 2]); + let rhs = OwnedColumn::::BigInt(vec![1_i64, 2, 5]); let result = lhs - rhs; assert_eq!( result, - Ok(OwnedColumn::::BigInt(vec![3_i64, 3, -3])) + Ok(OwnedColumn::::BigInt(vec![3_i64, 3, -3])) ); - let lhs = OwnedColumn::::Int(vec![3_i32, 2, 3]); - let rhs = OwnedColumn::::BigInt(vec![1_i64, 2, 5]); + let lhs = OwnedColumn::::Int(vec![3_i32, 2, 3]); + let rhs = OwnedColumn::::BigInt(vec![1_i64, 2, 5]); let result = lhs - rhs; assert_eq!( result, - Ok(OwnedColumn::::BigInt(vec![2_i64, 0, -2])) + Ok(OwnedColumn::::BigInt(vec![2_i64, 0, -2])) ); } #[test] fn we_can_try_subtract_decimal_columns() { // lhs and rhs have the same precision and scale - let lhs_scalars = [4, 5, 2].iter().map(Curve25519Scalar::from).collect(); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs_scalars = [4, 5, 2].iter().map(TestScalar::from).collect(); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs - rhs).unwrap(); - let expected_scalars = [3, 3, -1].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [3, 3, -1].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(6).unwrap(), - 2, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(6).unwrap(), 2, expected_scalars) ); // lhs and rhs have different precisions and scales - let lhs_scalars = [4, 5, 2].iter().map(Curve25519Scalar::from).collect(); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let lhs = - OwnedColumn::::Decimal75(Precision::new(25).unwrap(), 2, lhs_scalars); - let rhs = - OwnedColumn::::Decimal75(Precision::new(51).unwrap(), 3, rhs_scalars); + let lhs_scalars = [4, 5, 2].iter().map(TestScalar::from).collect(); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let lhs = OwnedColumn::::Decimal75(Precision::new(25).unwrap(), 2, lhs_scalars); + let rhs = OwnedColumn::::Decimal75(Precision::new(51).unwrap(), 3, rhs_scalars); let result = (lhs - rhs).unwrap(); - let expected_scalars = [39, 48, 17].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [39, 48, 17].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(52).unwrap(), - 3, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(52).unwrap(), 3, expected_scalars) ); // lhs is integer and rhs is decimal - let lhs = OwnedColumn::::TinyInt(vec![4, 5, 2]); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs = OwnedColumn::::TinyInt(vec![4, 5, 2]); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs - rhs).unwrap(); - let expected_scalars = [399, 498, 197].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [399, 498, 197].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(6).unwrap(), - 2, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(6).unwrap(), 2, expected_scalars) ); - let lhs = OwnedColumn::::Int(vec![4, 5, 2]); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs = OwnedColumn::::Int(vec![4, 5, 2]); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs - rhs).unwrap(); - let expected_scalars = [399, 498, 197].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [399, 498, 197].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(13).unwrap(), - 2, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(13).unwrap(), 2, expected_scalars) ); } #[test] fn we_can_try_multiply_integer_columns() { // lhs and rhs have the same precision - let lhs = OwnedColumn::::TinyInt(vec![4_i8, 5, -2]); - let rhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); + let lhs = OwnedColumn::::TinyInt(vec![4_i8, 5, -2]); + let rhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); let result = lhs * rhs; assert_eq!( result, - Ok(OwnedColumn::::TinyInt(vec![4_i8, 10, -6])) + Ok(OwnedColumn::::TinyInt(vec![4_i8, 10, -6])) ); - let lhs = OwnedColumn::::BigInt(vec![4_i64, 5, -2]); - let rhs = OwnedColumn::::BigInt(vec![1_i64, 2, 3]); + let lhs = OwnedColumn::::BigInt(vec![4_i64, 5, -2]); + let rhs = OwnedColumn::::BigInt(vec![1_i64, 2, 3]); let result = lhs * rhs; assert_eq!( result, - Ok(OwnedColumn::::BigInt(vec![4_i64, 10, -6])) + Ok(OwnedColumn::::BigInt(vec![4_i64, 10, -6])) ); // lhs and rhs have different precisions - let lhs = OwnedColumn::::TinyInt(vec![3_i8, 2, 3]); - let rhs = OwnedColumn::::Int128(vec![1_i128, 2, 5]); + let lhs = OwnedColumn::::TinyInt(vec![3_i8, 2, 3]); + let rhs = OwnedColumn::::Int128(vec![1_i128, 2, 5]); let result = lhs * rhs; assert_eq!( result, - Ok(OwnedColumn::::Int128(vec![3_i128, 4, 15])) + Ok(OwnedColumn::::Int128(vec![3_i128, 4, 15])) ); - let lhs = OwnedColumn::::Int(vec![3_i32, 2, 3]); - let rhs = OwnedColumn::::Int128(vec![1_i128, 2, 5]); + let lhs = OwnedColumn::::Int(vec![3_i32, 2, 3]); + let rhs = OwnedColumn::::Int128(vec![1_i128, 2, 5]); let result = lhs * rhs; assert_eq!( result, - Ok(OwnedColumn::::Int128(vec![3_i128, 4, 15])) + Ok(OwnedColumn::::Int128(vec![3_i128, 4, 15])) ); } #[test] fn we_can_try_multiply_decimal_columns() { // lhs and rhs are both decimals - let lhs_scalars = [4, 5, 2].iter().map(Curve25519Scalar::from).collect(); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); - let rhs_scalars = [-1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs_scalars = [4, 5, 2].iter().map(TestScalar::from).collect(); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); + let rhs_scalars = [-1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs * rhs).unwrap(); - let expected_scalars = [-4, 10, 6].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [-4, 10, 6].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(11).unwrap(), - 4, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(11).unwrap(), 4, expected_scalars) ); // lhs is integer and rhs is decimal - let lhs = OwnedColumn::::TinyInt(vec![4, 5, 2]); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs = OwnedColumn::::TinyInt(vec![4, 5, 2]); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs * rhs).unwrap(); - let expected_scalars = [4, 10, 6].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [4, 10, 6].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(9).unwrap(), - 2, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(9).unwrap(), 2, expected_scalars) ); - let lhs = OwnedColumn::::Int(vec![4, 5, 2]); - let rhs_scalars = [1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs = OwnedColumn::::Int(vec![4, 5, 2]); + let rhs_scalars = [1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs * rhs).unwrap(); - let expected_scalars = [4, 10, 6].iter().map(Curve25519Scalar::from).collect(); + let expected_scalars = [4, 10, 6].iter().map(TestScalar::from).collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(16).unwrap(), - 2, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(16).unwrap(), 2, expected_scalars) ); } #[test] fn we_can_try_divide_integer_columns() { // lhs and rhs have the same precision - let lhs = OwnedColumn::::TinyInt(vec![4_i8, 5, -2]); - let rhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); + let lhs = OwnedColumn::::TinyInt(vec![4_i8, 5, -2]); + let rhs = OwnedColumn::::TinyInt(vec![1_i8, 2, 3]); let result = lhs / rhs; assert_eq!( result, - Ok(OwnedColumn::::TinyInt(vec![4_i8, 2, 0])) + Ok(OwnedColumn::::TinyInt(vec![4_i8, 2, 0])) ); - let lhs = OwnedColumn::::BigInt(vec![4_i64, 5, -2]); - let rhs = OwnedColumn::::BigInt(vec![1_i64, 2, 3]); + let lhs = OwnedColumn::::BigInt(vec![4_i64, 5, -2]); + let rhs = OwnedColumn::::BigInt(vec![1_i64, 2, 3]); let result = lhs / rhs; assert_eq!( result, - Ok(OwnedColumn::::BigInt(vec![4_i64, 2, 0])) + Ok(OwnedColumn::::BigInt(vec![4_i64, 2, 0])) ); // lhs and rhs have different precisions - let lhs = OwnedColumn::::TinyInt(vec![3_i8, 2, 3]); - let rhs = OwnedColumn::::Int128(vec![1_i128, 2, 5]); + let lhs = OwnedColumn::::TinyInt(vec![3_i8, 2, 3]); + let rhs = OwnedColumn::::Int128(vec![1_i128, 2, 5]); let result = lhs / rhs; assert_eq!( result, - Ok(OwnedColumn::::Int128(vec![3_i128, 1, 0])) + Ok(OwnedColumn::::Int128(vec![3_i128, 1, 0])) ); - let lhs = OwnedColumn::::Int(vec![3_i32, 2, 3]); - let rhs = OwnedColumn::::Int128(vec![1_i128, 2, 5]); + let lhs = OwnedColumn::::Int(vec![3_i32, 2, 3]); + let rhs = OwnedColumn::::Int128(vec![1_i128, 2, 5]); let result = lhs / rhs; assert_eq!( result, - Ok(OwnedColumn::::Int128(vec![3_i128, 1, 0])) + Ok(OwnedColumn::::Int128(vec![3_i128, 1, 0])) ); } #[test] fn we_can_try_divide_decimal_columns() { // lhs and rhs are both decimals - let lhs_scalars = [4, 5, 3].iter().map(Curve25519Scalar::from).collect(); - let lhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); - let rhs_scalars = [-1, 2, 4].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); + let lhs_scalars = [4, 5, 3].iter().map(TestScalar::from).collect(); + let lhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, lhs_scalars); + let rhs_scalars = [-1, 2, 4].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(5).unwrap(), 2, rhs_scalars); let result = (lhs / rhs).unwrap(); let expected_scalars = [-400_000_000_i128, 250_000_000, 75_000_000] .iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(13).unwrap(), - 8, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(13).unwrap(), 8, expected_scalars) ); // lhs is integer and rhs is decimal - let lhs = OwnedColumn::::TinyInt(vec![4, 5, 3]); - let rhs_scalars = [-1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(3).unwrap(), 2, rhs_scalars); + let lhs = OwnedColumn::::TinyInt(vec![4, 5, 3]); + let rhs_scalars = [-1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(3).unwrap(), 2, rhs_scalars); let result = (lhs / rhs).unwrap(); let expected_scalars = [-400_000_000, 250_000_000, 100_000_000] .iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(11).unwrap(), - 6, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(11).unwrap(), 6, expected_scalars) ); - let lhs = OwnedColumn::::SmallInt(vec![4, 5, 3]); - let rhs_scalars = [-1, 2, 3].iter().map(Curve25519Scalar::from).collect(); - let rhs = - OwnedColumn::::Decimal75(Precision::new(3).unwrap(), 2, rhs_scalars); + let lhs = OwnedColumn::::SmallInt(vec![4, 5, 3]); + let rhs_scalars = [-1, 2, 3].iter().map(TestScalar::from).collect(); + let rhs = OwnedColumn::::Decimal75(Precision::new(3).unwrap(), 2, rhs_scalars); let result = (lhs / rhs).unwrap(); let expected_scalars = [-400_000_000, 250_000_000, 100_000_000] .iter() - .map(Curve25519Scalar::from) + .map(TestScalar::from) .collect(); assert_eq!( result, - OwnedColumn::::Decimal75( - Precision::new(13).unwrap(), - 6, - expected_scalars - ) + OwnedColumn::::Decimal75(Precision::new(13).unwrap(), 6, expected_scalars) ); } } diff --git a/crates/proof-of-sql/src/base/database/scalar_and_i256_conversions.rs b/crates/proof-of-sql/src/base/database/scalar_and_i256_conversions.rs index 3ea407f41..582bcec34 100644 --- a/crates/proof-of-sql/src/base/database/scalar_and_i256_conversions.rs +++ b/crates/proof-of-sql/src/base/database/scalar_and_i256_conversions.rs @@ -57,7 +57,7 @@ mod tests { use super::{convert_i256_to_scalar, convert_scalar_to_i256}; use crate::base::{ database::scalar_and_i256_conversions::{MAX_SUPPORTED_I256, MIN_SUPPORTED_I256}, - scalar::{Curve25519Scalar, Scalar}, + scalar::{test_scalar::TestScalar, Curve25519Scalar, Scalar}, }; use arrow::datatypes::i256; use num_traits::Zero; @@ -67,7 +67,7 @@ mod tests { fn random_i256(rng: &mut R) -> i256 { use rand::Rng; let max_signed_as_parts: (u128, i128) = - convert_scalar_to_i256(&Curve25519Scalar::MAX_SIGNED).to_parts(); + convert_scalar_to_i256(&TestScalar::MAX_SIGNED).to_parts(); // Generate a random high part let high: i128 = rng.gen_range(-max_signed_as_parts.1..=max_signed_as_parts.1); @@ -82,7 +82,7 @@ mod tests { i256::from_parts(low, high) } - impl TryFrom for Curve25519Scalar { + impl TryFrom for TestScalar { type Error = (); // Must fit inside 252 bits and so requires fallible @@ -90,109 +90,109 @@ mod tests { convert_i256_to_scalar(&value).ok_or(()) } } + impl From for i256 { fn from(value: Curve25519Scalar) -> Self { convert_scalar_to_i256(&value) } } + impl From for i256 { + fn from(value: TestScalar) -> Self { + convert_scalar_to_i256(&value) + } + } + #[test] - fn test_curve25519scalar_to_i256_conversion() { - let positive_scalar = Curve25519Scalar::from(12345); + fn test_testscalar_to_i256_conversion() { + let positive_scalar = TestScalar::from(12345); let expected_i256 = i256::from(12345); assert_eq!(i256::from(positive_scalar), expected_i256); - let negative_scalar = Curve25519Scalar::from(-12345); + let negative_scalar = TestScalar::from(-12345); let expected_i256 = i256::from(-12345); assert_eq!(i256::from(negative_scalar), expected_i256); - let max_scalar = Curve25519Scalar::MAX_SIGNED; - let expected_max = i256::from(Curve25519Scalar::MAX_SIGNED); + let max_scalar = TestScalar::MAX_SIGNED; + let expected_max = i256::from(TestScalar::MAX_SIGNED); assert_eq!(i256::from(max_scalar), expected_max); - let min_scalar = Curve25519Scalar::from(0); - let expected_min = i256::from(Curve25519Scalar::from(0)); + let min_scalar = TestScalar::from(0); + let expected_min = i256::from(TestScalar::from(0)); assert_eq!(i256::from(min_scalar), expected_min); } #[test] - fn test_curve25519scalar_i256_overflow_and_underflow() { + fn test_testscalar_i256_overflow_and_underflow() { // 2^256 overflows - assert!(Curve25519Scalar::try_from(i256::MAX).is_err()); + assert!(TestScalar::try_from(i256::MAX).is_err()); // MAX_SIGNED + 1 overflows - assert!(Curve25519Scalar::try_from(MAX_SUPPORTED_I256 + i256::from(1)).is_err()); + assert!(TestScalar::try_from(MAX_SUPPORTED_I256 + i256::from(1)).is_err()); // -2^255 underflows - assert!(i256::MIN < -(i256::from(Curve25519Scalar::MAX_SIGNED))); - assert!(Curve25519Scalar::try_from(i256::MIN).is_err()); + assert!(i256::MIN < -(i256::from(TestScalar::MAX_SIGNED))); + assert!(TestScalar::try_from(i256::MIN).is_err()); // -MAX-SIGNED - 1 underflows - assert!(Curve25519Scalar::try_from(MIN_SUPPORTED_I256 - i256::from(1)).is_err()); + assert!(TestScalar::try_from(MIN_SUPPORTED_I256 - i256::from(1)).is_err()); } #[test] - fn test_i256_curve25519scalar_negative() { - // Test conversion from i256(-1) to Curve25519Scalar - let neg_one_i256_curve25519scalar = Curve25519Scalar::try_from(i256::from(-1)); - assert!(neg_one_i256_curve25519scalar.is_ok()); - let neg_one_curve25519scalar = Curve25519Scalar::from(-1); - assert_eq!( - neg_one_i256_curve25519scalar.unwrap(), - neg_one_curve25519scalar - ); + fn test_i256_testscalar_negative() { + // Test conversion from i256(-1) to TestScalar + let neg_one_i256_testscalar = TestScalar::try_from(i256::from(-1)); + assert!(neg_one_i256_testscalar.is_ok()); + let neg_one_testscalar = TestScalar::from(-1); + assert_eq!(neg_one_i256_testscalar.unwrap(), neg_one_testscalar); } #[test] - fn test_i256_curve25519scalar_zero() { - // Test conversion from i256(0) to Curve25519Scalar - let zero_i256_curve25519scalar = Curve25519Scalar::try_from(i256::from(0)); - assert!(zero_i256_curve25519scalar.is_ok()); - let zero_curve25519scalar = Curve25519Scalar::zero(); - assert_eq!(zero_i256_curve25519scalar.unwrap(), zero_curve25519scalar); + fn test_i256_testscalar_zero() { + // Test conversion from i256(0) to TestScalar + let zero_i256_testscalar = TestScalar::try_from(i256::from(0)); + assert!(zero_i256_testscalar.is_ok()); + let zero_testscalar = TestScalar::zero(); + assert_eq!(zero_i256_testscalar.unwrap(), zero_testscalar); } #[test] - fn test_i256_curve25519scalar_positive() { - // Test conversion from i256(42) to Curve25519Scalar - let forty_two_i256_curve25519scalar = Curve25519Scalar::try_from(i256::from(42)); - let forty_two_curve25519scalar = Curve25519Scalar::from(42); - assert_eq!( - forty_two_i256_curve25519scalar.unwrap(), - forty_two_curve25519scalar - ); + fn test_i256_testscalar_positive() { + // Test conversion from i256(42) to TestScalar + let forty_two_i256_testscalar = TestScalar::try_from(i256::from(42)); + let forty_two_testscalar = TestScalar::from(42); + assert_eq!(forty_two_i256_testscalar.unwrap(), forty_two_testscalar); } #[test] - fn test_i256_curve25519scalar_max_signed() { + fn test_i256_testscalar_max_signed() { let max_signed = MAX_SUPPORTED_I256; // max signed value - let max_signed_scalar = Curve25519Scalar::MAX_SIGNED; - // Test conversion from i256 to Curve25519Scalar - let i256_curve25519scalar = Curve25519Scalar::try_from(max_signed); - assert!(i256_curve25519scalar.is_ok()); - assert_eq!(i256_curve25519scalar.unwrap(), max_signed_scalar); + let max_signed_scalar = TestScalar::MAX_SIGNED; + // Test conversion from i256 to TestScalar + let i256_testscalar = TestScalar::try_from(max_signed); + assert!(i256_testscalar.is_ok()); + assert_eq!(i256_testscalar.unwrap(), max_signed_scalar); } #[test] - fn test_i256_curve25519scalar_min_signed() { + fn test_i256_testscalar_min_signed() { let min_signed = MIN_SUPPORTED_I256; - let i256_curve25519scalar = Curve25519Scalar::try_from(min_signed); + let i256_testscalar = TestScalar::try_from(min_signed); // -MAX_SIGNED is ok - assert!(i256_curve25519scalar.is_ok()); + assert!(i256_testscalar.is_ok()); assert_eq!( - i256_curve25519scalar.unwrap(), - Curve25519Scalar::MAX_SIGNED + Curve25519Scalar::from(1) + i256_testscalar.unwrap(), + TestScalar::MAX_SIGNED + TestScalar::from(1) ); } #[test] - fn test_i256_curve25519scalar_random() { + fn test_i256_testscalar_random() { let mut rng = rand::thread_rng(); for _ in 0..1000 { let i256_value = random_i256(&mut rng); - let curve25519_scalar = - Curve25519Scalar::try_from(i256_value).expect("Conversion failed"); + let curve25519_scalar = TestScalar::try_from(i256_value).expect("Conversion failed"); let back_to_i256 = i256::from(curve25519_scalar); assert_eq!(i256_value, back_to_i256, "Round-trip conversion failed"); }