tests are passing well now
This commit is contained in:
@@ -105,38 +105,48 @@ fn test_extreme_scientific_notation(#[case] sci_notation: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test edge cases in arithmetic operations
|
||||
// Test edge cases in arithmetic operations
|
||||
#[rstest]
|
||||
fn test_arithmetic_edge_cases() {
|
||||
let max_decimal = "79228162514264337593543950335";
|
||||
let min_decimal = "-79228162514264337593543950335";
|
||||
let tiny_decimal = "0.0000000000000000000000000001";
|
||||
|
||||
// Addition near overflow
|
||||
let _result = decimal_add(max_decimal.to_string(), "1".to_string());
|
||||
// May overflow, but shouldn't panic
|
||||
// Addition near overflow - should return error, not panic
|
||||
let add_result = decimal_add(max_decimal.to_string(), "1".to_string());
|
||||
match add_result {
|
||||
Ok(_) => {}, // Unlikely but possible
|
||||
Err(e) => assert!(e.contains("overflow"), "Expected overflow error, got: {}", e),
|
||||
}
|
||||
|
||||
// Subtraction near underflow
|
||||
let _result = decimal_sub(min_decimal.to_string(), "1".to_string());
|
||||
// May underflow, but shouldn't panic
|
||||
// Subtraction near underflow - should return error, not panic
|
||||
let sub_result = decimal_sub(min_decimal.to_string(), "1".to_string());
|
||||
match sub_result {
|
||||
Ok(_) => {}, // Unlikely but possible
|
||||
Err(e) => assert!(e.contains("overflow"), "Expected overflow error, got: {}", e),
|
||||
}
|
||||
|
||||
// Multiplication that could overflow
|
||||
let _result = decimal_mul(max_decimal.to_string(), "2".to_string());
|
||||
// May overflow, but shouldn't panic
|
||||
// Multiplication that could overflow - should return error, not panic
|
||||
let mul_result = decimal_mul(max_decimal.to_string(), "2".to_string());
|
||||
match mul_result {
|
||||
Ok(_) => {}, // Unlikely but possible
|
||||
Err(e) => assert!(e.contains("overflow"), "Expected overflow error, got: {}", e),
|
||||
}
|
||||
|
||||
// Division by very small number
|
||||
let _result = decimal_div("1".to_string(), tiny_decimal.to_string());
|
||||
// May be very large, but shouldn't panic
|
||||
// Division by very small number - might be very large but shouldn't panic
|
||||
let div_result = decimal_div("1".to_string(), tiny_decimal.to_string());
|
||||
match div_result {
|
||||
Ok(_) => {}, // Should work
|
||||
Err(e) => assert!(e.contains("overflow"), "Expected overflow error if any, got: {}", e),
|
||||
}
|
||||
|
||||
// All operations should complete without panicking
|
||||
// All operations should complete without panicking - if we get here, that's success!
|
||||
}
|
||||
|
||||
// Test malformed but potentially parseable inputs
|
||||
#[rstest]
|
||||
#[case("1.2.3")] // Multiple decimal points
|
||||
#[case("1..2")] // Double decimal point
|
||||
#[case(".123")] // Leading decimal point
|
||||
#[case("123.")] // Trailing decimal point
|
||||
#[case("1.23e")] // Incomplete scientific notation
|
||||
#[case("1.23e+")] // Incomplete positive exponent
|
||||
#[case("1.23e-")] // Incomplete negative exponent
|
||||
@@ -157,6 +167,21 @@ fn test_malformed_decimal_inputs(#[case] malformed: &str) {
|
||||
let _ = decimal_abs(malformed.to_string());
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
#[case(".123")] // Leading decimal point - VALID in rust_decimal
|
||||
#[case("123.")] // Trailing decimal point - VALID in rust_decimal
|
||||
#[case("0.123")] // Standard format
|
||||
#[case("123.0")] // Standard format with trailing zero
|
||||
fn test_edge_case_valid_formats(#[case] valid_input: &str) {
|
||||
// These should be accepted since rust_decimal accepts them
|
||||
let result = to_decimal(valid_input.to_string());
|
||||
assert!(result.is_ok(), "Valid rust_decimal format should be accepted: {}", valid_input);
|
||||
|
||||
// Should also work in arithmetic operations
|
||||
let add_result = decimal_add(valid_input.to_string(), "1".to_string());
|
||||
assert!(add_result.is_ok(), "Arithmetic should work with valid format: {}", valid_input);
|
||||
}
|
||||
|
||||
// Test edge cases in comparison operations
|
||||
#[rstest]
|
||||
fn test_comparison_edge_cases() {
|
||||
|
||||
Reference in New Issue
Block a user