Skip to content

Commit 652501f

Browse files
authored
propose change
1 parent 6092b48 commit 652501f

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

types/conversion_test.go

+14-19
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,35 @@ package types
1515

1616
import (
1717
"testing"
18+
19+
"github.com/stretchr/testify/assert"
20+
"github.com/stretchr/testify/require"
1821
)
1922

2023
func TestUint64ToUint32(t *testing.T) {
2124
tests := []struct {
2225
name string
2326
input uint64
2427
want uint32
25-
errType error
28+
wantErr bool
2629
}{
27-
{"Zero", 0, 0, nil},
28-
{"Max uint32", 4294967295, 4294967295, nil},
29-
{"Overflow", 4294967296, 0, &OutOfRangeError{}},
30-
{"Large overflow", 18446744073709551615, 0, &OutOfRangeError{}},
31-
{"Mid-range value", 2147483648, 2147483648, nil},
30+
{"Zero", 0, 0, false},
31+
{"Max uint32", 4294967295, 4294967295, false},
32+
{"Overflow", 4294967296, 0, true},
33+
{"Large overflow", 18446744073709551615, 0, true},
34+
{"Mid-range value", 2147483648, 2147483648, false},
3235
}
3336

3437
for _, tt := range tests {
3538
t.Run(tt.name, func(t *testing.T) {
3639
got, err := Uint64ToUint32(tt.input)
37-
if tt.errType != nil {
40+
if tt.wantErr {
3841
// Check if the error is of the expected type
39-
if err == nil {
40-
t.Errorf("Expected error type %T, got no error", tt.errType)
41-
} else if _, ok := err.(*OutOfRangeError); !ok {
42-
t.Errorf("Expected error type *OutOfRangeError, got %T", err)
43-
}
42+
require.Error(t, err)
43+
assert.Equal(t, err, &OutOfRangeError{tt.input, "uint32"})
4444
} else {
45-
if err != nil {
46-
t.Errorf("Uint64ToUint32() error = %v, want no error", err)
47-
return
48-
}
49-
if got != tt.want {
50-
t.Errorf("Uint64ToUint32() = %v, want %v", got, tt.want)
51-
}
45+
require.NoError(t, err)
46+
assert.Equal(t, tt.want, got)
5247
}
5348
})
5449
}

0 commit comments

Comments
 (0)