@@ -383,6 +383,12 @@ struct IncompleteInterval <: AbstractInterval{Int} end
383
383
384
384
@testset " Union and intersection" begin
385
385
for T in (Float32,Float64)
386
+ # i1 0 ------>------ 1
387
+ # i2 1/3 ->- 1/2
388
+ # i3 1/2 ------>------ 2
389
+ # i4 2 -->-- 3
390
+ # i5 1.0+ -->-- 2
391
+ # i_empty 0 ------<------ 1
386
392
i1 = zero (T) .. one (T)
387
393
i2 = one (T)/ 3 .. one (T)/ 2
388
394
i3 = one (T)/ 2 .. 2 * one (T)
@@ -391,7 +397,9 @@ struct IncompleteInterval <: AbstractInterval{Int} end
391
397
i_empty = one (T) .. zero (T)
392
398
393
399
# - union of completely overlapping intervals
394
- @test i1 ∪ i2 ≡ i2 ∪ i1 ≡ i1
400
+ # i1 0 ------>------ 1
401
+ # i2 1/3 ->- 1/2
402
+ @test (@inferred i1 ∪ i2) ≡ (@inferred i2 ∪ i1) ≡ i1
395
403
@test Interval {:open,:closed} (i1) ∪ Interval {:open,:closed} (i2) ≡
396
404
Interval {:open,:closed} (i2) ∪ Interval {:open,:closed} (i1) ≡ Interval {:open,:closed} (i1)
397
405
@test Interval {:closed,:open} (i1) ∪ Interval {:closed,:open} (i2) ≡
@@ -408,7 +416,9 @@ struct IncompleteInterval <: AbstractInterval{Int} end
408
416
@test Interval {:open,:closed} (i1) ∪ Interval {:closed,:open} (i2) ≡ Interval {:closed,:open} (i2) ∪ Interval {:open,:closed} (i1) ≡ Interval {:open,:closed} (i1)
409
417
410
418
# - intersection of completely overlapping intervals
411
- @test i1 ∩ i2 ≡ i2 ∩ i1 ≡ i2
419
+ # i1 0 ------>------ 1
420
+ # i2 1/3 ->- 1/2
421
+ @test (@inferred i1 ∩ i2) ≡ (@inferred i2 ∩ i1) ≡ i2
412
422
@test Interval {:open,:closed} (i1) ∩ Interval {:open,:closed} (i2) ≡
413
423
Interval {:open,:closed} (i2) ∩ Interval {:open,:closed} (i1) ≡ Interval {:open,:closed} (i2)
414
424
@test Interval {:closed,:open} (i1) ∩ Interval {:closed,:open} (i2) ≡
@@ -427,8 +437,10 @@ struct IncompleteInterval <: AbstractInterval{Int} end
427
437
428
438
429
439
# - union of partially overlapping intervals
440
+ # i1 0 ------>------ 1
441
+ # i3 1/2 ------>------ 2
430
442
d = zero (T) .. 2 * one (T)
431
- @test i1 ∪ i3 ≡ i3 ∪ i1 ≡ d
443
+ @test ( @inferred i1 ∪ i3) ≡ ( @inferred i3 ∪ i1) ≡ d
432
444
@test Interval {:open,:closed} (i1) ∪ Interval {:open,:closed} (i3) ≡
433
445
Interval {:open,:closed} (i3) ∪ Interval {:open,:closed} (i1) ≡ Interval {:open,:closed} (d)
434
446
@test Interval {:closed,:open} (i1) ∪ Interval {:closed,:open} (i3) ≡
@@ -444,11 +456,11 @@ struct IncompleteInterval <: AbstractInterval{Int} end
444
456
@test Interval {:open,:closed} (i1) ∪ OpenInterval (i3) ≡ OpenInterval (i3) ∪ Interval {:open,:closed} (i1) ≡ OpenInterval (d)
445
457
@test Interval {:open,:closed} (i1) ∪ Interval {:closed,:open} (i3) ≡ Interval {:closed,:open} (i3) ∪ Interval {:open,:closed} (i1) ≡ OpenInterval (d)
446
458
447
-
448
-
449
459
# - intersection of partially overlapping intervals
460
+ # i1 0 ------>------ 1
461
+ # i3 1/2 ------>------ 2
450
462
d = one (T)/ 2 .. one (T)
451
- @test i1 ∩ i3 ≡ i3 ∩ i1 ≡ d
463
+ @test ( @inferred i1 ∩ i3) ≡ ( @inferred i3 ∩ i1) ≡ d
452
464
@test Interval {:open,:closed} (i1) ∩ Interval {:open,:closed} (i3) ≡
453
465
Interval {:open,:closed} (i3) ∩ Interval {:open,:closed} (i1) ≡ Interval {:open,:closed} (d)
454
466
@test Interval {:closed,:open} (i1) ∩ Interval {:closed,:open} (i3) ≡
@@ -467,8 +479,10 @@ struct IncompleteInterval <: AbstractInterval{Int} end
467
479
468
480
469
481
# - union of barely overlapping intervals
482
+ # i2 1/3 ->- 1/2
483
+ # i3 1/2 ------>------ 2
470
484
d = one (T)/ 3 .. 2 * one (T)
471
- @test i2 ∪ i3 ≡ i3 ∪ i2 ≡ d
485
+ @test ( @inferred i2 ∪ i3) ≡ ( @inferred i3 ∪ i2) ≡ d
472
486
@test Interval {:open,:closed} (i2) ∪ Interval {:open,:closed} (i3) ≡
473
487
Interval {:open,:closed} (i3) ∪ Interval {:open,:closed} (i2) ≡ Interval {:open,:closed} (d)
474
488
@test Interval {:closed,:open} (i2) ∪ Interval {:closed,:open} (i3) ≡
@@ -483,8 +497,10 @@ struct IncompleteInterval <: AbstractInterval{Int} end
483
497
@test Interval {:open,:closed} (i2) ∪ Interval {:closed,:open} (i3) ≡ Interval {:closed,:open} (i3) ∪ Interval {:open,:closed} (i2) ≡ OpenInterval (d)
484
498
485
499
# - intersection of barely overlapping intervals
500
+ # i2 1/3 ->- 1/2
501
+ # i3 1/2 ------>------ 2
486
502
d = one (T)/ 2 .. one (T)/ 2
487
- @test i2 ∩ i3 ≡ i3 ∩ i2 ≡ d
503
+ @test ( @inferred i2 ∩ i3) ≡ ( @inferred i3 ∩ i2) ≡ d
488
504
@test Interval {:open,:closed} (i2) ∩ Interval {:open,:closed} (i3) ≡
489
505
Interval {:open,:closed} (i3) ∩ Interval {:open,:closed} (i2) ≡ Interval {:open,:closed} (d)
490
506
@test Interval {:closed,:open} (i2) ∩ Interval {:closed,:open} (i3) ≡
@@ -505,6 +521,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end
505
521
@test intersect (MyUnitInterval (true ,true ), OpenInterval (0 ,1 )) == OpenInterval (0 ,1 )
506
522
507
523
# - union of non-overlapping intervals
524
+ # i1 0 ------>------ 1
525
+ # i4 2 -->-- 3
508
526
@test_throws ArgumentError i1 ∪ i4
509
527
@test_throws ArgumentError i4 ∪ i1
510
528
@test_throws ArgumentError OpenInterval (i1) ∪ i4
@@ -513,6 +531,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end
513
531
@test_throws ArgumentError Interval {:closed,:open} (i1) ∪ OpenInterval (i4)
514
532
515
533
# - union of almost-overlapping intervals
534
+ # i1 0 ------>------ 1
535
+ # i5 1.0+ -->-- 2
516
536
@test_throws ArgumentError i1 ∪ i5
517
537
@test_throws ArgumentError i5 ∪ i1
518
538
@test_throws ArgumentError OpenInterval (i1) ∪ i5
@@ -521,6 +541,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end
521
541
@test_throws ArgumentError Interval {:closed,:open} (i1) ∪ OpenInterval (i5)
522
542
523
543
# - intersection of non-overlapping intervals
544
+ # i1 0 ------>------ 1
545
+ # i4 2 -->-- 3
524
546
@test isempty (i1 ∩ i4)
525
547
@test isempty (i4 ∩ i1)
526
548
@test isempty (OpenInterval (i1) ∩ i4)
@@ -534,6 +556,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end
534
556
535
557
536
558
# - intersection of almost-overlapping intervals
559
+ # i1 0 ------>------ 1
560
+ # i5 1.0+ -->-- 2
537
561
@test isempty (i1 ∩ i5)
538
562
@test isempty (i5 ∩ i1)
539
563
@test isempty (OpenInterval (i1) ∩ i5)
@@ -546,6 +570,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end
546
570
@test isdisjoint (Interval {:closed,:open} (i1), i5)
547
571
548
572
# - union of interval with empty
573
+ # i1 0 ------>------ 1
574
+ # i_empty 0 ------<------ 1
549
575
@test i1 ∪ i_empty ≡ i_empty ∪ i1 ≡ i1
550
576
@test Interval {:open,:closed} (i1) ∪ Interval {:open,:closed} (i_empty) ≡
551
577
Interval {:open,:closed} (i_empty) ∪ Interval {:open,:closed} (i1) ≡ Interval {:open,:closed} (i1)
@@ -563,6 +589,8 @@ struct IncompleteInterval <: AbstractInterval{Int} end
563
589
@test Interval {:open,:closed} (i1) ∪ Interval {:closed,:open} (i_empty) ≡ Interval {:closed,:open} (i_empty) ∪ Interval {:open,:closed} (i1) ≡ Interval {:open,:closed} (i1)
564
590
565
591
# - intersection of interval with empty
592
+ # i1 0 ------>------ 1
593
+ # i_empty 0 ------<------ 1
566
594
@test isempty (i1 ∩ i_empty)
567
595
@test isempty (i_empty ∩ i1)
568
596
@test isempty (OpenInterval (i1) ∩ i_empty)
0 commit comments