From 8ed57c6468c00e9afcd6f345325a55564b52897d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E9=AA=9E?= Date: Mon, 11 Jul 2022 21:29:32 +0800 Subject: [PATCH] Improve the code coverage of the gtype module (#1975) --- container/gtype/gtype_z_unit_bool_test.go | 14 +++++++++++++- container/gtype/gtype_z_unit_byte_test.go | 14 +++++++++++++- container/gtype/gtype_z_unit_bytes_test.go | 12 +++++++++++- container/gtype/gtype_z_unit_float32_test.go | 15 ++++++++++++++- container/gtype/gtype_z_unit_float64_test.go | 15 ++++++++++++++- container/gtype/gtype_z_unit_int32_test.go | 15 ++++++++++++++- container/gtype/gtype_z_unit_int64_test.go | 15 ++++++++++++++- container/gtype/gtype_z_unit_int_test.go | 15 ++++++++++++++- container/gtype/gtype_z_unit_interface_test.go | 11 ++++++++++- container/gtype/gtype_z_unit_string_test.go | 11 +++++++++-- container/gtype/gtype_z_unit_uint32_test.go | 15 ++++++++++++++- container/gtype/gtype_z_unit_uint64_test.go | 15 ++++++++++++++- container/gtype/gtype_z_unit_uint_test.go | 15 ++++++++++++++- 13 files changed, 168 insertions(+), 14 deletions(-) diff --git a/container/gtype/gtype_z_unit_bool_test.go b/container/gtype/gtype_z_unit_bool_test.go index e44c6b456..8174a250d 100644 --- a/container/gtype/gtype_z_unit_bool_test.go +++ b/container/gtype/gtype_z_unit_bool_test.go @@ -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) }) diff --git a/container/gtype/gtype_z_unit_byte_test.go b/container/gtype/gtype_z_unit_byte_test.go index d3b87ec49..72f1fcee7 100644 --- a/container/gtype/gtype_z_unit_byte_test.go +++ b/container/gtype/gtype_z_unit_byte_test.go @@ -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) }) } diff --git a/container/gtype/gtype_z_unit_bytes_test.go b/container/gtype/gtype_z_unit_bytes_test.go index d919c47bf..29e731c77 100644 --- a/container/gtype/gtype_z_unit_bytes_test.go +++ b/container/gtype/gtype_z_unit_bytes_test.go @@ -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) }) } diff --git a/container/gtype/gtype_z_unit_float32_test.go b/container/gtype/gtype_z_unit_float32_test.go index e3e6cd667..26c5c5840 100644 --- a/container/gtype/gtype_z_unit_float32_test.go +++ b/container/gtype/gtype_z_unit_float32_test.go @@ -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) }) } diff --git a/container/gtype/gtype_z_unit_float64_test.go b/container/gtype/gtype_z_unit_float64_test.go index 02339cefd..1bc6b27b9 100644 --- a/container/gtype/gtype_z_unit_float64_test.go +++ b/container/gtype/gtype_z_unit_float64_test.go @@ -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) }) } diff --git a/container/gtype/gtype_z_unit_int32_test.go b/container/gtype/gtype_z_unit_int32_test.go index 996f4d087..445fabee9 100644 --- a/container/gtype/gtype_z_unit_int32_test.go +++ b/container/gtype/gtype_z_unit_int32_test.go @@ -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) }) } diff --git a/container/gtype/gtype_z_unit_int64_test.go b/container/gtype/gtype_z_unit_int64_test.go index f3c74bced..1233f0f45 100644 --- a/container/gtype/gtype_z_unit_int64_test.go +++ b/container/gtype/gtype_z_unit_int64_test.go @@ -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) }) } diff --git a/container/gtype/gtype_z_unit_int_test.go b/container/gtype/gtype_z_unit_int_test.go index 39114eb59..5bbbdbbdb 100644 --- a/container/gtype/gtype_z_unit_int_test.go +++ b/container/gtype/gtype_z_unit_int_test.go @@ -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) }) } diff --git a/container/gtype/gtype_z_unit_interface_test.go b/container/gtype/gtype_z_unit_interface_test.go index 828edf36a..29c66bb36 100644 --- a/container/gtype/gtype_z_unit_interface_test.go +++ b/container/gtype/gtype_z_unit_interface_test.go @@ -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) }) } diff --git a/container/gtype/gtype_z_unit_string_test.go b/container/gtype/gtype_z_unit_string_test.go index 319adf509..a7769110a 100644 --- a/container/gtype/gtype_z_unit_string_test.go +++ b/container/gtype/gtype_z_unit_string_test.go @@ -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(), "") }) diff --git a/container/gtype/gtype_z_unit_uint32_test.go b/container/gtype/gtype_z_unit_uint32_test.go index 6e00fc7d8..d1989a689 100644 --- a/container/gtype/gtype_z_unit_uint32_test.go +++ b/container/gtype/gtype_z_unit_uint32_test.go @@ -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) }) } diff --git a/container/gtype/gtype_z_unit_uint64_test.go b/container/gtype/gtype_z_unit_uint64_test.go index 5fe206051..4718ac458 100644 --- a/container/gtype/gtype_z_unit_uint64_test.go +++ b/container/gtype/gtype_z_unit_uint64_test.go @@ -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) { diff --git a/container/gtype/gtype_z_unit_uint_test.go b/container/gtype/gtype_z_unit_uint_test.go index 56d564d72..e4b6b957c 100644 --- a/container/gtype/gtype_z_unit_uint_test.go +++ b/container/gtype/gtype_z_unit_uint_test.go @@ -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) }) }