// Package define ... // // Description : define ... // // Author : go_developer@163.com<白茶清欢> // // Date : 2024-03-08 15:24 package define import ( "git.zhangdeman.cn/zhangdeman/wrapper" "github.com/stretchr/testify/assert" "testing" ) func TestDefaultDiffFunc(t *testing.T) { var ( num1 float64 = 1.0 num2 float32 = 1.00 num3 string = "1" num4 string = "1.00" ) input := wrapper.EasyMap(map[string]any{ "num": num1, "num3": num3, "num4": num4, "num5": num1, }) storage := wrapper.EasyMap(map[string]any{ "num": num2, "num3": num2, "num4": num2, "num5": num1, }) diffOption := NewDiffOption() diffOption.StrictMode = true res := DefaultDiffFunc("num", input, storage, diffOption) assert.EqualValues(t, false, res.IsSame, "严格模式下, float32与float64不相等") res = DefaultDiffFunc("num5", input, storage, diffOption) assert.EqualValues(t, true, res.IsSame, "严格模式下, float32与float32相等") diffOption.StrictMode = false res = DefaultDiffFunc("num", input, storage, diffOption) assert.EqualValues(t, true, res.IsSame, "非严格模式下, float32与float64相等") res = DefaultDiffFunc("num3", input, storage, diffOption) assert.EqualValues(t, true, res.IsSame, "非严格模式下, float32与string相等") diffOption.AllowStringNumber = true res = DefaultDiffFunc("num4", input, storage, diffOption) assert.EqualValues(t, true, res.IsSame, "非严格模式下, float32与string相等") }