|
| 1 | +package x |
| 2 | + |
| 3 | +import ( |
| 4 | + "log" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | +) |
| 9 | + |
| 10 | +func TestS2I64(t *testing.T) { |
| 11 | + cases := []struct { |
| 12 | + in string |
| 13 | + exp int64 |
| 14 | + }{ |
| 15 | + {"0", 0}, |
| 16 | + {"999", 999}, |
| 17 | + {"-999", -999}, |
| 18 | + } |
| 19 | + for _, c := range cases { |
| 20 | + res := S2I64(c.in) |
| 21 | + log.Printf("%+v\n"+"res--------------->", res) |
| 22 | + assert.Equal(t, c.exp, res) |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +func TestI2S(t *testing.T) { |
| 27 | + type cs[T Int] struct { |
| 28 | + in T |
| 29 | + exp string |
| 30 | + } |
| 31 | + c1 := cs[int]{0, "0"} |
| 32 | + res := I2S(c1.in) |
| 33 | + log.Printf("res--------------->"+"%+v\n", res) |
| 34 | + assert.Equal(t, c1.exp, res) |
| 35 | + |
| 36 | + c2 := cs[int8]{9, "9"} |
| 37 | + res = I2S(c2.in) |
| 38 | + log.Printf("res--------------->"+"%+v\n", res) |
| 39 | + assert.Equal(t, c2.exp, res) |
| 40 | + |
| 41 | + c3 := cs[int32]{999, "999"} |
| 42 | + res = I2S(c3.in) |
| 43 | + log.Printf("res--------------->"+"%+v\n", res) |
| 44 | + assert.Equal(t, c3.exp, res) |
| 45 | + |
| 46 | + type MyI32 int32 |
| 47 | + c4 := cs[MyI32]{999, "999"} |
| 48 | + res = I2S(c4.in) |
| 49 | + log.Printf("res--------------->"+"%+v\n", res) |
| 50 | + assert.Equal(t, c4.exp, res) |
| 51 | + |
| 52 | + c5 := cs[int16]{9999, "9999"} |
| 53 | + res = I2S(c5.in) |
| 54 | + log.Printf("res--------------->"+"%+v\n", res) |
| 55 | + assert.Equal(t, c5.exp, res) |
| 56 | +} |
| 57 | + |
| 58 | +func TestUI2S(t *testing.T) { |
| 59 | + type cs[T Uint] struct { |
| 60 | + in T |
| 61 | + exp string |
| 62 | + } |
| 63 | + c1 := cs[uint8]{0, "0"} |
| 64 | + res := UI2S(c1.in) |
| 65 | + log.Printf("res--------------->"+"%+v\n", res) |
| 66 | + assert.Equal(t, c1.exp, res) |
| 67 | + |
| 68 | + c2 := cs[uint32]{9, "9"} |
| 69 | + res = UI2S(c2.in) |
| 70 | + log.Printf("res--------------->"+"%+v\n", res) |
| 71 | + assert.Equal(t, c2.exp, res) |
| 72 | + |
| 73 | + c3 := cs[uint64]{999, "999"} |
| 74 | + res = UI2S(c3.in) |
| 75 | + log.Printf("res--------------->"+"%+v\n", res) |
| 76 | + assert.Equal(t, c3.exp, res) |
| 77 | +} |
0 commit comments