Skip to content

Commit

Permalink
Add test case for input/output scale = 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
aweltsch committed Feb 13, 2025
1 parent a8d26bd commit a2f2b98
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions arrow-cast/src/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9948,7 +9948,7 @@ mod tests {
input_repr: 99999, // 9999.9
output_prec: 7,
output_scale: 6,
expected_output_repr: Err(r"Invalid argument error: 9999900000 is too large to store in a {} of precision 7. Max is 9999999".to_string()) // max is 9.999999
expected_output_repr: Err("Invalid argument error: 9999900000 is too large to store in a {} of precision 7. Max is 9999999".to_string()) // max is 9.999999
},
// increase precision, decrease scale, always infallible
DecimalCastTestConfig {
Expand Down Expand Up @@ -9993,7 +9993,7 @@ mod tests {
input_repr: 9999999, // 99.99999
output_prec: 8,
output_scale: 7,
expected_output_repr: Err(r"Invalid argument error: 999999900 is too large to store in a {} of precision 8. Max is 99999999".to_string()) // max is 9.9999999
expected_output_repr: Err("Invalid argument error: 999999900 is too large to store in a {} of precision 8. Max is 99999999".to_string()) // max is 9.9999999
},
// decrease precision, decrease scale, safe, infallible
DecimalCastTestConfig {
Expand All @@ -10020,7 +10020,7 @@ mod tests {
input_repr: 9999999, // 99.99999
output_prec: 4,
output_scale: 3,
expected_output_repr: Err(r"Invalid argument error: 100000 is too large to store in a {} of precision 4. Max is 9999".to_string()) // max is 9.999
expected_output_repr: Err("Invalid argument error: 100000 is too large to store in a {} of precision 4. Max is 9999".to_string()) // max is 9.999
},
// decrease precision, same scale, safe
DecimalCastTestConfig {
Expand All @@ -10038,7 +10038,7 @@ mod tests {
input_repr: 9999999, // 99.99999
output_prec: 6,
output_scale: 5,
expected_output_repr: Err(r"Invalid argument error: 9999999 is too large to store in a {} of precision 6. Max is 999999".to_string()) // max is 9.99999
expected_output_repr: Err("Invalid argument error: 9999999 is too large to store in a {} of precision 6. Max is 999999".to_string()) // max is 9.99999
},
// same precision, increase scale, safe
DecimalCastTestConfig {
Expand All @@ -10056,7 +10056,7 @@ mod tests {
input_repr: 123456, // 12.3456
output_prec: 7,
output_scale: 6,
expected_output_repr: Err(r"Invalid argument error: 12345600 is too large to store in a {} of precision 7. Max is 9999999".to_string()) // max is 9.99999
expected_output_repr: Err("Invalid argument error: 12345600 is too large to store in a {} of precision 7. Max is 9999999".to_string()) // max is 9.99999
},
// same precision, decrease scale, infallible
DecimalCastTestConfig {
Expand All @@ -10076,6 +10076,33 @@ mod tests {
output_scale: 5,
expected_output_repr: Ok(9999999), // 99.99999
},
// precision increase, input scale & output scale = 0, infallible
DecimalCastTestConfig {
input_prec: 7,
input_scale: 0,
input_repr: 1234567, // 9999999
output_prec: 8,
output_scale: 0,
expected_output_repr: Ok(1234567), // 9999999
},
// precision decrease, input scale & output scale = 0, failure
DecimalCastTestConfig {
input_prec: 7,
input_scale: 0,
input_repr: 1234567, // 9999999
output_prec: 6,
output_scale: 0,
expected_output_repr: Err("Invalid argument error: 1234567 is too large to store in a {} of precision 6. Max is 999999".to_string())
},
// precision decrease, input scale & output scale = 0, success
DecimalCastTestConfig {
input_prec: 7,
input_scale: 0,
input_repr: 123456, // 123456
output_prec: 6,
output_scale: 0,
expected_output_repr: Ok(123456), // 123456
},
];

for t in test_cases {
Expand Down Expand Up @@ -10124,7 +10151,7 @@ mod tests {
input_repr: -12345,
output_prec: 6,
output_scale: 5,
expected_output_repr: Err(r"Invalid argument error: -1234500 is too small to store in a {} of precision 6. Min is -999999".to_string())
expected_output_repr: Err("Invalid argument error: -1234500 is too small to store in a {} of precision 6. Min is -999999".to_string())
},
];

Expand Down Expand Up @@ -10175,7 +10202,7 @@ mod tests {
output_prec: 6,
output_scale: 3,
expected_output_repr:
Err(r"Invalid argument error: 1000000 is too large to store in a {} of precision 6. Max is 999999".to_string()),
Err("Invalid argument error: 1000000 is too large to store in a {} of precision 6. Max is 999999".to_string()),
},
];
for t in test_cases {
Expand Down

0 comments on commit a2f2b98

Please sign in to comment.