|
| 1 | +package degradation_detector |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | +) |
| 8 | + |
| 9 | +func TestThresholdGreaterThan_TriggersWhenStrictlyGreater(t *testing.T) { |
| 10 | + t.Parallel() |
| 11 | + values := []int{90, 96} |
| 12 | + builds := []string{"b0", "b1"} |
| 13 | + times := []int64{0, 123} |
| 14 | + |
| 15 | + settings := AnalysisSettings{ |
| 16 | + AnalysisKind: ThresholdAnalysis, |
| 17 | + ThresholdMode: ThresholdGreaterThan, |
| 18 | + ThresholdValue: 95, |
| 19 | + } |
| 20 | + |
| 21 | + degradations := detectDegradations(values, builds, times, settings) |
| 22 | + assert.Len(t, degradations, 1) |
| 23 | + deg := degradations[0] |
| 24 | + assert.Equal(t, "b1", deg.Build) |
| 25 | + assert.Equal(t, int64(123), deg.timestamp) |
| 26 | + assert.True(t, deg.IsDegradation) |
| 27 | + assert.Equal(t, 90.0, deg.medianValues.previousValue) |
| 28 | + assert.Equal(t, 96.0, deg.medianValues.newValue) |
| 29 | +} |
| 30 | + |
| 31 | +func TestThresholdGreaterThan_DoesNotTriggerOnEqual(t *testing.T) { |
| 32 | + t.Parallel() |
| 33 | + values := []int{95} |
| 34 | + builds := []string{"b0"} |
| 35 | + times := []int64{0} |
| 36 | + |
| 37 | + settings := AnalysisSettings{ |
| 38 | + AnalysisKind: ThresholdAnalysis, |
| 39 | + ThresholdMode: ThresholdGreaterThan, |
| 40 | + ThresholdValue: 95, |
| 41 | + } |
| 42 | + |
| 43 | + degradations := detectDegradations(values, builds, times, settings) |
| 44 | + assert.Empty(t, degradations) |
| 45 | +} |
| 46 | + |
| 47 | +func TestThresholdLessThan_TriggersWhenStrictlyLess(t *testing.T) { |
| 48 | + t.Parallel() |
| 49 | + values := []int{100, 80} |
| 50 | + builds := []string{"b0", "b1"} |
| 51 | + times := []int64{0, 77} |
| 52 | + |
| 53 | + settings := AnalysisSettings{ |
| 54 | + AnalysisKind: ThresholdAnalysis, |
| 55 | + ThresholdMode: ThresholdLessThan, |
| 56 | + ThresholdValue: 85, |
| 57 | + } |
| 58 | + |
| 59 | + degradations := detectDegradations(values, builds, times, settings) |
| 60 | + assert.Len(t, degradations, 1) |
| 61 | + deg := degradations[0] |
| 62 | + assert.Equal(t, "b1", deg.Build) |
| 63 | + assert.Equal(t, int64(77), deg.timestamp) |
| 64 | + assert.True(t, deg.IsDegradation) |
| 65 | + assert.Equal(t, 100.0, deg.medianValues.previousValue) |
| 66 | + assert.Equal(t, 80.0, deg.medianValues.newValue) |
| 67 | +} |
| 68 | + |
| 69 | +func TestThresholdLessThan_DoesNotTriggerOnEqual(t *testing.T) { |
| 70 | + t.Parallel() |
| 71 | + values := []int{85} |
| 72 | + builds := []string{"b0"} |
| 73 | + times := []int64{0} |
| 74 | + |
| 75 | + settings := AnalysisSettings{ |
| 76 | + AnalysisKind: ThresholdAnalysis, |
| 77 | + ThresholdMode: ThresholdLessThan, |
| 78 | + ThresholdValue: 85, |
| 79 | + } |
| 80 | + |
| 81 | + degradations := detectDegradations(values, builds, times, settings) |
| 82 | + assert.Empty(t, degradations) |
| 83 | +} |
| 84 | + |
| 85 | +func TestThreshold_NoDataReturnsEmpty(t *testing.T) { |
| 86 | + t.Parallel() |
| 87 | + var values []int |
| 88 | + var builds []string |
| 89 | + var times []int64 |
| 90 | + |
| 91 | + settings := AnalysisSettings{ |
| 92 | + AnalysisKind: ThresholdAnalysis, |
| 93 | + ThresholdMode: ThresholdGreaterThan, |
| 94 | + ThresholdValue: 95, |
| 95 | + } |
| 96 | + |
| 97 | + degradations := detectDegradations(values, builds, times, settings) |
| 98 | + assert.Empty(t, degradations) |
| 99 | +} |
0 commit comments