github.com/sandwich-go/boost@v1.3.29/xslice/slice_test.go (about) 1 // Code generated by tools. DO NOT EDIT. 2 package xslice 3 4 import ( 5 . "github.com/smartystreets/goconvey/convey" 6 "testing" 7 ) 8 9 func TestFloat32s(t *testing.T) { 10 Convey("float32 slice", t, func() { 11 for _, test := range []struct { 12 ss []float32 13 s float32 14 contains bool 15 }{ 16 {ss: nil, s: 1}, 17 {ss: []float32{1, 2}, s: 3, contains: false}, 18 {ss: []float32{1, 2}, s: 1, contains: true}, 19 } { 20 So(Float32sContain(test.ss, test.s), ShouldEqual, test.contains) 21 } 22 dest := Float32sSetAdd(nil, 1) 23 So(len(dest), ShouldEqual, 1) 24 So(len(Float32sSetAdd(dest, 1)), ShouldEqual, 1) 25 26 src := []float32{1, 2} 27 dest = Float32sWalk(src, func(s float32) (float32, bool) { 28 return s + 1, true 29 }) 30 So(len(src), ShouldEqual, len(dest)) 31 for i := 0; i < len(src); i++ { 32 So(src[i]+1, ShouldEqual, dest[i]) 33 } 34 for i := 0; i < 2; i++ { 35 if i > 0 { 36 tooManyElement = 4 37 } 38 for _, test := range []struct { 39 src []float32 40 dest []float32 41 contains bool 42 }{ 43 {src: []float32{1, 2, 2}, dest: []float32{1, 2}}, 44 {src: []float32{1, 1, 2}, dest: []float32{1, 2}}, 45 {src: []float32{1, 1, 2, 2, 2}, dest: []float32{1, 2}}, 46 } { 47 So(Float32sRemoveRepeated(test.src), ShouldResemble, test.dest) 48 } 49 } 50 51 for _, test := range []struct { 52 src []float32 53 dest []float32 54 contains bool 55 }{ 56 {src: []float32{1, 0, 2}, dest: []float32{1, 2}}, 57 {src: []float32{1, 1, 0}, dest: []float32{1, 1}}, 58 {src: []float32{1, 0, 0, 2, 0}, dest: []float32{1, 2}}, 59 } { 60 v := Float32sRemoveEmpty(test.src) 61 So(v, ShouldResemble, test.dest) 62 Float32sShuffle(v) 63 } 64 }) 65 } 66 67 func TestFloat64s(t *testing.T) { 68 Convey("float64 slice", t, func() { 69 for _, test := range []struct { 70 ss []float64 71 s float64 72 contains bool 73 }{ 74 {ss: nil, s: 1}, 75 {ss: []float64{1, 2}, s: 3, contains: false}, 76 {ss: []float64{1, 2}, s: 1, contains: true}, 77 } { 78 So(Float64sContain(test.ss, test.s), ShouldEqual, test.contains) 79 } 80 dest := Float64sSetAdd(nil, 1) 81 So(len(dest), ShouldEqual, 1) 82 So(len(Float64sSetAdd(dest, 1)), ShouldEqual, 1) 83 84 src := []float64{1, 2} 85 dest = Float64sWalk(src, func(s float64) (float64, bool) { 86 return s + 1, true 87 }) 88 So(len(src), ShouldEqual, len(dest)) 89 for i := 0; i < len(src); i++ { 90 So(src[i]+1, ShouldEqual, dest[i]) 91 } 92 for i := 0; i < 2; i++ { 93 if i > 0 { 94 tooManyElement = 4 95 } 96 for _, test := range []struct { 97 src []float64 98 dest []float64 99 contains bool 100 }{ 101 {src: []float64{1, 2, 2}, dest: []float64{1, 2}}, 102 {src: []float64{1, 1, 2}, dest: []float64{1, 2}}, 103 {src: []float64{1, 1, 2, 2, 2}, dest: []float64{1, 2}}, 104 } { 105 So(Float64sRemoveRepeated(test.src), ShouldResemble, test.dest) 106 } 107 } 108 109 for _, test := range []struct { 110 src []float64 111 dest []float64 112 contains bool 113 }{ 114 {src: []float64{1, 0, 2}, dest: []float64{1, 2}}, 115 {src: []float64{1, 1, 0}, dest: []float64{1, 1}}, 116 {src: []float64{1, 0, 0, 2, 0}, dest: []float64{1, 2}}, 117 } { 118 v := Float64sRemoveEmpty(test.src) 119 So(v, ShouldResemble, test.dest) 120 Float64sShuffle(v) 121 } 122 }) 123 } 124 125 func TestInts(t *testing.T) { 126 Convey("int slice", t, func() { 127 for _, test := range []struct { 128 ss []int 129 s int 130 contains bool 131 }{ 132 {ss: nil, s: 1}, 133 {ss: []int{1, 2}, s: 3, contains: false}, 134 {ss: []int{1, 2}, s: 1, contains: true}, 135 } { 136 So(IntsContain(test.ss, test.s), ShouldEqual, test.contains) 137 } 138 dest := IntsSetAdd(nil, 1) 139 So(len(dest), ShouldEqual, 1) 140 So(len(IntsSetAdd(dest, 1)), ShouldEqual, 1) 141 142 src := []int{1, 2} 143 dest = IntsWalk(src, func(s int) (int, bool) { 144 return s + 1, true 145 }) 146 So(len(src), ShouldEqual, len(dest)) 147 for i := 0; i < len(src); i++ { 148 So(src[i]+1, ShouldEqual, dest[i]) 149 } 150 for i := 0; i < 2; i++ { 151 if i > 0 { 152 tooManyElement = 4 153 } 154 for _, test := range []struct { 155 src []int 156 dest []int 157 contains bool 158 }{ 159 {src: []int{1, 2, 2}, dest: []int{1, 2}}, 160 {src: []int{1, 1, 2}, dest: []int{1, 2}}, 161 {src: []int{1, 1, 2, 2, 2}, dest: []int{1, 2}}, 162 } { 163 So(IntsRemoveRepeated(test.src), ShouldResemble, test.dest) 164 } 165 } 166 167 for _, test := range []struct { 168 src []int 169 dest []int 170 contains bool 171 }{ 172 {src: []int{1, 0, 2}, dest: []int{1, 2}}, 173 {src: []int{1, 1, 0}, dest: []int{1, 1}}, 174 {src: []int{1, 0, 0, 2, 0}, dest: []int{1, 2}}, 175 } { 176 v := IntsRemoveEmpty(test.src) 177 So(v, ShouldResemble, test.dest) 178 IntsShuffle(v) 179 } 180 }) 181 } 182 183 func TestInt16s(t *testing.T) { 184 Convey("int16 slice", t, func() { 185 for _, test := range []struct { 186 ss []int16 187 s int16 188 contains bool 189 }{ 190 {ss: nil, s: 1}, 191 {ss: []int16{1, 2}, s: 3, contains: false}, 192 {ss: []int16{1, 2}, s: 1, contains: true}, 193 } { 194 So(Int16sContain(test.ss, test.s), ShouldEqual, test.contains) 195 } 196 dest := Int16sSetAdd(nil, 1) 197 So(len(dest), ShouldEqual, 1) 198 So(len(Int16sSetAdd(dest, 1)), ShouldEqual, 1) 199 200 src := []int16{1, 2} 201 dest = Int16sWalk(src, func(s int16) (int16, bool) { 202 return s + 1, true 203 }) 204 So(len(src), ShouldEqual, len(dest)) 205 for i := 0; i < len(src); i++ { 206 So(src[i]+1, ShouldEqual, dest[i]) 207 } 208 for i := 0; i < 2; i++ { 209 if i > 0 { 210 tooManyElement = 4 211 } 212 for _, test := range []struct { 213 src []int16 214 dest []int16 215 contains bool 216 }{ 217 {src: []int16{1, 2, 2}, dest: []int16{1, 2}}, 218 {src: []int16{1, 1, 2}, dest: []int16{1, 2}}, 219 {src: []int16{1, 1, 2, 2, 2}, dest: []int16{1, 2}}, 220 } { 221 So(Int16sRemoveRepeated(test.src), ShouldResemble, test.dest) 222 } 223 } 224 225 for _, test := range []struct { 226 src []int16 227 dest []int16 228 contains bool 229 }{ 230 {src: []int16{1, 0, 2}, dest: []int16{1, 2}}, 231 {src: []int16{1, 1, 0}, dest: []int16{1, 1}}, 232 {src: []int16{1, 0, 0, 2, 0}, dest: []int16{1, 2}}, 233 } { 234 v := Int16sRemoveEmpty(test.src) 235 So(v, ShouldResemble, test.dest) 236 Int16sShuffle(v) 237 } 238 }) 239 } 240 241 func TestInt32s(t *testing.T) { 242 Convey("int32 slice", t, func() { 243 for _, test := range []struct { 244 ss []int32 245 s int32 246 contains bool 247 }{ 248 {ss: nil, s: 1}, 249 {ss: []int32{1, 2}, s: 3, contains: false}, 250 {ss: []int32{1, 2}, s: 1, contains: true}, 251 } { 252 So(Int32sContain(test.ss, test.s), ShouldEqual, test.contains) 253 } 254 dest := Int32sSetAdd(nil, 1) 255 So(len(dest), ShouldEqual, 1) 256 So(len(Int32sSetAdd(dest, 1)), ShouldEqual, 1) 257 258 src := []int32{1, 2} 259 dest = Int32sWalk(src, func(s int32) (int32, bool) { 260 return s + 1, true 261 }) 262 So(len(src), ShouldEqual, len(dest)) 263 for i := 0; i < len(src); i++ { 264 So(src[i]+1, ShouldEqual, dest[i]) 265 } 266 for i := 0; i < 2; i++ { 267 if i > 0 { 268 tooManyElement = 4 269 } 270 for _, test := range []struct { 271 src []int32 272 dest []int32 273 contains bool 274 }{ 275 {src: []int32{1, 2, 2}, dest: []int32{1, 2}}, 276 {src: []int32{1, 1, 2}, dest: []int32{1, 2}}, 277 {src: []int32{1, 1, 2, 2, 2}, dest: []int32{1, 2}}, 278 } { 279 So(Int32sRemoveRepeated(test.src), ShouldResemble, test.dest) 280 } 281 } 282 283 for _, test := range []struct { 284 src []int32 285 dest []int32 286 contains bool 287 }{ 288 {src: []int32{1, 0, 2}, dest: []int32{1, 2}}, 289 {src: []int32{1, 1, 0}, dest: []int32{1, 1}}, 290 {src: []int32{1, 0, 0, 2, 0}, dest: []int32{1, 2}}, 291 } { 292 v := Int32sRemoveEmpty(test.src) 293 So(v, ShouldResemble, test.dest) 294 Int32sShuffle(v) 295 } 296 }) 297 } 298 299 func TestInt64s(t *testing.T) { 300 Convey("int64 slice", t, func() { 301 for _, test := range []struct { 302 ss []int64 303 s int64 304 contains bool 305 }{ 306 {ss: nil, s: 1}, 307 {ss: []int64{1, 2}, s: 3, contains: false}, 308 {ss: []int64{1, 2}, s: 1, contains: true}, 309 } { 310 So(Int64sContain(test.ss, test.s), ShouldEqual, test.contains) 311 } 312 dest := Int64sSetAdd(nil, 1) 313 So(len(dest), ShouldEqual, 1) 314 So(len(Int64sSetAdd(dest, 1)), ShouldEqual, 1) 315 316 src := []int64{1, 2} 317 dest = Int64sWalk(src, func(s int64) (int64, bool) { 318 return s + 1, true 319 }) 320 So(len(src), ShouldEqual, len(dest)) 321 for i := 0; i < len(src); i++ { 322 So(src[i]+1, ShouldEqual, dest[i]) 323 } 324 for i := 0; i < 2; i++ { 325 if i > 0 { 326 tooManyElement = 4 327 } 328 for _, test := range []struct { 329 src []int64 330 dest []int64 331 contains bool 332 }{ 333 {src: []int64{1, 2, 2}, dest: []int64{1, 2}}, 334 {src: []int64{1, 1, 2}, dest: []int64{1, 2}}, 335 {src: []int64{1, 1, 2, 2, 2}, dest: []int64{1, 2}}, 336 } { 337 So(Int64sRemoveRepeated(test.src), ShouldResemble, test.dest) 338 } 339 } 340 341 for _, test := range []struct { 342 src []int64 343 dest []int64 344 contains bool 345 }{ 346 {src: []int64{1, 0, 2}, dest: []int64{1, 2}}, 347 {src: []int64{1, 1, 0}, dest: []int64{1, 1}}, 348 {src: []int64{1, 0, 0, 2, 0}, dest: []int64{1, 2}}, 349 } { 350 v := Int64sRemoveEmpty(test.src) 351 So(v, ShouldResemble, test.dest) 352 Int64sShuffle(v) 353 } 354 }) 355 } 356 357 func TestInt8s(t *testing.T) { 358 Convey("int8 slice", t, func() { 359 for _, test := range []struct { 360 ss []int8 361 s int8 362 contains bool 363 }{ 364 {ss: nil, s: 1}, 365 {ss: []int8{1, 2}, s: 3, contains: false}, 366 {ss: []int8{1, 2}, s: 1, contains: true}, 367 } { 368 So(Int8sContain(test.ss, test.s), ShouldEqual, test.contains) 369 } 370 dest := Int8sSetAdd(nil, 1) 371 So(len(dest), ShouldEqual, 1) 372 So(len(Int8sSetAdd(dest, 1)), ShouldEqual, 1) 373 374 src := []int8{1, 2} 375 dest = Int8sWalk(src, func(s int8) (int8, bool) { 376 return s + 1, true 377 }) 378 So(len(src), ShouldEqual, len(dest)) 379 for i := 0; i < len(src); i++ { 380 So(src[i]+1, ShouldEqual, dest[i]) 381 } 382 for i := 0; i < 2; i++ { 383 if i > 0 { 384 tooManyElement = 4 385 } 386 for _, test := range []struct { 387 src []int8 388 dest []int8 389 contains bool 390 }{ 391 {src: []int8{1, 2, 2}, dest: []int8{1, 2}}, 392 {src: []int8{1, 1, 2}, dest: []int8{1, 2}}, 393 {src: []int8{1, 1, 2, 2, 2}, dest: []int8{1, 2}}, 394 } { 395 So(Int8sRemoveRepeated(test.src), ShouldResemble, test.dest) 396 } 397 } 398 399 for _, test := range []struct { 400 src []int8 401 dest []int8 402 contains bool 403 }{ 404 {src: []int8{1, 0, 2}, dest: []int8{1, 2}}, 405 {src: []int8{1, 1, 0}, dest: []int8{1, 1}}, 406 {src: []int8{1, 0, 0, 2, 0}, dest: []int8{1, 2}}, 407 } { 408 v := Int8sRemoveEmpty(test.src) 409 So(v, ShouldResemble, test.dest) 410 Int8sShuffle(v) 411 } 412 }) 413 } 414 415 func TestStrings(t *testing.T) { 416 Convey("string slice", t, func() { 417 for _, test := range []struct { 418 ss []string 419 s string 420 contains bool 421 }{ 422 {ss: nil, s: "a"}, 423 {ss: []string{"abc", "b"}, s: "a", contains: false}, 424 {ss: []string{"abc", "b"}, s: "abc", contains: true}, 425 } { 426 So(StringsContain(test.ss, test.s), ShouldEqual, test.contains) 427 } 428 for _, test := range []struct { 429 ss []string 430 s string 431 contains bool 432 }{ 433 {ss: nil, s: "a"}, 434 {ss: []string{"abc", "b"}, s: "a", contains: false}, 435 {ss: []string{"abc", "b"}, s: "abc", contains: true}, 436 {ss: []string{"ABC", "b"}, s: "abc", contains: true}, 437 } { 438 So(StringsContainEqualFold(test.ss, test.s), ShouldEqual, test.contains) 439 } 440 dest := StringsSetAdd(nil, "a") 441 So(len(dest), ShouldEqual, 1) 442 So(len(StringsSetAdd(dest, "a")), ShouldEqual, 1) 443 444 src := []string{"1", "2"} 445 dest = StringsWalk(src, func(s string) (string, bool) { 446 return s + ",", true 447 }) 448 So(len(src), ShouldEqual, len(dest)) 449 for i := 0; i < len(src); i++ { 450 So(src[i]+",", ShouldEqual, dest[i]) 451 } 452 453 dest = StringsAddSuffix(src, ",") 454 So(len(src), ShouldEqual, len(dest)) 455 for i := 0; i < len(src); i++ { 456 So(src[i]+",", ShouldEqual, dest[i]) 457 } 458 459 dest = StringsAddPrefix(src, ",") 460 So(len(src), ShouldEqual, len(dest)) 461 for i := 0; i < len(src); i++ { 462 So(","+src[i], ShouldEqual, dest[i]) 463 } 464 for i := 0; i < 2; i++ { 465 if i > 0 { 466 tooManyElement = 4 467 } 468 for _, test := range []struct { 469 src []string 470 dest []string 471 contains bool 472 }{ 473 {src: []string{"abc", "b", "b"}, dest: []string{"abc", "b"}}, 474 {src: []string{"abc", "abc", "b"}, dest: []string{"abc", "b"}}, 475 {src: []string{"abc", "abc", "b", "b", "b"}, dest: []string{"abc", "b"}}, 476 } { 477 So(StringsRemoveRepeated(test.src), ShouldResemble, test.dest) 478 } 479 } 480 481 for _, test := range []struct { 482 src []string 483 dest []string 484 contains bool 485 }{ 486 {src: []string{"abc", "", "b"}, dest: []string{"abc", "b"}}, 487 {src: []string{"abc", "abc", ""}, dest: []string{"abc", "abc"}}, 488 {src: []string{"abc", "", "", "b", ""}, dest: []string{"abc", "b"}}, 489 } { 490 v := StringsRemoveEmpty(test.src) 491 So(v, ShouldResemble, test.dest) 492 StringsShuffle(v) 493 } 494 }) 495 } 496 497 func TestUints(t *testing.T) { 498 Convey("uint slice", t, func() { 499 for _, test := range []struct { 500 ss []uint 501 s uint 502 contains bool 503 }{ 504 {ss: nil, s: 1}, 505 {ss: []uint{1, 2}, s: 3, contains: false}, 506 {ss: []uint{1, 2}, s: 1, contains: true}, 507 } { 508 So(UintsContain(test.ss, test.s), ShouldEqual, test.contains) 509 } 510 dest := UintsSetAdd(nil, 1) 511 So(len(dest), ShouldEqual, 1) 512 So(len(UintsSetAdd(dest, 1)), ShouldEqual, 1) 513 514 src := []uint{1, 2} 515 dest = UintsWalk(src, func(s uint) (uint, bool) { 516 return s + 1, true 517 }) 518 So(len(src), ShouldEqual, len(dest)) 519 for i := 0; i < len(src); i++ { 520 So(src[i]+1, ShouldEqual, dest[i]) 521 } 522 for i := 0; i < 2; i++ { 523 if i > 0 { 524 tooManyElement = 4 525 } 526 for _, test := range []struct { 527 src []uint 528 dest []uint 529 contains bool 530 }{ 531 {src: []uint{1, 2, 2}, dest: []uint{1, 2}}, 532 {src: []uint{1, 1, 2}, dest: []uint{1, 2}}, 533 {src: []uint{1, 1, 2, 2, 2}, dest: []uint{1, 2}}, 534 } { 535 So(UintsRemoveRepeated(test.src), ShouldResemble, test.dest) 536 } 537 } 538 539 for _, test := range []struct { 540 src []uint 541 dest []uint 542 contains bool 543 }{ 544 {src: []uint{1, 0, 2}, dest: []uint{1, 2}}, 545 {src: []uint{1, 1, 0}, dest: []uint{1, 1}}, 546 {src: []uint{1, 0, 0, 2, 0}, dest: []uint{1, 2}}, 547 } { 548 v := UintsRemoveEmpty(test.src) 549 So(v, ShouldResemble, test.dest) 550 UintsShuffle(v) 551 } 552 }) 553 } 554 555 func TestUint16s(t *testing.T) { 556 Convey("uint16 slice", t, func() { 557 for _, test := range []struct { 558 ss []uint16 559 s uint16 560 contains bool 561 }{ 562 {ss: nil, s: 1}, 563 {ss: []uint16{1, 2}, s: 3, contains: false}, 564 {ss: []uint16{1, 2}, s: 1, contains: true}, 565 } { 566 So(Uint16sContain(test.ss, test.s), ShouldEqual, test.contains) 567 } 568 dest := Uint16sSetAdd(nil, 1) 569 So(len(dest), ShouldEqual, 1) 570 So(len(Uint16sSetAdd(dest, 1)), ShouldEqual, 1) 571 572 src := []uint16{1, 2} 573 dest = Uint16sWalk(src, func(s uint16) (uint16, bool) { 574 return s + 1, true 575 }) 576 So(len(src), ShouldEqual, len(dest)) 577 for i := 0; i < len(src); i++ { 578 So(src[i]+1, ShouldEqual, dest[i]) 579 } 580 for i := 0; i < 2; i++ { 581 if i > 0 { 582 tooManyElement = 4 583 } 584 for _, test := range []struct { 585 src []uint16 586 dest []uint16 587 contains bool 588 }{ 589 {src: []uint16{1, 2, 2}, dest: []uint16{1, 2}}, 590 {src: []uint16{1, 1, 2}, dest: []uint16{1, 2}}, 591 {src: []uint16{1, 1, 2, 2, 2}, dest: []uint16{1, 2}}, 592 } { 593 So(Uint16sRemoveRepeated(test.src), ShouldResemble, test.dest) 594 } 595 } 596 597 for _, test := range []struct { 598 src []uint16 599 dest []uint16 600 contains bool 601 }{ 602 {src: []uint16{1, 0, 2}, dest: []uint16{1, 2}}, 603 {src: []uint16{1, 1, 0}, dest: []uint16{1, 1}}, 604 {src: []uint16{1, 0, 0, 2, 0}, dest: []uint16{1, 2}}, 605 } { 606 v := Uint16sRemoveEmpty(test.src) 607 So(v, ShouldResemble, test.dest) 608 Uint16sShuffle(v) 609 } 610 }) 611 } 612 613 func TestUint32s(t *testing.T) { 614 Convey("uint32 slice", t, func() { 615 for _, test := range []struct { 616 ss []uint32 617 s uint32 618 contains bool 619 }{ 620 {ss: nil, s: 1}, 621 {ss: []uint32{1, 2}, s: 3, contains: false}, 622 {ss: []uint32{1, 2}, s: 1, contains: true}, 623 } { 624 So(Uint32sContain(test.ss, test.s), ShouldEqual, test.contains) 625 } 626 dest := Uint32sSetAdd(nil, 1) 627 So(len(dest), ShouldEqual, 1) 628 So(len(Uint32sSetAdd(dest, 1)), ShouldEqual, 1) 629 630 src := []uint32{1, 2} 631 dest = Uint32sWalk(src, func(s uint32) (uint32, bool) { 632 return s + 1, true 633 }) 634 So(len(src), ShouldEqual, len(dest)) 635 for i := 0; i < len(src); i++ { 636 So(src[i]+1, ShouldEqual, dest[i]) 637 } 638 for i := 0; i < 2; i++ { 639 if i > 0 { 640 tooManyElement = 4 641 } 642 for _, test := range []struct { 643 src []uint32 644 dest []uint32 645 contains bool 646 }{ 647 {src: []uint32{1, 2, 2}, dest: []uint32{1, 2}}, 648 {src: []uint32{1, 1, 2}, dest: []uint32{1, 2}}, 649 {src: []uint32{1, 1, 2, 2, 2}, dest: []uint32{1, 2}}, 650 } { 651 So(Uint32sRemoveRepeated(test.src), ShouldResemble, test.dest) 652 } 653 } 654 655 for _, test := range []struct { 656 src []uint32 657 dest []uint32 658 contains bool 659 }{ 660 {src: []uint32{1, 0, 2}, dest: []uint32{1, 2}}, 661 {src: []uint32{1, 1, 0}, dest: []uint32{1, 1}}, 662 {src: []uint32{1, 0, 0, 2, 0}, dest: []uint32{1, 2}}, 663 } { 664 v := Uint32sRemoveEmpty(test.src) 665 So(v, ShouldResemble, test.dest) 666 Uint32sShuffle(v) 667 } 668 }) 669 } 670 671 func TestUint64s(t *testing.T) { 672 Convey("uint64 slice", t, func() { 673 for _, test := range []struct { 674 ss []uint64 675 s uint64 676 contains bool 677 }{ 678 {ss: nil, s: 1}, 679 {ss: []uint64{1, 2}, s: 3, contains: false}, 680 {ss: []uint64{1, 2}, s: 1, contains: true}, 681 } { 682 So(Uint64sContain(test.ss, test.s), ShouldEqual, test.contains) 683 } 684 dest := Uint64sSetAdd(nil, 1) 685 So(len(dest), ShouldEqual, 1) 686 So(len(Uint64sSetAdd(dest, 1)), ShouldEqual, 1) 687 688 src := []uint64{1, 2} 689 dest = Uint64sWalk(src, func(s uint64) (uint64, bool) { 690 return s + 1, true 691 }) 692 So(len(src), ShouldEqual, len(dest)) 693 for i := 0; i < len(src); i++ { 694 So(src[i]+1, ShouldEqual, dest[i]) 695 } 696 for i := 0; i < 2; i++ { 697 if i > 0 { 698 tooManyElement = 4 699 } 700 for _, test := range []struct { 701 src []uint64 702 dest []uint64 703 contains bool 704 }{ 705 {src: []uint64{1, 2, 2}, dest: []uint64{1, 2}}, 706 {src: []uint64{1, 1, 2}, dest: []uint64{1, 2}}, 707 {src: []uint64{1, 1, 2, 2, 2}, dest: []uint64{1, 2}}, 708 } { 709 So(Uint64sRemoveRepeated(test.src), ShouldResemble, test.dest) 710 } 711 } 712 713 for _, test := range []struct { 714 src []uint64 715 dest []uint64 716 contains bool 717 }{ 718 {src: []uint64{1, 0, 2}, dest: []uint64{1, 2}}, 719 {src: []uint64{1, 1, 0}, dest: []uint64{1, 1}}, 720 {src: []uint64{1, 0, 0, 2, 0}, dest: []uint64{1, 2}}, 721 } { 722 v := Uint64sRemoveEmpty(test.src) 723 So(v, ShouldResemble, test.dest) 724 Uint64sShuffle(v) 725 } 726 }) 727 } 728 729 func TestUint8s(t *testing.T) { 730 Convey("uint8 slice", t, func() { 731 for _, test := range []struct { 732 ss []uint8 733 s uint8 734 contains bool 735 }{ 736 {ss: nil, s: 1}, 737 {ss: []uint8{1, 2}, s: 3, contains: false}, 738 {ss: []uint8{1, 2}, s: 1, contains: true}, 739 } { 740 So(Uint8sContain(test.ss, test.s), ShouldEqual, test.contains) 741 } 742 dest := Uint8sSetAdd(nil, 1) 743 So(len(dest), ShouldEqual, 1) 744 So(len(Uint8sSetAdd(dest, 1)), ShouldEqual, 1) 745 746 src := []uint8{1, 2} 747 dest = Uint8sWalk(src, func(s uint8) (uint8, bool) { 748 return s + 1, true 749 }) 750 So(len(src), ShouldEqual, len(dest)) 751 for i := 0; i < len(src); i++ { 752 So(src[i]+1, ShouldEqual, dest[i]) 753 } 754 for i := 0; i < 2; i++ { 755 if i > 0 { 756 tooManyElement = 4 757 } 758 for _, test := range []struct { 759 src []uint8 760 dest []uint8 761 contains bool 762 }{ 763 {src: []uint8{1, 2, 2}, dest: []uint8{1, 2}}, 764 {src: []uint8{1, 1, 2}, dest: []uint8{1, 2}}, 765 {src: []uint8{1, 1, 2, 2, 2}, dest: []uint8{1, 2}}, 766 } { 767 So(Uint8sRemoveRepeated(test.src), ShouldResemble, test.dest) 768 } 769 } 770 771 for _, test := range []struct { 772 src []uint8 773 dest []uint8 774 contains bool 775 }{ 776 {src: []uint8{1, 0, 2}, dest: []uint8{1, 2}}, 777 {src: []uint8{1, 1, 0}, dest: []uint8{1, 1}}, 778 {src: []uint8{1, 0, 0, 2, 0}, dest: []uint8{1, 2}}, 779 } { 780 v := Uint8sRemoveEmpty(test.src) 781 So(v, ShouldResemble, test.dest) 782 Uint8sShuffle(v) 783 } 784 }) 785 }