Skip to content

Commit 2066568

Browse files
authored
Clarify tests for Interval::and, Interval::not, and add Interval::or tests (#18621)
## Which issue does this PR close? None, unit test clarification ## Rationale for this change The unit tests for `Interval::and`, and `Interval::not` are written using a hard to to interpret matrix of boolean values. It's much easier to scan this for correctness when using the constants instead. ## What changes are included in this PR? - Replace raw boolean values with constant references - Ensure tests cover all permutations - Add missing test for `Interval::or` ## Are these changes tested? Test only change ## Are there any user-facing changes? No
1 parent a3a5ca4 commit 2066568

File tree

1 file changed

+115
-15
lines changed

1 file changed

+115
-15
lines changed

datafusion/expr-common/src/interval_arithmetic.rs

Lines changed: 115 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2486,41 +2486,141 @@ mod tests {
24862486
#[test]
24872487
fn and_test() -> Result<()> {
24882488
let cases = vec![
2489-
(false, true, false, false, false, false),
2490-
(false, false, false, true, false, false),
2491-
(false, true, false, true, false, true),
2492-
(false, true, true, true, false, true),
2493-
(false, false, false, false, false, false),
2494-
(true, true, true, true, true, true),
2489+
(
2490+
Interval::UNCERTAIN,
2491+
Interval::CERTAINLY_FALSE,
2492+
Interval::CERTAINLY_FALSE,
2493+
),
2494+
(
2495+
Interval::UNCERTAIN,
2496+
Interval::UNCERTAIN,
2497+
Interval::UNCERTAIN,
2498+
),
2499+
(
2500+
Interval::UNCERTAIN,
2501+
Interval::CERTAINLY_TRUE,
2502+
Interval::UNCERTAIN,
2503+
),
2504+
(
2505+
Interval::CERTAINLY_FALSE,
2506+
Interval::CERTAINLY_FALSE,
2507+
Interval::CERTAINLY_FALSE,
2508+
),
2509+
(
2510+
Interval::CERTAINLY_FALSE,
2511+
Interval::UNCERTAIN,
2512+
Interval::CERTAINLY_FALSE,
2513+
),
2514+
(
2515+
Interval::CERTAINLY_FALSE,
2516+
Interval::CERTAINLY_TRUE,
2517+
Interval::CERTAINLY_FALSE,
2518+
),
2519+
(
2520+
Interval::CERTAINLY_TRUE,
2521+
Interval::CERTAINLY_FALSE,
2522+
Interval::CERTAINLY_FALSE,
2523+
),
2524+
(
2525+
Interval::CERTAINLY_TRUE,
2526+
Interval::UNCERTAIN,
2527+
Interval::UNCERTAIN,
2528+
),
2529+
(
2530+
Interval::CERTAINLY_TRUE,
2531+
Interval::CERTAINLY_TRUE,
2532+
Interval::CERTAINLY_TRUE,
2533+
),
24952534
];
24962535

24972536
for case in cases {
24982537
assert_eq!(
2499-
Interval::make(Some(case.0), Some(case.1))?
2500-
.and(Interval::make(Some(case.2), Some(case.3))?)?,
2501-
Interval::make(Some(case.4), Some(case.5))?
2538+
case.0.and(&case.1)?,
2539+
case.2,
2540+
"Failed for {} AND {}",
2541+
case.0,
2542+
case.1
25022543
);
25032544
}
25042545
Ok(())
25052546
}
25062547

25072548
#[test]
2508-
fn not_test() -> Result<()> {
2549+
fn or_test() -> Result<()> {
25092550
let cases = vec![
2510-
(false, true, false, true),
2511-
(false, false, true, true),
2512-
(true, true, false, false),
2551+
(
2552+
Interval::UNCERTAIN,
2553+
Interval::CERTAINLY_FALSE,
2554+
Interval::UNCERTAIN,
2555+
),
2556+
(
2557+
Interval::UNCERTAIN,
2558+
Interval::UNCERTAIN,
2559+
Interval::UNCERTAIN,
2560+
),
2561+
(
2562+
Interval::UNCERTAIN,
2563+
Interval::CERTAINLY_TRUE,
2564+
Interval::CERTAINLY_TRUE,
2565+
),
2566+
(
2567+
Interval::CERTAINLY_FALSE,
2568+
Interval::CERTAINLY_FALSE,
2569+
Interval::CERTAINLY_FALSE,
2570+
),
2571+
(
2572+
Interval::CERTAINLY_FALSE,
2573+
Interval::UNCERTAIN,
2574+
Interval::UNCERTAIN,
2575+
),
2576+
(
2577+
Interval::CERTAINLY_FALSE,
2578+
Interval::CERTAINLY_TRUE,
2579+
Interval::CERTAINLY_TRUE,
2580+
),
2581+
(
2582+
Interval::CERTAINLY_TRUE,
2583+
Interval::CERTAINLY_FALSE,
2584+
Interval::CERTAINLY_TRUE,
2585+
),
2586+
(
2587+
Interval::CERTAINLY_TRUE,
2588+
Interval::UNCERTAIN,
2589+
Interval::CERTAINLY_TRUE,
2590+
),
2591+
(
2592+
Interval::CERTAINLY_TRUE,
2593+
Interval::CERTAINLY_TRUE,
2594+
Interval::CERTAINLY_TRUE,
2595+
),
25132596
];
25142597

25152598
for case in cases {
25162599
assert_eq!(
2517-
Interval::make(Some(case.0), Some(case.1))?.not()?,
2518-
Interval::make(Some(case.2), Some(case.3))?
2600+
case.0.or(&case.1)?,
2601+
case.2,
2602+
"Failed for {} OR {}",
2603+
case.0,
2604+
case.1
25192605
);
25202606
}
25212607
Ok(())
25222608
}
25232609

2610+
#[test]
2611+
fn not_test() -> Result<()> {
2612+
let cases = vec![
2613+
(Interval::UNCERTAIN, Interval::UNCERTAIN),
2614+
(Interval::CERTAINLY_FALSE, Interval::CERTAINLY_TRUE),
2615+
(Interval::CERTAINLY_TRUE, Interval::CERTAINLY_FALSE),
2616+
];
2617+
2618+
for case in cases {
2619+
assert_eq!(case.0.not()?, case.1, "Failed for NOT {}", case.0);
2620+
}
2621+
Ok(())
2622+
}
2623+
25242624
#[test]
25252625
fn test_and_or_with_normalized_boolean_intervals() -> Result<()> {
25262626
// Verify that NULL boolean bounds are normalized and don't cause errors

0 commit comments

Comments
 (0)