Repository navigation
Expand file tree
/
Copy pathbreakeven_test.go
More file actions
85 lines (80 loc) · 3.53 KB
/
Copy pathbreakeven_test.go
File metadata and controls
85 lines (80 loc) · 3.53 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package common //nolint:revive // see breakeven.go
import (
"math"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBreakEven(t *testing.T) {
t.Parallel()
tests := []struct {
name string
rec Recommendation
wantMonth float64
wantKnown bool
}{
{"provider value wins", Recommendation{BreakEvenMonths: 9, CommitmentCost: 1, Term: "1yr"}, 9, true},
{"no upfront is zero and known", Recommendation{CommitmentCost: 0, EstimatedSavings: 50, Term: "1yr"}, 0, true},
// OD 100/mo, 1yr all-upfront 720, net savings 40/mo: gross 100/mo, 7.2 months.
{"all upfront 1yr", Recommendation{CommitmentCost: 720, EstimatedSavings: 40, Term: "1yr"}, 7.2, true},
// 3yr partial: upfront 360, net 30/mo, amortized 10/mo, gross 40/mo -> 9 months.
{"partial upfront 3yr", Recommendation{CommitmentCost: 360, EstimatedSavings: 30, Term: "3yr"}, 9, true},
{"term alias", Recommendation{CommitmentCost: 360, EstimatedSavings: 30, Term: "P3Y"}, 9, true},
{"never pays back", Recommendation{CommitmentCost: 120, EstimatedSavings: -10, Term: "1yr"}, math.Inf(1), true},
{"unknown term", Recommendation{CommitmentCost: 100, EstimatedSavings: 10, Term: "5yr"}, 0, false},
{"empty term", Recommendation{CommitmentCost: 100, EstimatedSavings: 10}, 0, false},
{"negative upfront", Recommendation{CommitmentCost: -1, EstimatedSavings: 10, Term: "1yr"}, 0, false},
{"nan savings", Recommendation{CommitmentCost: 10, EstimatedSavings: math.NaN(), Term: "1yr"}, 0, false},
// #392: a zero upfront on an upfront-bearing payment option is a missing price.
{"azure advisor upfront variant", Recommendation{PaymentOption: "upfront", EstimatedSavings: 50, Term: "1yr"}, 0, false},
{"all upfront without price", Recommendation{PaymentOption: "all-upfront", EstimatedSavings: 50, Term: "3yr"}, 0, false},
{"partial upfront without price", Recommendation{PaymentOption: "partial-upfront", EstimatedSavings: 50, Term: "1yr"}, 0, false},
{"no upfront option is known zero", Recommendation{PaymentOption: "no-upfront", EstimatedSavings: 50, Term: "1yr"}, 0, true},
{"azure monthly variant is known zero", Recommendation{PaymentOption: "monthly", EstimatedSavings: 50, Term: "1yr"}, 0, true},
{"provider value wins over missing upfront", Recommendation{BreakEvenMonths: 9, PaymentOption: "all-upfront", Term: "1yr"}, 9, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, known := BreakEven(tt.rec)
assert.Equal(t, tt.wantKnown, known)
assert.InDelta(t, tt.wantMonth, got, 1e-9)
})
}
}
func TestBreakEven_InvariantUnderScaling(t *testing.T) {
t.Parallel()
rec := Recommendation{CommitmentCost: 720, EstimatedSavings: 40, Term: "1yr"}
before, _ := BreakEven(rec)
after, _ := BreakEven(ScaleRecommendationCosts(rec, 0.4))
assert.InDelta(t, before, after, 1e-9)
}
func TestUpfrontPriceUnknown(t *testing.T) {
t.Parallel()
tests := []struct {
payment string
cost float64
want bool
}{
{"all-upfront", 0, true},
{"partial-upfront", 0, true},
{"upfront", 0, true},
{"partial", 0, true},
{"All Upfront", 0, true},
{" Partial Upfront ", 0, true},
{"ALL_UPFRONT", 0, true},
{"all-upfront", 720, false},
{"upfront", 0.01, false},
{"no-upfront", 0, false},
{"No Upfront", 0, false},
{"NO_UPFRONT", 0, false},
{"monthly", 0, false},
{"", 0, false},
{"weekly-bananas", 0, false},
}
for _, tt := range tests {
t.Run(tt.payment, func(t *testing.T) {
t.Parallel()
assert.Equal(t, tt.want, UpfrontPriceUnknown(Recommendation{PaymentOption: tt.payment, CommitmentCost: tt.cost}))
})
}
}