-
Notifications
You must be signed in to change notification settings - Fork 3
/
random_test.go
61 lines (51 loc) · 2.12 KB
/
random_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package timekit
import (
"testing"
"time"
)
func TestRandomDate(t *testing.T) {
startDateTime := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) // Jan 1st 2022
endDateTime := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC) // Jan 1st 2023
result := RandomDate(startDateTime, endDateTime)
// For debugging purposes only.
// fmt.Println("result:", result)
if result.Before(startDateTime) {
t.Errorf("Incorrect date, got %s but was less then start date", result)
}
if result.After(endDateTime) {
t.Errorf("Incorrect date, got %s but was greater then end date", result)
}
}
func TestRandomDateIntervals(t *testing.T) {
startDateTime := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) // Jan 1st 2022
endDateTime := time.Date(2022, 1, 1, 2, 0, 0, 0, time.UTC) // Jan 1st 2023
maxSeconds := int64(60) // 1 minute
drIntervals := RandomDateIntervals(startDateTime, endDateTime, maxSeconds)
for _, dr := range drIntervals {
if dr.Start.Before(startDateTime) {
t.Errorf("Incorrect date, got %s but was less then start date", dr.Start)
}
if dr.Finish.After(endDateTime) {
t.Errorf("Incorrect date, got %s but was greater then end date", dr.Finish)
}
// // For debugging purposes only.
// fmt.Println("startDT:", dr.Start, "finishDT:", dr.Finish)
}
}
func TestRandomSegmentedDateIntervals(t *testing.T) {
startDateTime := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) // Jan 1st 2022
endDateTime := time.Date(2022, 1, 1, 2, 0, 0, 0, time.UTC) // Jan 1st 2023
maxSeconds := int64(60) // 1 minute
totalSegments := int64(3)
segments := RandomSegmentedDateIntervals(startDateTime, endDateTime, maxSeconds, totalSegments)
for _, segment := range segments {
if segment.Interval.Start.Before(startDateTime) {
t.Errorf("Incorrect date, got %s but was less then start date", segment.Interval.Start)
}
if segment.Interval.Finish.After(endDateTime) {
t.Errorf("Incorrect date, got %s but was greater then end date", segment.Interval.Finish)
}
// // For debugging purposes only.
// fmt.Printf("segment %v > interval %v\n", segment.ID, segment.Interval)
}
}