mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 04:07:47 +08:00
Improve the code coverage of the gtype module (#1975)
This commit is contained in:
parent
0e6becc36d
commit
8ed57c6468
@ -27,7 +27,19 @@ func Test_Bool(t *testing.T) {
|
||||
t.AssertEQ(iClone1.Set(true), false)
|
||||
t.AssertEQ(iClone1.Val(), true)
|
||||
|
||||
// 空参测试
|
||||
t.AssertEQ(iClone1.Cas(false, true), false)
|
||||
t.AssertEQ(iClone1.String(), "true")
|
||||
t.AssertEQ(iClone1.Cas(true, false), true)
|
||||
t.AssertEQ(iClone1.String(), "false")
|
||||
|
||||
copyVal := i1.DeepCopy()
|
||||
iClone.Set(true)
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
iClone = nil
|
||||
copyVal = iClone.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
|
||||
// empty param test
|
||||
i2 := gtype.NewBool()
|
||||
t.AssertEQ(i2.Val(), false)
|
||||
})
|
||||
|
@ -34,9 +34,21 @@ func Test_Byte(t *testing.T) {
|
||||
wg.Wait()
|
||||
t.AssertEQ(byte(addTimes), i.Val())
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewByte()
|
||||
t.AssertEQ(i1.Val(), byte(0))
|
||||
|
||||
i2 := gtype.NewByte(byte(64))
|
||||
t.AssertEQ(i2.String(), "64")
|
||||
t.AssertEQ(i2.Cas(byte(63), byte(65)), false)
|
||||
t.AssertEQ(i2.Cas(byte(64), byte(65)), true)
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set(byte(65))
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -22,9 +22,19 @@ func Test_Bytes(t *testing.T) {
|
||||
t.AssertEQ(iClone.Set([]byte("123")), []byte("abc"))
|
||||
t.AssertEQ(iClone.Val(), []byte("123"))
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewBytes()
|
||||
t.AssertEQ(i1.Val(), nil)
|
||||
|
||||
i2 := gtype.NewBytes([]byte("abc"))
|
||||
t.Assert(i2.String(), "abc")
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set([]byte("def"))
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,22 @@ func Test_Float32(t *testing.T) {
|
||||
t.AssertEQ(iClone.Set(0.1), float32(0))
|
||||
t.AssertEQ(iClone.Val(), float32(0.1))
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewFloat32()
|
||||
t.AssertEQ(i1.Val(), float32(0))
|
||||
|
||||
i2 := gtype.NewFloat32(1.23)
|
||||
t.AssertEQ(i2.Add(3.21), float32(4.44))
|
||||
t.AssertEQ(i2.Cas(4.45, 5.55), false)
|
||||
t.AssertEQ(i2.Cas(4.44, 5.55), true)
|
||||
t.AssertEQ(i2.String(), "5.55")
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set(float32(6.66))
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -22,9 +22,22 @@ func Test_Float64(t *testing.T) {
|
||||
iClone := i.Clone()
|
||||
t.AssertEQ(iClone.Set(0.1), float64(0))
|
||||
t.AssertEQ(iClone.Val(), float64(0.1))
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewFloat64()
|
||||
t.AssertEQ(i1.Val(), float64(0))
|
||||
|
||||
i2 := gtype.NewFloat64(1.1)
|
||||
t.AssertEQ(i2.Add(3.3), 4.4)
|
||||
t.AssertEQ(i2.Cas(4.5, 5.5), false)
|
||||
t.AssertEQ(i2.Cas(4.4, 5.5), true)
|
||||
t.AssertEQ(i2.String(), "5.5")
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set(6.6)
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -35,9 +35,22 @@ func Test_Int32(t *testing.T) {
|
||||
wg.Wait()
|
||||
t.AssertEQ(int32(addTimes), i.Val())
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewInt32()
|
||||
t.AssertEQ(i1.Val(), int32(0))
|
||||
|
||||
i2 := gtype.NewInt32(11)
|
||||
t.AssertEQ(i2.Add(1), int32(12))
|
||||
t.AssertEQ(i2.Cas(11, 13), false)
|
||||
t.AssertEQ(i2.Cas(12, 13), true)
|
||||
t.AssertEQ(i2.String(), "13")
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set(14)
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -35,9 +35,22 @@ func Test_Int64(t *testing.T) {
|
||||
wg.Wait()
|
||||
t.AssertEQ(int64(addTimes), i.Val())
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewInt64()
|
||||
t.AssertEQ(i1.Val(), int64(0))
|
||||
|
||||
i2 := gtype.NewInt64(11)
|
||||
t.AssertEQ(i2.Add(1), int64(12))
|
||||
t.AssertEQ(i2.Cas(11, 13), false)
|
||||
t.AssertEQ(i2.Cas(12, 13), true)
|
||||
t.AssertEQ(i2.String(), "13")
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set(14)
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -34,9 +34,22 @@ func Test_Int(t *testing.T) {
|
||||
wg.Wait()
|
||||
t.AssertEQ(addTimes, i.Val())
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewInt()
|
||||
t.AssertEQ(i1.Val(), 0)
|
||||
|
||||
i2 := gtype.NewInt(11)
|
||||
t.AssertEQ(i2.Add(1), 12)
|
||||
t.AssertEQ(i2.Cas(11, 13), false)
|
||||
t.AssertEQ(i2.Cas(12, 13), true)
|
||||
t.AssertEQ(i2.String(), "13")
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set(14)
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -24,9 +24,18 @@ func Test_Interface(t *testing.T) {
|
||||
t.AssertEQ(iClone.Set(t2), t1)
|
||||
t.AssertEQ(iClone.Val().(Temp), t2)
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.New()
|
||||
t.AssertEQ(i1.Val(), nil)
|
||||
|
||||
i2 := gtype.New("gf")
|
||||
t.AssertEQ(i2.String(), "gf")
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set("goframe")
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,15 @@ func Test_String(t *testing.T) {
|
||||
iClone := i.Clone()
|
||||
t.AssertEQ(iClone.Set("123"), "abc")
|
||||
t.AssertEQ(iClone.Val(), "123")
|
||||
|
||||
// 空参测试
|
||||
t.AssertEQ(iClone.String(), "123")
|
||||
//
|
||||
copyVal := iClone.DeepCopy()
|
||||
iClone.Set("124")
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
iClone = nil
|
||||
copyVal = iClone.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
// empty param test
|
||||
i1 := gtype.NewString()
|
||||
t.AssertEQ(i1.Val(), "")
|
||||
})
|
||||
|
@ -35,9 +35,22 @@ func Test_Uint32(t *testing.T) {
|
||||
wg.Wait()
|
||||
t.AssertEQ(uint32(addTimes), i.Val())
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewUint32()
|
||||
t.AssertEQ(i1.Val(), uint32(0))
|
||||
|
||||
i2 := gtype.NewUint32(11)
|
||||
t.AssertEQ(i2.Add(1), uint32(12))
|
||||
t.AssertEQ(i2.Cas(11, 13), false)
|
||||
t.AssertEQ(i2.Cas(12, 13), true)
|
||||
t.AssertEQ(i2.String(), "13")
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set(14)
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -40,9 +40,22 @@ func Test_Uint64(t *testing.T) {
|
||||
wg.Wait()
|
||||
t.AssertEQ(uint64(addTimes), i.Val())
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewUint64()
|
||||
t.AssertEQ(i1.Val(), uint64(0))
|
||||
|
||||
i2 := gtype.NewUint64(11)
|
||||
t.AssertEQ(i2.Add(1), uint64(12))
|
||||
t.AssertEQ(i2.Cas(11, 13), false)
|
||||
t.AssertEQ(i2.Cas(12, 13), true)
|
||||
t.AssertEQ(i2.String(), "13")
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set(14)
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
func Test_Uint64_JSON(t *testing.T) {
|
||||
|
@ -34,9 +34,22 @@ func Test_Uint(t *testing.T) {
|
||||
wg.Wait()
|
||||
t.AssertEQ(uint(addTimes), i.Val())
|
||||
|
||||
// 空参测试
|
||||
// empty param test
|
||||
i1 := gtype.NewUint()
|
||||
t.AssertEQ(i1.Val(), uint(0))
|
||||
|
||||
i2 := gtype.NewUint(11)
|
||||
t.AssertEQ(i2.Add(1), uint(12))
|
||||
t.AssertEQ(i2.Cas(11, 13), false)
|
||||
t.AssertEQ(i2.Cas(12, 13), true)
|
||||
t.AssertEQ(i2.String(), "13")
|
||||
|
||||
copyVal := i2.DeepCopy()
|
||||
i2.Set(14)
|
||||
t.AssertNE(copyVal, iClone.Val())
|
||||
i2 = nil
|
||||
copyVal = i2.DeepCopy()
|
||||
t.AssertNil(copyVal)
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user