Skip to content

Commit

Permalink
test(logic): put MultiplyUint64Overflow under test
Browse files Browse the repository at this point in the history
  • Loading branch information
ccamel committed Apr 1, 2023
1 parent f668dd1 commit f36c6b1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions x/logic/meter/weighted_meter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package meter

import (
"fmt"
"math"
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestMultiplyUint64Overflow(t *testing.T) {
Convey("Given test cases", t, func() {
testCases := []struct {
a uint64
b uint64
wantResult uint64
wantOverflow bool
}{
{0, 0, 0, false},
{0, 1, 0, false},
{1, 0, 0, false},
{1, 1, 1, false},
{1, math.MaxUint64, math.MaxUint64, false},
{math.MaxUint64, 1, math.MaxUint64, false},
{2, math.MaxUint64, 0, true},
{math.MaxUint64, 2, 0, true},
{math.MaxUint64, math.MaxUint64, 0, true},
}

for _, tc := range testCases {
Convey(fmt.Sprintf("When calling the multiplyUint64Overflow(%d, %d)", tc.a, tc.b), func() {
actual, overflow := multiplyUint64Overflow(tc.a, tc.b)

Convey("Then we should get ()", func() {
So(overflow, ShouldEqual, tc.wantOverflow)
So(actual, ShouldEqual, tc.wantResult)
})
})
}
})
}

0 comments on commit f36c6b1

Please sign in to comment.