Skip to content

Commit

Permalink
fix tests and greater than comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Feb 26, 2025
1 parent 3133362 commit bae5d2f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/services/workflows/metering.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (v MeteringSpendValue) Div(value MeteringSpendValue) MeteringSpendValue {
}

func (v MeteringSpendValue) GreaterThan(value MeteringSpendValue) bool {
return v.value.GreaterThan(v.value)
return v.value.GreaterThan(value.value)
}

func (v MeteringSpendValue) String() string {
Expand Down
31 changes: 27 additions & 4 deletions core/services/workflows/metering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/shopspring/decimal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"

"github.com/smartcontractkit/chainlink/v2/core/services/workflows"
)
Expand Down Expand Up @@ -39,7 +40,14 @@ func TestMeteringReport(t *testing.T) {
testUnitB: testUnitB.DecimalToSpendValue(decimal.NewFromFloat(0.2)),
}

assert.Equal(t, expected, report.MedianSpend())
median := report.MedianSpend()

require.Len(t, median, 2)
require.Contains(t, maps.Keys(median), testUnitA)
require.Contains(t, maps.Keys(median), testUnitB)

assert.Equal(t, expected[testUnitA].String(), median[testUnitA].String())
assert.Equal(t, expected[testUnitB].String(), median[testUnitB].String())
})

t.Run("MedianSpend returns median single spend value", func(t *testing.T) {
Expand All @@ -58,7 +66,12 @@ func TestMeteringReport(t *testing.T) {
testUnitA: testUnitA.IntToSpendValue(1),
}

assert.Equal(t, expected, report.MedianSpend())
median := report.MedianSpend()

require.Len(t, median, 1)
require.Contains(t, maps.Keys(median), testUnitA)

assert.Equal(t, expected[testUnitA].String(), median[testUnitA].String())
})

t.Run("MedianSpend returns median odd number of spend values", func(t *testing.T) {
Expand All @@ -79,7 +92,12 @@ func TestMeteringReport(t *testing.T) {
testUnitA: testUnitA.IntToSpendValue(2),
}

assert.Equal(t, expected, report.MedianSpend())
median := report.MedianSpend()

require.Len(t, median, 1)
require.Contains(t, maps.Keys(median), testUnitA)

assert.Equal(t, expected[testUnitA].String(), median[testUnitA].String())
})

t.Run("MedianSpend returns median as average for even number of spend values", func(t *testing.T) {
Expand All @@ -101,6 +119,11 @@ func TestMeteringReport(t *testing.T) {
testUnitA: testUnitA.DecimalToSpendValue(decimal.NewFromFloat(2.5)),
}

assert.Equal(t, expected, report.MedianSpend())
median := report.MedianSpend()

require.Len(t, median, 1)
require.Contains(t, maps.Keys(median), testUnitA)

assert.Equal(t, expected[testUnitA].String(), median[testUnitA].String())
})
}

0 comments on commit bae5d2f

Please sign in to comment.