github.com/zhongdalu/gf@v1.0.0/g/util/gutil/gutil_z_comparator_z_unit_test.go (about) 1 package gutil_test 2 3 import ( 4 "testing" 5 6 "github.com/zhongdalu/gf/g/test/gtest" 7 "github.com/zhongdalu/gf/g/util/gutil" 8 ) 9 10 func Test_ComparatorString(t *testing.T) { 11 12 gtest.Case(t, func() { 13 gtest.Assert(gutil.ComparatorString(1, 1), 0) 14 gtest.Assert(gutil.ComparatorString(1, 2), -1) 15 gtest.Assert(gutil.ComparatorString(2, 1), 1) 16 }) 17 } 18 19 func Test_ComparatorInt(t *testing.T) { 20 21 gtest.Case(t, func() { 22 gtest.Assert(gutil.ComparatorInt(1, 1), 0) 23 gtest.Assert(gutil.ComparatorInt(1, 2), -1) 24 gtest.Assert(gutil.ComparatorInt(2, 1), 1) 25 }) 26 } 27 28 func Test_ComparatorInt8(t *testing.T) { 29 30 gtest.Case(t, func() { 31 gtest.Assert(gutil.ComparatorInt8(1, 1), 0) 32 gtest.Assert(gutil.ComparatorInt8(1, 2), -1) 33 gtest.Assert(gutil.ComparatorInt8(2, 1), 1) 34 }) 35 } 36 37 func Test_ComparatorInt16(t *testing.T) { 38 39 gtest.Case(t, func() { 40 gtest.Assert(gutil.ComparatorInt16(1, 1), 0) 41 gtest.Assert(gutil.ComparatorInt16(1, 2), -1) 42 gtest.Assert(gutil.ComparatorInt16(2, 1), 1) 43 }) 44 } 45 46 func Test_ComparatorInt32(t *testing.T) { 47 48 gtest.Case(t, func() { 49 gtest.Assert(gutil.ComparatorInt32(1, 1), 0) 50 gtest.Assert(gutil.ComparatorInt32(1, 2), -1) 51 gtest.Assert(gutil.ComparatorInt32(2, 1), 1) 52 }) 53 } 54 55 func Test_ComparatorInt64(t *testing.T) { 56 57 gtest.Case(t, func() { 58 gtest.Assert(gutil.ComparatorInt64(1, 1), 0) 59 gtest.Assert(gutil.ComparatorInt64(1, 2), -1) 60 gtest.Assert(gutil.ComparatorInt64(2, 1), 1) 61 }) 62 } 63 64 func Test_ComparatorUint(t *testing.T) { 65 66 gtest.Case(t, func() { 67 gtest.Assert(gutil.ComparatorUint(1, 1), 0) 68 gtest.Assert(gutil.ComparatorUint(1, 2), -1) 69 gtest.Assert(gutil.ComparatorUint(2, 1), 1) 70 }) 71 } 72 73 func Test_ComparatorUint8(t *testing.T) { 74 75 gtest.Case(t, func() { 76 gtest.Assert(gutil.ComparatorUint8(1, 1), 0) 77 gtest.Assert(gutil.ComparatorUint8(2, 6), 252) 78 gtest.Assert(gutil.ComparatorUint8(2, 1), 1) 79 }) 80 } 81 82 func Test_ComparatorUint16(t *testing.T) { 83 84 gtest.Case(t, func() { 85 gtest.Assert(gutil.ComparatorUint16(1, 1), 0) 86 gtest.Assert(gutil.ComparatorUint16(1, 2), 65535) 87 gtest.Assert(gutil.ComparatorUint16(2, 1), 1) 88 }) 89 } 90 91 func Test_ComparatorUint32(t *testing.T) { 92 93 gtest.Case(t, func() { 94 gtest.Assert(gutil.ComparatorUint32(1, 1), 0) 95 gtest.Assert(gutil.ComparatorUint32(-1000, 2147483640), 2147482656) 96 gtest.Assert(gutil.ComparatorUint32(2, 1), 1) 97 }) 98 } 99 100 func Test_ComparatorUint64(t *testing.T) { 101 102 gtest.Case(t, func() { 103 gtest.Assert(gutil.ComparatorUint64(1, 1), 0) 104 gtest.Assert(gutil.ComparatorUint64(1, 2), -1) 105 gtest.Assert(gutil.ComparatorUint64(2, 1), 1) 106 }) 107 } 108 109 func Test_ComparatorFloat32(t *testing.T) { 110 111 gtest.Case(t, func() { 112 gtest.Assert(gutil.ComparatorFloat32(1, 1), 0) 113 gtest.Assert(gutil.ComparatorFloat32(1, 2), -1) 114 gtest.Assert(gutil.ComparatorFloat32(2, 1), 1) 115 }) 116 } 117 118 func Test_ComparatorFloat64(t *testing.T) { 119 120 gtest.Case(t, func() { 121 gtest.Assert(gutil.ComparatorFloat64(1, 1), 0) 122 gtest.Assert(gutil.ComparatorFloat64(1, 2), -1) 123 gtest.Assert(gutil.ComparatorFloat64(2, 1), 1) 124 }) 125 } 126 127 func Test_ComparatorByte(t *testing.T) { 128 129 gtest.Case(t, func() { 130 gtest.Assert(gutil.ComparatorByte(1, 1), 0) 131 gtest.Assert(gutil.ComparatorByte(1, 2), 255) 132 gtest.Assert(gutil.ComparatorByte(2, 1), 1) 133 }) 134 } 135 136 func Test_ComparatorRune(t *testing.T) { 137 138 gtest.Case(t, func() { 139 gtest.Assert(gutil.ComparatorRune(1, 1), 0) 140 gtest.Assert(gutil.ComparatorRune(1, 2), -1) 141 gtest.Assert(gutil.ComparatorRune(2, 1), 1) 142 }) 143 } 144 145 func Test_ComparatorTime(t *testing.T) { 146 gtest.Case(t, func() { 147 j := gutil.ComparatorTime("2019-06-14", "2019-06-14") 148 gtest.Assert(j, 0) 149 150 k := gutil.ComparatorTime("2019-06-15", "2019-06-14") 151 gtest.Assert(k, 1) 152 153 l := gutil.ComparatorTime("2019-06-13", "2019-06-14") 154 gtest.Assert(l, -1) 155 }) 156 }