From e9c6dc86a01b0d95362f21b71449a8bf4bd85666 Mon Sep 17 00:00:00 2001 From: btangmu Date: Tue, 12 Mar 2024 09:35:26 -0400 Subject: [PATCH] CLDR-11155 Pages too big: add test for large pages -New testPageSize in TestPathHeader.java --- .../unicode/cldr/unittest/TestPathHeader.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java index ee0225cb3ed..b1d627e9084 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestPathHeader.java @@ -26,11 +26,13 @@ import java.util.TreeMap; import java.util.TreeSet; import java.util.regex.Matcher; +import java.util.stream.Collectors; import org.unicode.cldr.test.CoverageLevel2; import org.unicode.cldr.test.ExampleGenerator; import org.unicode.cldr.util.CLDRConfig; import org.unicode.cldr.util.CLDRFile; import org.unicode.cldr.util.CLDRFile.Status; +import org.unicode.cldr.util.CLDRLocale; import org.unicode.cldr.util.CLDRPaths; import org.unicode.cldr.util.CLDRURLS; import org.unicode.cldr.util.CldrUtility; @@ -1677,4 +1679,70 @@ public void TestUnitOrder() { } } } + + public void testPageSize() { + final long minError = 946; // above this, emit error + final long minLog = 700; // otherwise above this, emit warning + Factory factory = CLDRConfig.getInstance().getCommonAndSeedAndMainAndAnnotationsFactory(); + // "en", "cs", "ar", "pl" + List locales = + StandardCodes.make() + .getLocaleCoverageLocales(Organization.cldr, ImmutableSet.of(Level.MODERN)) + .stream() + .filter(x -> CLDRLocale.getInstance(x).getCountry().isEmpty()) + .collect(Collectors.toUnmodifiableList()); + List> counters = new ArrayList<>(); + for (String locale : locales) { + CLDRFile cldrFile = factory.make(locale, false); + PathHeader.Factory phf = PathHeader.getFactory(); + Counter c = new Counter<>(); + counters.add(c); + for (String path : cldrFile) { + PathHeader ph = phf.fromPath(path); + c.add(ph.getPageId(), 1); + } + for (PageId entry : c.getKeysetSortedByKey()) { + long count = c.getCount(entry); + if (count > minError) { + errln( + locale + + "\t" + + entry.getSectionId() + + "\t" + + entry + + "\thas too many entries:\t" + + count); + } else if (count > minLog) { + warnln( + locale + + "\t" + + entry.getSectionId() + + "\t" + + "\thas too many entries:\t" + + count); + } + } + } + if (isVerbose()) { + System.out.println(); + Set sorted = new TreeSet<>(); + for (Counter counter : counters) { + sorted.addAll(counter.keySet()); + } + int i = 0; + System.out.print("Order" + "\t" + "Section" + "\t" + "Page"); + for (String c : locales) { + System.out.print("\t" + c); + } + System.out.println(); + + for (PageId entry : sorted) { + System.out.print(++i + "\t" + entry.getSectionId() + "\t" + entry); + for (Counter c : counters) { + System.out.print("\t" + c.get(entry)); + } + System.out.println(); + } + } + } }