@@ -534,43 +534,54 @@ let d = Dates.Day(1)
534
534
@test (Dates. Date (2000 ): d: Dates. Date (2001 )) - d == (Dates. Date (2000 ) - d: d: Dates. Date (2001 ) - d)
535
535
end
536
536
537
- # Time ranges
538
- dr = Dates. Time (23 , 1 , 1 ): Dates. Second (1 ): Dates. Time (23 , 2 , 1 )
539
- dr1 = Dates. Time (23 , 1 , 1 ): Dates. Second (1 ): Dates. Time (23 , 1 , 1 )
540
- dr2 = Dates. Time (23 , 1 , 1 ): Dates. Second (1 ): Dates. Time (22 , 2 , 1 ) # empty range
541
- dr3 = Dates. Time (23 , 1 , 1 ): Dates. Minute (- 1 ): Dates. Time (22 , 1 , 1 ) # negative step
542
- dr4 = range (Dates. Time (0 ), step= Dates. Hour (1 ), length= 23 ) # by step, length
543
-
544
- # Big ranges
545
- dr8 = typemin (Dates. Time): Dates. Second (1 ): typemax (Dates. Time)
546
- dr9 = typemin (Dates. Time): Dates. Nanosecond (1 ): typemax (Dates. Time)
547
- # Other steps
548
- dr10 = typemax (Dates. Time): Dates. Microsecond (- 1 ): typemin (Dates. Time)
549
- dr11 = typemin (Dates. Time): Dates. Millisecond (1 ): typemax (Dates. Time)
550
- dr12 = typemin (Dates. Time): Dates. Minute (1 ): typemax (Dates. Time)
551
- dr13 = typemin (Dates. Time): Dates. Hour (1 ): typemax (Dates. Time)
552
- dr14 = typemin (Dates. Time): Dates. Millisecond (10 ): typemax (Dates. Time)
553
- dr15 = typemin (Dates. Time): Dates. Minute (100 ): typemax (Dates. Time)
554
- dr16 = typemin (Dates. Time): Dates. Hour (1000 ): typemax (Dates. Time)
555
- dr17 = typemax (Dates. Time): Dates. Millisecond (- 10000 ): typemin (Dates. Time)
556
- dr18 = typemax (Dates. Time): Dates. Minute (- 100 ): typemin (Dates. Time)
557
- dr19 = typemax (Dates. Time): Dates. Hour (- 10 ): typemin (Dates. Time)
558
- dr20 = typemin (Dates. Time): Dates. Microsecond (2 ): typemax (Dates. Time)
559
-
560
- drs = Any[dr, dr1, dr2, dr3, dr4, dr8, dr9, dr10,
561
- dr11, dr12, dr13, dr14, dr15, dr16, dr17, dr18, dr19, dr20]
537
+ # small Time ranges
538
+ small_ranges_with = Any[
539
+ Dates. Time (23 , 1 , 1 ): Dates. Second (1 ): Dates. Time (23 , 2 , 1 ),
540
+ Dates. Time (23 , 1 , 1 ): Dates. Second (1 ): Dates. Time (23 , 1 , 1 ),
541
+ Dates. Time (23 , 1 , 1 ): Dates. Minute (- 1 ): Dates. Time (22 , 1 , 1 ) # negative step
542
+ ]
543
+ empty_range = Dates. Time (23 , 1 , 1 ): Dates. Second (1 ): Dates. Time (22 , 2 , 1 )
544
+ small_ranges_without = Any[
545
+ empty_range,
546
+ range (Dates. Time (0 ), step= Dates. Hour (1 ), length= 23 ) # by step, length
547
+ ]
548
+ small_ranges = Any[small_ranges_with; small_ranges_without]
549
+
550
+ # Big ranges of various steps, increasing and decreasing
551
+ big_ranges = Any[
552
+ [typemin (Dates. Time): step: typemax (Dates. Time) for step in [
553
+ Dates. Second (1 )
554
+ Dates. Nanosecond (1 )
555
+ Dates. Microsecond (2 )
556
+ Dates. Millisecond (1 )
557
+ Dates. Minute (1 )
558
+ Dates. Hour (1 )
559
+ Dates. Millisecond (10 )
560
+ Dates. Minute (100 )
561
+ Dates. Hour (1000 )
562
+ ]]
563
+ [typemax (Dates. Time): step: typemin (Dates. Time) for step in [
564
+ Dates. Microsecond (- 1 )
565
+ Dates. Millisecond (- 10000 )
566
+ Dates. Minute (- 100 )
567
+ Dates. Hour (- 10 )
568
+ ]]
569
+ ]
570
+
571
+
572
+ drs = Any[small_ranges; big_ranges]
562
573
563
574
@test map (length, drs) == map (x-> size (x)[1 ], drs)
564
- @test all (x-> findall (in (x), x) == [1 : length (x);], drs[ 1 : 4 ] )
565
- @test isempty (dr2 )
575
+ @test all (x-> findall (in (x), x) == [1 : length (x);], small_ranges )
576
+ @test isempty (empty_range )
566
577
@test all (x-> reverse (x) == last (x): - step (x): first (x), drs)
567
- @test all (x-> minimum (x) == (step (x) < zero (step (x)) ? last (x) : first (x)), drs[ 4 : end ] )
568
- @test all (x-> maximum (x) == (step (x) < zero (step (x)) ? first (x) : last (x)), drs[ 4 : end ] )
569
- @test_throws MethodError dr .+ 1
578
+ @test all (x-> minimum (x) == (step (x) < zero (step (x)) ? last (x) : first (x)), big_ranges )
579
+ @test all (x-> maximum (x) == (step (x) < zero (step (x)) ? first (x) : last (x)), big_ranges )
580
+ @test_throws MethodError drs[ 1 ] .+ 1
570
581
571
582
a = Dates. Time (23 , 1 , 1 )
572
- @test map (x-> a in x, drs[ 1 : 4 ]) == [ true , true , false , true ]
573
- @test a in dr
583
+ @test all (x-> a in x, small_ranges_with)
584
+ @test all (x -> ! ( a in x), small_ranges_without)
574
585
575
586
@test all (x-> sort (x) == (step (x) < zero (step (x)) ? reverse (x) : x), drs)
576
587
@test all (x-> step (x) < zero (step (x)) ? issorted (reverse (x)) : issorted (x), drs)
613
624
@test_throws OverflowError StepRange (dmin, Day (1 ), dmax)
614
625
end
615
626
627
+ @testset " StepRangeLen{Time} periodicity, indexing" begin
628
+ r = range (Time (0 ), step = Hour (9 ), length = 5 )
629
+ @test length (r) == 5
630
+ @test r[begin : end ] == [Time (0 ), Time (9 ), Time (18 ), Time (3 ), Time (12 )]
631
+ end
632
+
633
+
634
+
616
635
end # RangesTest module
0 commit comments