1 package org.unicode.cldr.util; 2 3 import static org.junit.jupiter.api.Assertions.assertEquals; 4 import static org.junit.jupiter.api.Assertions.assertFalse; 5 import static org.junit.jupiter.api.Assertions.assertTrue; 6 import static org.junit.jupiter.api.Assumptions.assumeFalse; 7 import static org.junit.jupiter.params.provider.Arguments.arguments; 8 9 import java.util.Set; 10 import java.util.TreeSet; 11 import java.util.stream.Stream; 12 import org.junit.jupiter.api.BeforeAll; 13 import org.junit.jupiter.api.Test; 14 import org.junit.jupiter.params.ParameterizedTest; 15 import org.junit.jupiter.params.provider.Arguments; 16 import org.junit.jupiter.params.provider.CsvSource; 17 import org.junit.jupiter.params.provider.MethodSource; 18 19 public class TestLevel { 20 @ParameterizedTest(name = "{index}: min {0},{1}") 21 @CsvSource({ 22 // a, b, expected => min(a, b) == expected 23 "UNDETERMINED,UNDETERMINED,UNDETERMINED", 24 "BASIC,MODERN,BASIC", 25 "BASIC,COMPREHENSIVE,BASIC", 26 "MODERN,MODERN,MODERN", 27 "MODERN,COMPREHENSIVE,MODERN", 28 "COMPREHENSIVE,MODERN,MODERN", 29 }) testMin(final String a, final String b, final String c)30 void testMin(final String a, final String b, final String c) { 31 final Level aa = Level.fromString(a); 32 final Level bb = Level.fromString(b); 33 final Level expect = Level.fromString(c); 34 final Level actual = Level.min(aa, bb); 35 assertEquals( 36 expect, 37 actual, 38 () -> String.format("Expected Level.min(%s,%s) but was %s", aa, bb, actual)); 39 } 40 41 @ParameterizedTest(name = "{index}: max {0},{1}") 42 @CsvSource({ 43 // a, b, expected => min(a, b) == expected 44 "UNDETERMINED,UNDETERMINED,UNDETERMINED", 45 "BASIC,MODERN,MODERN", 46 "BASIC,COMPREHENSIVE,COMPREHENSIVE", 47 "MODERN,MODERN,MODERN", 48 "MODERN,COMPREHENSIVE,COMPREHENSIVE", 49 "COMPREHENSIVE,MODERN,COMPREHENSIVE", 50 }) testMax(final String a, final String b, final String c)51 void testMax(final String a, final String b, final String c) { 52 final Level aa = Level.fromString(a); 53 final Level bb = Level.fromString(b); 54 final Level expect = Level.fromString(c); 55 final Level actual = Level.max(aa, bb); 56 assertEquals( 57 expect, 58 actual, 59 () -> String.format("Expected Level.max(%s,%s) but was %s", aa, bb, actual)); 60 } 61 62 static SupplementalDataInfo sdi = null; 63 64 @BeforeAll setUp()65 public static void setUp() throws Exception { 66 sdi = CLDRConfig.getInstance().getSupplementalDataInfo(); 67 } 68 69 /** walk through all currencies looking for modern ones */ modernCurrencies()70 static final Stream<Arguments> modernCurrencies() { 71 final Set<String> all = new TreeSet<String>(); 72 73 sdi.getCurrencyTerritories() 74 .forEach( 75 (t) -> { 76 sdi.getCurrencyDateInfo(t).stream() 77 // TODO: should we use RECENT_HISTORY? CLDR-16316 78 .filter( 79 di -> 80 (di.isLegalTender() 81 && (DateConstants.NOW.compareTo( 82 di.getStart()) 83 >= 0) 84 && (DateConstants.NOW.compareTo( 85 di.getEnd()) 86 <= 0))) 87 .map(di -> di.getCurrency()) 88 .forEach(c -> all.add(c)); 89 }); 90 return all.stream().map(c -> arguments(c)); 91 } 92 93 @ParameterizedTest() 94 @MethodSource("modernCurrencies") testModernCurrencies(final String code)95 public void testModernCurrencies(final String code) { 96 Level l = 97 sdi.getCoverageLevel( 98 String.format( 99 "//ldml/numbers/currencies/currency[@type=\"%s\"]/symbol", code), 100 "und"); 101 final Level expect = Level.MODERN; 102 assumeFalse( 103 code.equals("ZWL") && CLDRFile.GEN_VERSION.equals("46"), 104 "Skipping ZWL for CLDR 46"); 105 assumeFalse( 106 code.equals("ZWG") && CLDRFile.GEN_VERSION.equals("46"), 107 "Skipping ZWG for CLDR 46"); 108 assertTrue( 109 expect.isAtLeast(l), 110 () -> 111 String.format( 112 "Coverage for modern currency %s: %s, expected ≤ %s", 113 code, l, expect)); 114 } 115 116 @Test TestMath()117 public void TestMath() { 118 assertTrue(Level.MODERN.isAbove(Level.MODERATE)); 119 assertFalse(Level.BASIC.isAtLeast(Level.MODERN)); 120 assertTrue(Level.MODERN.isAtLeast(Level.BASIC)); 121 } 122 } 123