use of android.icu.impl.coll.CollationWeights in project j2objc by google.
the class CollationTest method TestCollationWeights.
@Test
public void TestCollationWeights() {
CollationWeights cw = new CollationWeights();
// Non-compressible primaries use 254 second bytes 02..FF.
logln("CollationWeights.initForPrimary(non-compressible)");
cw.initForPrimary(false);
// Expect 1 weight 11 and 254 weights 12xx.
checkAllocWeights(cw, 0x10000000L, 0x13000000L, 255, 1, 1);
checkAllocWeights(cw, 0x10000000L, 0x13000000L, 255, 2, 254);
// Expect 255 two-byte weights from the ranges 10ff, 11xx, 1202.
checkAllocWeights(cw, 0x10fefe40L, 0x12030300L, 260, 2, 255);
// Expect 254 two-byte weights from the ranges 10ff and 11xx.
checkAllocWeights(cw, 0x10fefe40L, 0x12030300L, 600, 2, 254);
// Expect 254^2=64516 three-byte weights.
// During computation, there should be 3 three-byte ranges
// 10ffff, 11xxxx, 120202.
// The middle one should be split 64515:1,
// and the newly-split-off range and the last ranged lengthened.
checkAllocWeights(cw, 0x10fffe00L, 0x12020300L, 1 + 64516 + 254 + 1, 3, 64516);
// Expect weights 1102 & 1103.
checkAllocWeights(cw, 0x10ff0000L, 0x11040000L, 2, 2, 2);
// Expect weights 102102 & 102103.
checkAllocWeights(cw, 0x1020ff00L, 0x10210400L, 2, 3, 2);
// Compressible primaries use 251 second bytes 04..FE.
logln("CollationWeights.initForPrimary(compressible)");
cw.initForPrimary(true);
// Expect 1 weight 11 and 251 weights 12xx.
checkAllocWeights(cw, 0x10000000L, 0x13000000L, 252, 1, 1);
checkAllocWeights(cw, 0x10000000L, 0x13000000L, 252, 2, 251);
// Expect 252 two-byte weights from the ranges 10fe, 11xx, 1204.
checkAllocWeights(cw, 0x10fdfe40L, 0x12050300L, 260, 2, 252);
// Expect weights 1104 & 1105.
checkAllocWeights(cw, 0x10fe0000L, 0x11060000L, 2, 2, 2);
// Expect weights 102102 & 102103.
checkAllocWeights(cw, 0x1020ff00L, 0x10210400L, 2, 3, 2);
// Secondary and tertiary weights use only bytes 3 & 4.
logln("CollationWeights.initForSecondary()");
cw.initForSecondary();
// Expect weights fbxx and all four fc..ff.
checkAllocWeights(cw, 0xfb20L, 0x10000L, 20, 3, 4);
logln("CollationWeights.initForTertiary()");
cw.initForTertiary();
// Expect weights 3dxx and both 3e & 3f.
checkAllocWeights(cw, 0x3d02L, 0x4000L, 10, 3, 2);
}
use of android.icu.impl.coll.CollationWeights in project j2objc by google.
the class CollationTest method TestRootElements.
@Test
public void TestRootElements() {
CollationData root = CollationRoot.getData();
CollationRootElements rootElements = new CollationRootElements(root.rootElements);
RootElementsIterator iter = new RootElementsIterator(root);
// We check each root CE for validity,
// and we also verify that there is a tailoring gap between each two CEs.
// compressible primary weights
CollationWeights cw1c = new CollationWeights();
// uncompressible primary weights
CollationWeights cw1u = new CollationWeights();
CollationWeights cw2 = new CollationWeights();
CollationWeights cw3 = new CollationWeights();
cw1c.initForPrimary(true);
cw1u.initForPrimary(false);
cw2.initForSecondary();
cw3.initForTertiary();
// Note: The root elements do not include Han-implicit or unassigned-implicit CEs,
// nor the special merge-separator CE for U+FFFE.
long prevPri = 0;
long prevSec = 0;
long prevTer = 0;
while (iter.next()) {
long pri = iter.getPrimary();
long secTer = iter.getSecTer();
// CollationRootElements CEs must have 0 case and quaternary bits.
if ((secTer & Collation.CASE_AND_QUATERNARY_MASK) != 0) {
errln("CollationRootElements CE has non-zero case and/or quaternary bits: " + "0x" + Utility.hex(pri, 8) + " 0x" + Utility.hex(secTer, 8));
}
long sec = secTer >>> 16;
long ter = secTer & Collation.ONLY_TERTIARY_MASK;
long ctq = ter;
if (pri == 0 && sec == 0 && ter != 0) {
// Tertiary CEs must have uppercase bits,
// but they are not stored in the CollationRootElements.
ctq |= 0x8000;
}
if (!isValidCE(rootElements, root, pri, sec, ctq)) {
errln("invalid root CE 0x" + Utility.hex(pri, 8) + " 0x" + Utility.hex(secTer, 8));
} else {
if (pri != prevPri) {
long newWeight = 0;
if (prevPri == 0 || prevPri >= Collation.FFFD_PRIMARY) {
// There is currently no tailoring gap after primary ignorables,
// and we forbid tailoring after U+FFFD and U+FFFF.
} else if (root.isCompressiblePrimary(prevPri)) {
if (!cw1c.allocWeights(prevPri, pri, 1)) {
errln("no primary/compressible tailoring gap between " + "0x" + Utility.hex(prevPri, 8) + " and 0x" + Utility.hex(pri, 8));
} else {
newWeight = cw1c.nextWeight();
}
} else {
if (!cw1u.allocWeights(prevPri, pri, 1)) {
errln("no primary/uncompressible tailoring gap between " + "0x" + Utility.hex(prevPri, 8) + " and 0x" + Utility.hex(pri, 8));
} else {
newWeight = cw1u.nextWeight();
}
}
if (newWeight != 0 && !(prevPri < newWeight && newWeight < pri)) {
errln("mis-allocated primary weight, should get " + "0x" + Utility.hex(prevPri, 8) + " < 0x" + Utility.hex(newWeight, 8) + " < 0x" + Utility.hex(pri, 8));
}
} else if (sec != prevSec) {
long lowerLimit = prevSec == 0 ? rootElements.getSecondaryBoundary() - 0x100 : prevSec;
if (!cw2.allocWeights(lowerLimit, sec, 1)) {
errln("no secondary tailoring gap between " + "0x" + Utility.hex(lowerLimit) + " and 0x" + Utility.hex(sec));
} else {
long newWeight = cw2.nextWeight();
if (!(prevSec < newWeight && newWeight < sec)) {
errln("mis-allocated secondary weight, should get " + "0x" + Utility.hex(lowerLimit) + " < 0x" + Utility.hex(newWeight) + " < 0x" + Utility.hex(sec));
}
}
} else if (ter != prevTer) {
long lowerLimit = prevTer == 0 ? rootElements.getTertiaryBoundary() - 0x100 : prevTer;
if (!cw3.allocWeights(lowerLimit, ter, 1)) {
errln("no tertiary tailoring gap between " + "0x" + Utility.hex(lowerLimit) + " and 0x" + Utility.hex(ter));
} else {
long newWeight = cw3.nextWeight();
if (!(prevTer < newWeight && newWeight < ter)) {
errln("mis-allocated tertiary weight, should get " + "0x" + Utility.hex(lowerLimit) + " < 0x" + Utility.hex(newWeight) + " < 0x" + Utility.hex(ter));
}
}
} else {
errln("duplicate root CE 0x" + Utility.hex(pri, 8) + " 0x" + Utility.hex(secTer, 8));
}
}
prevPri = pri;
prevSec = sec;
prevTer = ter;
}
}
Aggregations