github.com/Mericusta/go-stp@v0.6.8/type_test.go (about) 1 package stp 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 type customType struct { 9 i Int 10 s String 11 } 12 13 func (v customType) EQ(rv customType) bool { 14 return v.i == rv.i && v.s == rv.s 15 } 16 17 func (v customType) LT(rv customType) bool { 18 return v.i < rv.i && v.s < rv.s 19 } 20 21 func (v customType) GT(rv customType) bool { 22 return v.i > rv.i && v.s > rv.s 23 } 24 25 func Test_Type(t *testing.T) { 26 int1, int2 := Int(1), Int(2) 27 if int1.LT(int2) { 28 fmt.Printf("Int %v LT %v\n", int1, int2) 29 } else { 30 panic(fmt.Sprintf("Int %v not LT %v\n", int1, int2)) 31 } 32 if int1.GT(int2) { 33 panic(fmt.Sprintf("Int %v GT %v\n", int1, int2)) 34 } else { 35 fmt.Printf("Int %v not GT %v\n", int1, int2) 36 } 37 if int1.EQ(int2) { 38 panic(fmt.Sprintf("Int %v EQ %v\n", int1, int2)) 39 } else { 40 fmt.Printf("Int %v not EQ %v\n", int1, int2) 41 } 42 if int1.V() == 1 { 43 fmt.Printf("Int %v == %v\n", int1.V(), 1) 44 } else { 45 panic(fmt.Sprintf("Int %v != %v\n", int1.V(), 1)) 46 } 47 if int2.V() == 2 { 48 fmt.Printf("Int %v == %v\n", int2.V(), 2) 49 } else { 50 panic(fmt.Sprintf("Int %v != %v\n", int2.V(), 2)) 51 } 52 53 ct1, ct2 := customType{i: 1, s: "1"}, customType{i: 2, s: "2"} 54 if ct1.LT(ct2) { 55 fmt.Printf("Int %v LT %v\n", ct1, ct2) 56 } else { 57 panic(fmt.Sprintf("Int %v not LT %v\n", ct1, ct2)) 58 } 59 if ct1.GT(ct2) { 60 panic(fmt.Sprintf("Int %v GT %v\n", ct1, ct2)) 61 } else { 62 fmt.Printf("Int %v not GT %v\n", ct1, ct2) 63 } 64 if ct1.EQ(ct2) { 65 panic(fmt.Sprintf("Int %v EQ %v\n", ct1, ct2)) 66 } else { 67 fmt.Printf("Int %v not EQ %v\n", ct1, ct2) 68 } 69 }