github.com/gogf/gf/v2@v2.7.4/util/gutil/gutil_z_unit_comparator_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package gutil_test 8 9 import ( 10 "testing" 11 12 "github.com/gogf/gf/v2/test/gtest" 13 "github.com/gogf/gf/v2/util/gutil" 14 ) 15 16 func Test_ComparatorString(t *testing.T) { 17 18 gtest.C(t, func(t *gtest.T) { 19 t.Assert(gutil.ComparatorString(1, 1), 0) 20 t.Assert(gutil.ComparatorString(1, 2), -1) 21 t.Assert(gutil.ComparatorString(2, 1), 1) 22 }) 23 } 24 25 func Test_ComparatorInt(t *testing.T) { 26 27 gtest.C(t, func(t *gtest.T) { 28 t.Assert(gutil.ComparatorInt(1, 1), 0) 29 t.Assert(gutil.ComparatorInt(1, 2), -1) 30 t.Assert(gutil.ComparatorInt(2, 1), 1) 31 }) 32 } 33 34 func Test_ComparatorInt8(t *testing.T) { 35 36 gtest.C(t, func(t *gtest.T) { 37 t.Assert(gutil.ComparatorInt8(1, 1), 0) 38 t.Assert(gutil.ComparatorInt8(1, 2), -1) 39 t.Assert(gutil.ComparatorInt8(2, 1), 1) 40 }) 41 } 42 43 func Test_ComparatorInt16(t *testing.T) { 44 45 gtest.C(t, func(t *gtest.T) { 46 t.Assert(gutil.ComparatorInt16(1, 1), 0) 47 t.Assert(gutil.ComparatorInt16(1, 2), -1) 48 t.Assert(gutil.ComparatorInt16(2, 1), 1) 49 }) 50 } 51 52 func Test_ComparatorInt32(t *testing.T) { 53 54 gtest.C(t, func(t *gtest.T) { 55 t.Assert(gutil.ComparatorInt32(1, 1), 0) 56 t.Assert(gutil.ComparatorInt32(1, 2), -1) 57 t.Assert(gutil.ComparatorInt32(2, 1), 1) 58 }) 59 } 60 61 func Test_ComparatorInt64(t *testing.T) { 62 63 gtest.C(t, func(t *gtest.T) { 64 t.Assert(gutil.ComparatorInt64(1, 1), 0) 65 t.Assert(gutil.ComparatorInt64(1, 2), -1) 66 t.Assert(gutil.ComparatorInt64(2, 1), 1) 67 }) 68 } 69 70 func Test_ComparatorUint(t *testing.T) { 71 72 gtest.C(t, func(t *gtest.T) { 73 t.Assert(gutil.ComparatorUint(1, 1), 0) 74 t.Assert(gutil.ComparatorUint(1, 2), -1) 75 t.Assert(gutil.ComparatorUint(2, 1), 1) 76 }) 77 } 78 79 func Test_ComparatorUint8(t *testing.T) { 80 81 gtest.C(t, func(t *gtest.T) { 82 t.Assert(gutil.ComparatorUint8(1, 1), 0) 83 t.Assert(gutil.ComparatorUint8(2, 6), 252) 84 t.Assert(gutil.ComparatorUint8(2, 1), 1) 85 }) 86 } 87 88 func Test_ComparatorUint16(t *testing.T) { 89 90 gtest.C(t, func(t *gtest.T) { 91 t.Assert(gutil.ComparatorUint16(1, 1), 0) 92 t.Assert(gutil.ComparatorUint16(1, 2), 65535) 93 t.Assert(gutil.ComparatorUint16(2, 1), 1) 94 }) 95 } 96 97 func Test_ComparatorUint32(t *testing.T) { 98 99 gtest.C(t, func(t *gtest.T) { 100 t.Assert(gutil.ComparatorUint32(1, 1), 0) 101 t.Assert(gutil.ComparatorUint32(-1000, 2147483640), 2147482656) 102 t.Assert(gutil.ComparatorUint32(2, 1), 1) 103 }) 104 } 105 106 func Test_ComparatorUint64(t *testing.T) { 107 108 gtest.C(t, func(t *gtest.T) { 109 t.Assert(gutil.ComparatorUint64(1, 1), 0) 110 t.Assert(gutil.ComparatorUint64(1, 2), -1) 111 t.Assert(gutil.ComparatorUint64(2, 1), 1) 112 }) 113 } 114 115 func Test_ComparatorFloat32(t *testing.T) { 116 117 gtest.C(t, func(t *gtest.T) { 118 t.Assert(gutil.ComparatorFloat32(1, 1), 0) 119 t.Assert(gutil.ComparatorFloat32(1, 2), -1) 120 t.Assert(gutil.ComparatorFloat32(2, 1), 1) 121 }) 122 } 123 124 func Test_ComparatorFloat64(t *testing.T) { 125 126 gtest.C(t, func(t *gtest.T) { 127 t.Assert(gutil.ComparatorFloat64(1, 1), 0) 128 t.Assert(gutil.ComparatorFloat64(1, 2), -1) 129 t.Assert(gutil.ComparatorFloat64(2, 1), 1) 130 }) 131 } 132 133 func Test_ComparatorByte(t *testing.T) { 134 135 gtest.C(t, func(t *gtest.T) { 136 t.Assert(gutil.ComparatorByte(1, 1), 0) 137 t.Assert(gutil.ComparatorByte(1, 2), 255) 138 t.Assert(gutil.ComparatorByte(2, 1), 1) 139 }) 140 } 141 142 func Test_ComparatorRune(t *testing.T) { 143 144 gtest.C(t, func(t *gtest.T) { 145 t.Assert(gutil.ComparatorRune(1, 1), 0) 146 t.Assert(gutil.ComparatorRune(1, 2), -1) 147 t.Assert(gutil.ComparatorRune(2, 1), 1) 148 }) 149 } 150 151 func Test_ComparatorTime(t *testing.T) { 152 gtest.C(t, func(t *gtest.T) { 153 j := gutil.ComparatorTime("2019-06-14", "2019-06-14") 154 t.Assert(j, 0) 155 156 k := gutil.ComparatorTime("2019-06-15", "2019-06-14") 157 t.Assert(k, 1) 158 159 l := gutil.ComparatorTime("2019-06-13", "2019-06-14") 160 t.Assert(l, -1) 161 }) 162 } 163 164 func Test_ComparatorFloat32OfFixed(t *testing.T) { 165 gtest.C(t, func(t *gtest.T) { 166 t.Assert(gutil.ComparatorFloat32(0.1, 0.1), 0) 167 t.Assert(gutil.ComparatorFloat32(1.1, 2.1), -1) 168 t.Assert(gutil.ComparatorFloat32(2.1, 1.1), 1) 169 }) 170 } 171 172 func Test_ComparatorFloat64OfFixed(t *testing.T) { 173 174 gtest.C(t, func(t *gtest.T) { 175 t.Assert(gutil.ComparatorFloat64(0.1, 0.1), 0) 176 t.Assert(gutil.ComparatorFloat64(1.1, 2.1), -1) 177 t.Assert(gutil.ComparatorFloat64(2.1, 1.1), 1) 178 }) 179 }