Skip to content

Commit

Permalink
fix: trying to remove the scripts from git diff
Browse files Browse the repository at this point in the history
Signed-off-by: Abinand P <[email protected]>
  • Loading branch information
Abiji-2020 committed Oct 21, 2024
1 parent edb6ccd commit c28ad44
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 65 deletions.
112 changes: 48 additions & 64 deletions crates/proof-of-sql/src/base/math/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,12 @@ mod scale_adjust_test {

let target_scale = 5;

assert!(
try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(u8::try_from(decimal.precision()).unwrap_or(u8::MAX)).unwrap(),
target_scale
)
.is_err()
);
assert!(try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(u8::try_from(decimal.precision()).unwrap_or(u8::MAX)).unwrap(),
target_scale
)
.is_err());
}

#[test]
Expand Down Expand Up @@ -254,94 +252,80 @@ mod scale_adjust_test {
.parse()
.unwrap();
let target_scale = 6; // now precision exceeds maximum
assert!(
try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(u8::try_from(decimal.precision()).unwrap_or(u8::MAX),).unwrap(),
target_scale
)
.is_err()
);
assert!(try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(u8::try_from(decimal.precision()).unwrap_or(u8::MAX),).unwrap(),
target_scale
)
.is_err());

// maximum decimal value we can support
let decimal =
"99999999999999999999999999999999999999999999999999999999999999999999999999.0"
.parse()
.unwrap();
let target_scale = 1;
assert!(
try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(MAX_SUPPORTED_PRECISION).unwrap(),
target_scale
)
.is_ok()
);
assert!(try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(MAX_SUPPORTED_PRECISION).unwrap(),
target_scale
)
.is_ok());

// scaling larger than max will fail
let decimal =
"999999999999999999999999999999999999999999999999999999999999999999999999999.0"
.parse()
.unwrap();
let target_scale = 1;
assert!(
try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(MAX_SUPPORTED_PRECISION).unwrap(),
target_scale
)
.is_err()
);
assert!(try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(MAX_SUPPORTED_PRECISION).unwrap(),
target_scale
)
.is_err());

// smallest possible decimal value we can support (either signed/unsigned)
let decimal =
"0.000000000000000000000000000000000000000000000000000000000000000000000000001"
.parse()
.unwrap();
let target_scale = MAX_SUPPORTED_PRECISION as i8;
assert!(
try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(u8::try_from(decimal.precision()).unwrap_or(u8::MAX),).unwrap(),
target_scale
)
.is_ok()
);
assert!(try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(u8::try_from(decimal.precision()).unwrap_or(u8::MAX),).unwrap(),
target_scale
)
.is_ok());

// this is ok because it can be scaled to 75 precision
let decimal = "0.1".parse().unwrap();
let target_scale = MAX_SUPPORTED_PRECISION as i8;
assert!(
try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(MAX_SUPPORTED_PRECISION).unwrap(),
target_scale
)
.is_ok()
);
assert!(try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(MAX_SUPPORTED_PRECISION).unwrap(),
target_scale
)
.is_ok());

// this exceeds max precision
let decimal = "1.0".parse().unwrap();
let target_scale = 75;
assert!(
try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(u8::try_from(decimal.precision()).unwrap_or(u8::MAX),).unwrap(),
target_scale
)
.is_err()
);
assert!(try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(u8::try_from(decimal.precision()).unwrap_or(u8::MAX),).unwrap(),
target_scale
)
.is_err());

// but this is ok
let decimal = "1.0".parse().unwrap();
let target_scale = 74;
assert!(
try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(MAX_SUPPORTED_PRECISION).unwrap(),
target_scale
)
.is_ok()
);
assert!(try_convert_intermediate_decimal_to_scalar::<TestScalar>(
&decimal,
Precision::new(MAX_SUPPORTED_PRECISION).unwrap(),
target_scale
)
.is_ok());
}
}
2 changes: 1 addition & 1 deletion scripts/run_ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ if [ "$failed_tests" -gt 0 ]; then
echo "Error: $failed_tests CI checks (excluding tests and udeps) have FAILED."
else
echo "All CI checks (excluding tests and udeps) have completed successfully."
fi
fi

0 comments on commit c28ad44

Please sign in to comment.