605 void testBufferType(BT bt, |
606 void testBufferType(BT bt, |
606 BiFunction<BT, Integer, B> aConstructor, |
607 BiFunction<BT, Integer, B> aConstructor, |
607 BiFunction<BT, Integer, B> bConstructor) { |
608 BiFunction<BT, Integer, B> bConstructor) { |
608 int n = arraySizeFor(bt.elementType); |
609 int n = arraySizeFor(bt.elementType); |
609 |
610 |
610 for (int s : ranges(0, n)) { |
611 for (boolean dupOtherwiseSlice : new boolean[]{ false, true }) { |
611 B a = aConstructor.apply(bt, s); |
612 for (int s : ranges(0, n)) { |
612 B b = bConstructor.apply(bt, s); |
613 B a = aConstructor.apply(bt, s); |
613 |
614 B b = bConstructor.apply(bt, s); |
614 for (int aFrom : ranges(0, s)) { |
615 |
615 for (int aTo : ranges(aFrom, s)) { |
616 for (int aFrom : ranges(0, s)) { |
616 int aLength = aTo - aFrom; |
617 for (int aTo : ranges(aFrom, s)) { |
617 |
618 int aLength = aTo - aFrom; |
618 B as = aLength != s |
619 |
619 ? bt.slice(a, aFrom, aTo) |
620 B as = aLength != s |
620 : a; |
621 ? bt.slice(a, aFrom, aTo, dupOtherwiseSlice) |
621 |
622 : a; |
622 for (int bFrom : ranges(0, s)) { |
623 |
623 for (int bTo : ranges(bFrom, s)) { |
624 for (int bFrom : ranges(0, s)) { |
624 int bLength = bTo - bFrom; |
625 for (int bTo : ranges(bFrom, s)) { |
625 |
626 int bLength = bTo - bFrom; |
626 B bs = bLength != s |
627 |
627 ? bt.slice(b, bFrom, bTo) |
628 B bs = bLength != s |
628 : b; |
629 ? bt.slice(b, bFrom, bTo, dupOtherwiseSlice) |
629 |
630 : b; |
630 boolean eq = bt.pairWiseEquals(as, bs); |
631 |
631 Assert.assertEquals(bt.equals(as, bs), eq); |
632 boolean eq = bt.pairWiseEquals(as, bs); |
632 Assert.assertEquals(bt.equals(bs, as), eq); |
633 Assert.assertEquals(bt.equals(as, bs), eq); |
633 if (eq) { |
634 Assert.assertEquals(bt.equals(bs, as), eq); |
634 Assert.assertEquals(bt.compare(as, bs), 0); |
635 if (eq) { |
635 Assert.assertEquals(bt.compare(bs, as), 0); |
636 Assert.assertEquals(bt.compare(as, bs), 0); |
|
637 Assert.assertEquals(bt.compare(bs, as), 0); |
|
638 } |
|
639 else { |
|
640 int aCb = bt.compare(as, bs); |
|
641 int bCa = bt.compare(bs, as); |
|
642 int v = Integer.signum(aCb) * Integer.signum(bCa); |
|
643 Assert.assertTrue(v == -1); |
|
644 } |
636 } |
645 } |
637 else { |
646 } |
638 int aCb = bt.compare(as, bs); |
647 |
639 int bCa = bt.compare(bs, as); |
648 if (aLength > 0 && !a.isReadOnly()) { |
640 int v = Integer.signum(aCb) * Integer.signum(bCa); |
649 for (int i = aFrom; i < aTo; i++) { |
|
650 B c = aConstructor.apply(bt, a.capacity()); |
|
651 B cs = aLength != s |
|
652 ? bt.slice(c, aFrom, aTo, dupOtherwiseSlice) |
|
653 : c; |
|
654 |
|
655 // Create common prefix with a length of i - aFrom |
|
656 bt.set(c, i, -1); |
|
657 |
|
658 Assert.assertFalse(bt.equals(c, a)); |
|
659 |
|
660 int cCa = bt.compare(cs, as); |
|
661 int aCc = bt.compare(as, cs); |
|
662 int v = Integer.signum(cCa) * Integer.signum(aCc); |
641 Assert.assertTrue(v == -1); |
663 Assert.assertTrue(v == -1); |
642 } |
664 } |
643 } |
|
644 } |
|
645 |
|
646 if (aLength > 0 && !a.isReadOnly()) { |
|
647 for (int i = aFrom; i < aTo; i++) { |
|
648 B c = aConstructor.apply(bt, a.capacity()); |
|
649 B cs = aLength != s |
|
650 ? bt.slice(c, aFrom, aTo) |
|
651 : c; |
|
652 |
|
653 // Create common prefix with a length of i - aFrom |
|
654 bt.set(c, i, -1); |
|
655 |
|
656 Assert.assertFalse(bt.equals(c, a)); |
|
657 |
|
658 int cCa = bt.compare(cs, as); |
|
659 int aCc = bt.compare(as, cs); |
|
660 int v = Integer.signum(cCa) * Integer.signum(aCc); |
|
661 Assert.assertTrue(v == -1); |
|
662 } |
665 } |
663 } |
666 } |
664 } |
667 } |
665 } |
668 } |
666 } |
669 } |