func TestCompare(t *testing.T) { t1 := newSimpleType() t1.A_string = "string" t1.A_string_p = &t1.A_string t1.A_interface = int(0) t2 := newSimpleType() t2.A_string = "string" t2.A_string_p = &t2.A_string t2.A_interface = float64(0) for name1, f1 := range gotype.ToMap(reflect.ValueOf(t1)) { for name2, f2 := range gotype.ToMap(reflect.ValueOf(&t2)) { if gotype.CanCompareKind(gotype.Underlying(f1).Kind(), gotype.Underlying(f2).Kind()) { equal := gotype.Equal(f1.Interface(), f2.Interface()) if !equal { t.Errorf("Test Equal fail for %s (%s) and %s (%s)", name1, f1, name2, f2) } greater := gotype.Greater(f1.Interface(), f2.Interface()) if greater { t.Errorf("Test Greater fail for %s (%s) and %s (%s)", name1, f1, name2, f2) } less := gotype.Less(f1.Interface(), f2.Interface()) if less { t.Errorf("Test Less fail for %s (%s) and %s (%s)", name1, f1, name2, f2) } } } } }
func compare() { fmt.Println("compare...") var v1 []interface{} = []interface{}{ int(16), int(10)} var v2 []interface{} = []interface{}{ uint(16), float32(10)} for i, v := range v1 { fmt.Printf("%d\t (%v)%v = (%v)%v ? \t%v \n", i, reflect.ValueOf(v).Kind(), v, reflect.ValueOf(v2[i]).Kind(), v2[i], gotype.Equal(v, v2[i])) } }
func equal(a, b interface{}) bool { return gotype.Equal(a, b) }
func Equal(t *testing.T, name string, expect, actual interface{}) { if !gotype.Equal(expect, actual) { t.Errorf("%s test equal fail: expect=%v; actual=%v", name, expect, actual) } }