more fixes, still not done yet

This commit is contained in:
filipriec
2025-07-07 13:32:06 +02:00
parent 4d5d22d0c2
commit 11487f0833
4 changed files with 61 additions and 64 deletions

View File

@@ -238,7 +238,7 @@ fn test_decimal_precision_edge_cases(#[case] a: &str, #[case] b: &str, #[case] e
// Test scientific notation
#[rstest]
#[case("1e2", "2e1", "120")]
#[case("1.5e2", "2.3e1", "173")]
#[case("1.5e2", "2.3e1", "173.0")]
fn test_scientific_notation(#[case] a: &str, #[case] b: &str, #[case] expected: &str) {
let result = decimal_add(a.to_string(), b.to_string()).unwrap();
assert_eq!(result, expected);
@@ -255,26 +255,21 @@ fn test_precision_preservation(#[case] a: &str, #[case] b: &str, #[case] expecte
assert_eq!(result, expected);
}
// Test explicit precision functions
// Test explicit precision using global precision setting
#[rstest]
#[case("5.123", "2.456", 0, "8")] // 0 decimal places
#[case("5.123", "2.456", 2, "7.58")] // 2 decimal places
#[case("5.123", "2.456", 4, "7.5790")] // 4 decimal places
#[case("5.12312", "2.45622", 4, "7.5793")] // 4 decimal places
fn test_explicit_precision(#[case] a: &str, #[case] b: &str, #[case] precision: u32, #[case] expected: &str) {
let result = decimal_add_p(a.to_string(), b.to_string(), precision).unwrap();
assert_eq!(result, expected);
}
// Set precision globally
set_precision(precision);
// Test scientific notation edge cases
#[rstest]
#[case("1e0", "1")] // Simple case
#[case("1.0e0", "1.0")] // Preserves decimal
#[case("1e-2", "0.01")] // Negative exponent
#[case("1.5e-3", "0.0015")] // Decimal + negative exponent
#[case("2.5e2", "250.0")] // Decimal + positive exponent
fn test_scientific_edge_cases(#[case] input: &str, #[case] expected: &str) {
let result = to_decimal(input.to_string()).unwrap();
// Test with precision set
let result = decimal_add(a.to_string(), b.to_string()).unwrap();
assert_eq!(result, expected);
// Clean up - clear precision for other tests
clear_precision();
}
// Test precision functions
@@ -289,9 +284,58 @@ fn test_precision_functions() {
assert_eq!(result, "4.46");
// Test clearing precision
assert_eq!(clear_precision(), "Precision cleared - using full precision");
assert_eq!(get_precision(), "full");
// Test with full precision
let result = decimal_add("1.567".to_string(), "2.891".to_string()).unwrap();
assert_eq!(result, "4.458");
}
// Test decimal_format function
#[rstest]
#[case("5.123456", 2, "5.12")]
#[case("5.123456", 4, "5.1235")]
#[case("5.999", 0, "6")]
fn test_decimal_format(#[case] value: &str, #[case] precision: u32, #[case] expected: &str) {
let result = decimal_format(value.to_string(), precision).unwrap();
assert_eq!(result, expected);
}
// Test precision doesn't affect comparison functions
#[test]
fn test_precision_does_not_affect_comparisons() {
set_precision(2);
// Comparisons should use full precision internally
assert_eq!(decimal_gt("1.567".to_string(), "1.566".to_string()).unwrap(), true);
assert_eq!(decimal_eq("1.567".to_string(), "1.567".to_string()).unwrap(), true);
assert_eq!(decimal_eq("1.567".to_string(), "1.57".to_string()).unwrap(), false);
clear_precision();
}
// Test precision edge cases
#[test]
fn test_precision_edge_cases() {
// Test max precision
assert_eq!(set_precision(28), "Precision set to 28 decimal places");
// Test beyond max precision
assert_eq!(set_precision(29), "Error: Maximum precision is 28 decimal places");
// Clean up
clear_precision();
}
// Test scientific notation edge cases
#[rstest]
#[case("1e0", "1")] // Simple case
#[case("1.0e0", "1.0")] // Preserves decimal
#[case("1e-2", "0.01")] // Negative exponent
#[case("1.5e-3", "0.0015")] // Decimal + negative exponent
#[case("2.5e2", "250.0")] // Decimal + positive exponent
fn test_scientific_edge_cases(#[case] input: &str, #[case] expected: &str) {
let result = to_decimal(input.to_string()).unwrap();
assert_eq!(result, expected);
}