github.com/matrixorigin/matrixone@v1.2.0/pkg/vectorize/format/format_test.go (about) 1 // Copyright 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package format 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestForamtENUS(t *testing.T) { 24 cases := []struct { 25 name string 26 number string 27 scale string 28 want string 29 }{ 30 { 31 name: "TEST01", 32 number: "12332.2", 33 scale: "2", 34 want: "12,332.20", 35 }, 36 { 37 name: "TEST02", 38 number: "12332.123456", 39 scale: "4", 40 want: "12,332.1235", 41 }, 42 { 43 name: "TEST03", 44 number: "12332.1", 45 scale: "4", 46 want: "12,332.1000", 47 }, 48 { 49 name: "TEST04", 50 number: "12332.2", 51 scale: "0", 52 want: "12,332", 53 }, 54 { 55 name: "TEST05", 56 number: "-.12334.2", 57 scale: "2", 58 want: "-0.12", 59 }, 60 { 61 name: "TEST06", 62 number: "19999999.999999999", 63 scale: "4", 64 want: "20,000,000.0000", 65 }, 66 } 67 68 for _, c := range cases { 69 t.Run(c.name, func(t *testing.T) { 70 got, _ := formatENUS(c.number, c.scale) 71 require.Equal(t, c.want, got) 72 }) 73 } 74 } 75 76 func TestForamtARSA(t *testing.T) { 77 cases := []struct { 78 name string 79 number string 80 scale string 81 want string 82 }{ 83 { 84 name: "TEST01", 85 number: "12332.2", 86 scale: "2", 87 want: "12332.20", 88 }, 89 { 90 name: "TEST02", 91 number: "12332.123456", 92 scale: "4", 93 want: "12332.1235", 94 }, 95 { 96 name: "TEST03", 97 number: "12332.1", 98 scale: "4", 99 want: "12332.1000", 100 }, 101 { 102 name: "TEST04", 103 number: "12332.2", 104 scale: "0", 105 want: "12332", 106 }, 107 { 108 name: "TEST05", 109 number: "-.12334.2", 110 scale: "2", 111 want: "-0.12", 112 }, 113 { 114 name: "TEST06", 115 number: "19999999.999999999", 116 scale: "4", 117 want: "20000000.0000", 118 }, 119 } 120 121 for _, c := range cases { 122 t.Run(c.name, func(t *testing.T) { 123 got, _ := formatARSA(c.number, c.scale) 124 require.Equal(t, c.want, got) 125 }) 126 } 127 } 128 129 func TestForamtBEBY(t *testing.T) { 130 cases := []struct { 131 name string 132 number string 133 scale string 134 want string 135 }{ 136 { 137 name: "TEST01", 138 number: "12332.2", 139 scale: "2", 140 want: "12.332,20", 141 }, 142 { 143 name: "TEST02", 144 number: "12332.123456", 145 scale: "4", 146 want: "12.332,1235", 147 }, 148 { 149 name: "TEST03", 150 number: "12332.1", 151 scale: "4", 152 want: "12.332,1000", 153 }, 154 { 155 name: "TEST04", 156 number: "12332.2", 157 scale: "0", 158 want: "12.332", 159 }, 160 { 161 name: "TEST05", 162 number: "-.12334.2", 163 scale: "2", 164 want: "-0,12", 165 }, 166 { 167 name: "TEST06", 168 number: "19999999.999999999", 169 scale: "4", 170 want: "20.000.000,0000", 171 }, 172 } 173 174 for _, c := range cases { 175 t.Run(c.name, func(t *testing.T) { 176 got, _ := formatBEBY(c.number, c.scale) 177 require.Equal(t, c.want, got) 178 }) 179 } 180 } 181 182 func TestForamtBGBG(t *testing.T) { 183 cases := []struct { 184 name string 185 number string 186 scale string 187 want string 188 }{ 189 { 190 name: "TEST01", 191 number: "12332.2", 192 scale: "2", 193 want: "12 332,20", 194 }, 195 { 196 name: "TEST02", 197 number: "12332.123456", 198 scale: "4", 199 want: "12 332,1235", 200 }, 201 { 202 name: "TEST03", 203 number: "12332.1", 204 scale: "4", 205 want: "12 332,1000", 206 }, 207 { 208 name: "TEST04", 209 number: "12332.2", 210 scale: "0", 211 want: "12 332", 212 }, 213 { 214 name: "TEST05", 215 number: "-.12334.2", 216 scale: "2", 217 want: "-0,12", 218 }, 219 { 220 name: "TEST06", 221 number: "19999999.999999999", 222 scale: "4", 223 want: "20 000 000,0000", 224 }, 225 } 226 227 for _, c := range cases { 228 t.Run(c.name, func(t *testing.T) { 229 got, _ := formatBGBG(c.number, c.scale) 230 require.Equal(t, c.want, got) 231 }) 232 } 233 } 234 235 func TestForamtDECH(t *testing.T) { 236 cases := []struct { 237 name string 238 number string 239 scale string 240 want string 241 }{ 242 { 243 name: "TEST01", 244 number: "12332.2", 245 scale: "2", 246 want: "12'332.20", 247 }, 248 { 249 name: "TEST02", 250 number: "12332.123456", 251 scale: "4", 252 want: "12'332.1235", 253 }, 254 { 255 name: "TEST03", 256 number: "12332.1", 257 scale: "4", 258 want: "12'332.1000", 259 }, 260 { 261 name: "TEST04", 262 number: "12332.2", 263 scale: "0", 264 want: "12'332", 265 }, 266 { 267 name: "TEST05", 268 number: "-.12334.2", 269 scale: "2", 270 want: "-0.12", 271 }, 272 { 273 name: "TEST06", 274 number: "19999999.999999999", 275 scale: "4", 276 want: "20'000'000.0000", 277 }, 278 } 279 280 for _, c := range cases { 281 t.Run(c.name, func(t *testing.T) { 282 got, _ := formatDECH(c.number, c.scale) 283 require.Equal(t, c.want, got) 284 }) 285 } 286 }