mirror of
https://github.com/hanzoai/tasks.git
synced 2026-11-03 03:56:04 +00:00
## What changed? Integrate Go 1.26's new `go fix` into workflow. NOTE that the changes caused our linter to fire; a [separate commit](https://github.com/temporalio/temporal/pull/9337/commits/1b23f787aef370098b35829c4d17dcc06230b4c1) addresses those. ## Why? Ensure Go code is standardized/modernized. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [x] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s)
76 lines
1.6 KiB
Go
76 lines
1.6 KiB
Go
package number
|
|
|
|
import (
|
|
"math/rand"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
)
|
|
|
|
type (
|
|
numberSuite struct {
|
|
suite.Suite
|
|
*require.Assertions
|
|
}
|
|
)
|
|
|
|
func TestNumberSuite(t *testing.T) {
|
|
s := new(numberSuite)
|
|
suite.Run(t, s)
|
|
}
|
|
|
|
func (s *numberSuite) SetupSuite() {}
|
|
|
|
func (s *numberSuite) TearDownSuite() {}
|
|
|
|
func (s *numberSuite) SetupTest() {
|
|
s.Assertions = require.New(s.T())
|
|
}
|
|
|
|
func (s *numberSuite) TearDownTest() {
|
|
|
|
}
|
|
|
|
func (s *numberSuite) TestInt() {
|
|
number := rand.Intn(128)
|
|
for _, n := range []any{
|
|
int8(number),
|
|
int16(number),
|
|
int32(number),
|
|
int64(number),
|
|
int(number),
|
|
} {
|
|
s.Equal(float64(number), NewNumber(n).GetFloatOrDefault(rand.Float64()))
|
|
s.Equal(int(number), NewNumber(n).GetIntOrDefault(rand.Int()))
|
|
s.Equal(uint(number), NewNumber(n).GetUintOrDefault(uint(rand.Uint64())))
|
|
}
|
|
}
|
|
|
|
func (s *numberSuite) TestUint() {
|
|
number := rand.Intn(256)
|
|
for _, n := range []any{
|
|
uint8(number),
|
|
uint16(number),
|
|
uint32(number),
|
|
uint64(number),
|
|
uint(number),
|
|
} {
|
|
s.Equal(float64(number), NewNumber(n).GetFloatOrDefault(rand.Float64()))
|
|
s.Equal(int(number), NewNumber(n).GetIntOrDefault(rand.Int()))
|
|
s.Equal(uint(number), NewNumber(n).GetUintOrDefault(uint(rand.Uint64())))
|
|
}
|
|
}
|
|
|
|
func (s *numberSuite) TestFloat() {
|
|
number := rand.Float32() * float32(rand.Int())
|
|
for _, n := range []any{
|
|
float32(number),
|
|
float64(number),
|
|
} {
|
|
s.Equal(float64(number), NewNumber(n).GetFloatOrDefault(rand.Float64()))
|
|
s.Equal(int(number), NewNumber(n).GetIntOrDefault(rand.Int()))
|
|
s.Equal(uint(number), NewNumber(n).GetUintOrDefault(uint(rand.Uint64())))
|
|
}
|
|
}
|