github.com/keakon/golog@v0.0.0-20230330091222-cac71197c18d/utils_test.go (about) 1 package golog 2 3 import "testing" 4 5 func TestUint2Bytes(t *testing.T) { 6 bs := string(uint2Bytes(0, 2)) 7 if bs != "00" { 8 t.Errorf("result is " + bs) 9 } 10 11 bs = string(uint2Bytes(59, 2)) 12 if bs != "59" { 13 t.Errorf("result is " + bs) 14 } 15 16 bs = string(uint2Bytes(1970, 4)) 17 if bs != "1970" { 18 t.Errorf("result is " + bs) 19 } 20 21 bs = string(uint2Bytes(2038, 4)) 22 if bs != "2038" { 23 t.Errorf("result is " + bs) 24 } 25 } 26 27 func TestUint2Bytes2(t *testing.T) { 28 bs := string(uint2Bytes2(0)) 29 if bs != "00" { 30 t.Errorf("result is " + bs) 31 } 32 33 bs = string(uint2Bytes2(59)) 34 if bs != "59" { 35 t.Errorf("result is " + bs) 36 } 37 } 38 39 func TestUint2Bytes4(t *testing.T) { 40 bs := string(uint2Bytes4(1970)) 41 if bs != "1970" { 42 t.Errorf("result is " + bs) 43 } 44 45 bs = string(uint2Bytes4(2038)) 46 if bs != "2038" { 47 t.Errorf("result is " + bs) 48 } 49 } 50 51 func TestUint2DynamicBytes(t *testing.T) { 52 bs := string(uint2DynamicBytes(0)) 53 if bs != "0" { 54 t.Errorf("result is " + bs) 55 } 56 57 bs = string(uint2DynamicBytes(59)) 58 if bs != "59" { 59 t.Errorf("result is " + bs) 60 } 61 62 bs = string(uint2DynamicBytes(999)) 63 if bs != "999" { 64 t.Errorf("result is " + bs) 65 } 66 67 bs = string(uint2DynamicBytes(1000)) 68 if bs != "1000" { 69 t.Errorf("result is " + bs) 70 } 71 72 bs = string(uint2DynamicBytes(1970)) 73 if bs != "1970" { 74 t.Errorf("result is " + bs) 75 } 76 77 bs = string(uint2DynamicBytes(2038)) 78 if bs != "2038" { 79 t.Errorf("result is " + bs) 80 } 81 82 bs = string(uint2DynamicBytes(12345)) 83 if bs != "12345" { 84 t.Errorf("result is " + bs) 85 } 86 87 bs = string(uint2DynamicBytes(123456)) 88 if bs != "123456" { 89 t.Errorf("result is " + bs) 90 } 91 92 bs = string(uint2DynamicBytes(1234567)) 93 if bs != "1234567" { 94 t.Errorf("result is " + bs) 95 } 96 97 bs = string(uint2DynamicBytes(12345678)) 98 if bs != "12345678" { 99 t.Errorf("result is " + bs) 100 } 101 102 bs = string(uint2DynamicBytes(123456789)) 103 if bs != "123456789" { 104 t.Errorf("result is " + bs) 105 } 106 107 bs = string(uint2DynamicBytes(1234567890)) 108 if bs != "1234567890" { 109 t.Errorf("result is " + bs) 110 } 111 112 bs = string(uint2DynamicBytes(2<<31 - 1)) 113 if bs != "4294967295" { 114 t.Errorf("result is " + bs) 115 } 116 } 117 118 func TestFastUint2DynamicBytes(t *testing.T) { 119 bs := string(fastUint2DynamicBytes(0)) 120 if bs != "0" { 121 t.Errorf("result is " + bs) 122 } 123 124 bs = string(fastUint2DynamicBytes(59)) 125 if bs != "59" { 126 t.Errorf("result is " + bs) 127 } 128 129 bs = string(fastUint2DynamicBytes(999)) 130 if bs != "999" { 131 t.Errorf("result is " + bs) 132 } 133 134 bs = string(fastUint2DynamicBytes(1000)) 135 if bs != "1000" { 136 t.Errorf("result is " + bs) 137 } 138 139 bs = string(fastUint2DynamicBytes(1970)) 140 if bs != "1970" { 141 t.Errorf("result is " + bs) 142 } 143 144 bs = string(fastUint2DynamicBytes(2038)) 145 if bs != "2038" { 146 t.Errorf("result is " + bs) 147 } 148 149 bs = string(fastUint2DynamicBytes(12345)) 150 if bs != "12345" { 151 t.Errorf("result is " + bs) 152 } 153 154 bs = string(fastUint2DynamicBytes(123456)) 155 if bs != "123456" { 156 t.Errorf("result is " + bs) 157 } 158 159 bs = string(fastUint2DynamicBytes(1234567)) 160 if bs != "1234567" { 161 t.Errorf("result is " + bs) 162 } 163 164 bs = string(fastUint2DynamicBytes(12345678)) 165 if bs != "12345678" { 166 t.Errorf("result is " + bs) 167 } 168 169 bs = string(fastUint2DynamicBytes(123456789)) 170 if bs != "123456789" { 171 t.Errorf("result is " + bs) 172 } 173 174 bs = string(fastUint2DynamicBytes(1234567890)) 175 if bs != "1234567890" { 176 t.Errorf("result is " + bs) 177 } 178 179 bs = string(fastUint2DynamicBytes(2<<31 - 1)) 180 if bs != "4294967295" { 181 t.Errorf("result is " + bs) 182 } 183 } 184 185 func BenchmarkCaller(b *testing.B) { 186 for i := 0; i < b.N; i++ { 187 Caller(1) 188 } 189 }