(t *testing.T)
| 711 | } |
| 712 | |
| 713 | func TestAverageInterval(t *testing.T) { |
| 714 | err := Init(nil) |
| 715 | require.NoError(t, err) |
| 716 | |
| 717 | // Use a fixed base time to eliminate execution time variance |
| 718 | baseTime := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC) |
| 719 | |
| 720 | tests := []struct { |
| 721 | name string |
| 722 | env map[string]any |
| 723 | code string |
| 724 | want time.Duration |
| 725 | }{ |
| 726 | { |
| 727 | name: "AverageInterval() test: two times with 1 second difference", |
| 728 | env: map[string]any{ |
| 729 | "times": []time.Time{baseTime, baseTime.Add(time.Second)}, |
| 730 | }, |
| 731 | code: "AverageInterval(times)", |
| 732 | want: time.Second, |
| 733 | }, |
| 734 | { |
| 735 | name: "AverageInterval() test: two times with 1 second difference (reverse order)", |
| 736 | env: map[string]any{ |
| 737 | "times": []time.Time{baseTime.Add(time.Second), baseTime}, |
| 738 | }, |
| 739 | code: "AverageInterval(times)", |
| 740 | want: time.Second, |
| 741 | }, |
| 742 | { |
| 743 | name: "AverageInterval() test: three times with varying intervals", |
| 744 | env: map[string]any{ |
| 745 | "times": []time.Time{ |
| 746 | baseTime, |
| 747 | baseTime.Add(2 * time.Second), // 2s gap |
| 748 | baseTime.Add(6 * time.Second), // 4s gap |
| 749 | }, |
| 750 | }, |
| 751 | code: "AverageInterval(times)", |
| 752 | want: 3 * time.Second, // (2s + 4s) / 2 = 3s average |
| 753 | }, |
| 754 | { |
| 755 | name: "AverageInterval() test: four times with equal intervals", |
| 756 | env: map[string]any{ |
| 757 | "times": []time.Time{ |
| 758 | baseTime, |
| 759 | baseTime.Add(time.Hour), |
| 760 | baseTime.Add(2 * time.Hour), |
| 761 | baseTime.Add(3 * time.Hour), |
| 762 | }, |
| 763 | }, |
| 764 | code: "AverageInterval(times)", |
| 765 | want: time.Hour, // all intervals are 1 hour |
| 766 | }, |
| 767 | } |
| 768 | |
| 769 | for _, test := range tests { |
| 770 | t.Run(test.name, func(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…