amuz.es/src/go/misc@v1.0.1/nums/big_test.go (about) 1 package nums 2 3 import ( 4 "github.com/ericlagergren/decimal" 5 "reflect" 6 "testing" 7 ) 8 9 func TestBigSeperateFractionalPotions(t *testing.T) { 10 type args struct { 11 src *decimal.Big 12 } 13 tests := []struct { 14 name string 15 args args 16 wantSign bool 17 wantInteger uint64 18 wantFractional uint64 19 wantFractionalLength uint8 20 }{ 21 { 22 "11.111", 23 args{ 24 decimal.New(11111, 3), 25 }, 26 false, 27 11, 28 111, 29 3, 30 }, 31 { 32 "0.111", 33 args{ 34 decimal.New(111, 3), 35 }, 36 false, 37 0, 38 111, 39 3, 40 }, 41 { 42 "11", 43 args{ 44 decimal.New(11000, 3), 45 }, 46 false, 47 11, 48 0, 49 0, 50 }, 51 { 52 "10.01", 53 args{ 54 decimal.New(10010, 3), 55 }, 56 false, 57 10, 58 1, 59 2, 60 }, 61 { 62 "0.013", 63 args{ 64 decimal.New(13, 3), 65 }, 66 false, 67 0, 68 13, 69 3, 70 }, 71 { 72 "-11.111", 73 args{ 74 decimal.New(-11111, 3), 75 }, 76 true, 77 11, 78 111, 79 3, 80 }, 81 { 82 "-0.111", 83 args{ 84 decimal.New(-111, 3), 85 }, 86 true, 87 0, 88 111, 89 3, 90 }, 91 { 92 "-11", 93 args{ 94 decimal.New(-11000, 3), 95 }, 96 true, 97 11, 98 0, 99 0, 100 }, 101 { 102 "-10.01", 103 args{ 104 decimal.New(-10010, 3), 105 }, 106 true, 107 10, 108 1, 109 2, 110 }, 111 { 112 "-0.013", 113 args{ 114 decimal.New(-13, 3), 115 }, 116 true, 117 0, 118 13, 119 3, 120 }, 121 } 122 for _, tt := range tests { 123 t.Run(tt.name, func(t *testing.T) { 124 gotSign, gotInteger, gotFractional, gotFractionalLength := BigSeperateFractionalPotions(tt.args.src) 125 t.Logf("BigSeperateFractionalPotions() sign =%v, integer = %v, fractional = %v, fractionalLength = %v", gotSign, gotInteger, gotFractional, gotFractionalLength) 126 if gotSign != tt.wantSign { 127 t.Errorf("BigSeperateFractionalPotions() gotSign = %v, want %v", gotSign, tt.wantSign) 128 } 129 if gotInteger != tt.wantInteger { 130 t.Errorf("BigSeperateFractionalPotions() gotInteger = %v, want %v", gotInteger, tt.wantInteger) 131 } 132 if gotFractional != tt.wantFractional { 133 t.Errorf("BigSeperateFractionalPotions() gotFractional = %v, want %v", gotFractional, tt.wantFractional) 134 } 135 if gotFractionalLength != tt.wantFractionalLength { 136 t.Errorf("BigSeperateFractionalPotions() gotFractionalLength = %v, want %v", gotFractionalLength, tt.wantFractionalLength) 137 } 138 }) 139 } 140 } 141 142 func TestBigMergeFractionalPotions(t *testing.T) { 143 type args struct { 144 sign bool 145 integer uint64 146 fractional uint64 147 fractionalLength uint8 148 } 149 tests := []struct { 150 name string 151 args args 152 wantDst *decimal.Big 153 }{ 154 { 155 "11.111", 156 args{ 157 false, 158 11, 159 111, 160 3, 161 }, 162 decimal.New(11111, 3), 163 }, 164 { 165 "0.111", 166 args{ 167 false, 168 0, 169 111, 170 3, 171 }, 172 decimal.New(111, 3), 173 }, 174 { 175 "11", 176 args{ 177 false, 178 11, 179 0, 180 0, 181 }, 182 decimal.New(11, 0), 183 }, 184 { 185 "10.01", 186 args{ 187 false, 188 10, 189 1, 190 2, 191 }, 192 decimal.New(1001, 2), 193 }, 194 { 195 "0.013", 196 args{ 197 false, 198 0, 199 13, 200 3, 201 }, 202 decimal.New(13, 3), 203 }, 204 { 205 "-11.111", 206 args{ 207 true, 208 11, 209 111, 210 3, 211 }, 212 decimal.New(-11111, 3), 213 }, 214 { 215 "-0.111", 216 args{ 217 true, 218 0, 219 111, 220 3, 221 }, 222 decimal.New(-111, 3), 223 }, 224 { 225 "-11", 226 args{ 227 true, 228 11, 229 0, 230 0, 231 }, 232 decimal.New(-11, 0), 233 }, 234 { 235 "-10.01", 236 args{ 237 true, 238 10, 239 1, 240 2, 241 }, 242 decimal.New(-1001, 2), 243 }, 244 { 245 "-0.013", 246 args{ 247 true, 248 0, 249 13, 250 3, 251 }, 252 decimal.New(-13, 3), 253 }, 254 } 255 for _, tt := range tests { 256 t.Run(tt.name, func(t *testing.T) { 257 if gotDst := BigMergeFractionalPotions(tt.args.sign, tt.args.integer, tt.args.fractional, tt.args.fractionalLength); !reflect.DeepEqual(gotDst, tt.wantDst) { 258 t.Errorf("BigMergeFractionalPotions() = %v, want %v", gotDst, tt.wantDst) 259 } 260 }) 261 } 262 }