From 3d664ec1edbe843bf116bbd0c73773c6ba929411 Mon Sep 17 00:00:00 2001 From: Alan Liu Date: Tue, 26 Oct 1999 17:16:13 +0000 Subject: [PATCH] ICU-34 Expanded test. X-SVN-Rev: 122 --- icu4c/source/test/intltest/usettest.cpp | 136 +++++++++++++++--------- icu4c/source/test/intltest/usettest.h | 18 +++- 2 files changed, 103 insertions(+), 51 deletions(-) diff --git a/icu4c/source/test/intltest/usettest.cpp b/icu4c/source/test/intltest/usettest.cpp index c232efdade2..2edef19caa6 100644 --- a/icu4c/source/test/intltest/usettest.cpp +++ b/icu4c/source/test/intltest/usettest.cpp @@ -1,3 +1,12 @@ +/* +********************************************************************** +* Copyright (C) 1999 Alan Liu and others. All rights reserved. +********************************************************************** +* Date Name Description +* 10/20/99 alan Creation. +********************************************************************** +*/ + #include "utypes.h" #include "usettest.h" #include "uniset.h" @@ -16,78 +25,106 @@ UnicodeSetTest::runIndexedTest(int32_t index, bool_t exec, char* &name, char* par) { // if (exec) logln((UnicodeString)"TestSuite UnicodeSetTest"); switch (index) { - CASE(0,Test1) + CASE(0,TestPatterns) + CASE(1,TestAddRemove) default: name = ""; break; } } void -UnicodeSetTest::Test1() { +UnicodeSetTest::TestPatterns() { + UnicodeSet set; + expectPattern(set, "[[a-m]&[d-z]&[k-y]]", "km"); + expectPattern(set, "[[a-z]-[m-y]-[d-r]]", "aczz"); + expectPattern(set, "[a\\-z]", "--aazz"); + expectPattern(set, "[-az]", "--aazz"); + expectPattern(set, "[az-]", "--aazz"); + expectPattern(set, "[[[a-z]-[aeiou]i]]", "bdfnptvz"); + + // Throw in a test of complement + set.complement(); + UnicodeString exp; + exp.append((UChar)0x0000).append("aeeoouu").append((UChar)('z'+1)).append((UChar)0xFFFF); + expectPairs(set, exp); +} + +void +UnicodeSetTest::TestAddRemove() { UErrorCode status = U_ZERO_ERROR; UnicodeSet set; // Construct empty set set.add('a', 'z'); - expect(set, "az"); + expectPairs(set, "az"); set.remove('m', 'p'); - expect(set, "alqz"); + expectPairs(set, "alqz"); set.remove('e', 'g'); - expect(set, "adhlqz"); + expectPairs(set, "adhlqz"); set.remove('d', 'i'); - expect(set, "acjlqz"); + expectPairs(set, "acjlqz"); set.remove('c', 'r'); - expect(set, "absz"); + expectPairs(set, "absz"); set.add('f', 'q'); - expect(set, "abfqsz"); + expectPairs(set, "abfqsz"); set.remove('a', 'g'); - expect(set, "hqsz"); + expectPairs(set, "hqsz"); set.remove('a', 'z'); - expect(set, ""); + expectPairs(set, ""); - set.applyPattern("[[a-m]&[d-z]&[k-y]]", status); - if (U_FAILURE(status)) { - errln("FAIL: Unexpected pattern parse failure"); - return; - } - expect(set, "km"); + // Try removing an entire set from another set + expectPattern(set, "[c-x]", "cx"); + UnicodeSet set2; + expectPattern(set2, "[f-ky-za-bc[vw]]", "acfkvwyz"); + set.removeAll(set2); + expectPairs(set, "deluxx"); - set.applyPattern("[[a-z]-[m-y]-[d-r]]", status); - if (U_FAILURE(status)) { - errln("FAIL: Unexpected pattern parse failure"); - return; - } - expect(set, "aczz"); + // Try adding an entire set to another set + expectPattern(set, "[jackiemclean]", "aacceein"); + expectPattern(set2, "[hitoshinamekatajamesanderson]", "aadehkmort"); + set.addAll(set2); + expectPairs(set, "aacehort"); - set.applyPattern("[a\\-z]", status); - if (U_FAILURE(status)) { - errln("FAIL: Unexpected pattern parse failure"); - return; - } - expect(set, "--aazz"); - set.applyPattern("[-az]", status); - if (U_FAILURE(status)) { - errln("FAIL: Unexpected pattern parse failure"); - return; - } - expect(set, "--aazz"); - set.applyPattern("[az-]", status); - if (U_FAILURE(status)) { - errln("FAIL: Unexpected pattern parse failure"); - return; - } - expect(set, "--aazz"); + // Test commutativity + expectPattern(set, "[hitoshinamekatajamesanderson]", "aadehkmort"); + expectPattern(set2, "[jackiemclean]", "aacceein"); + set.addAll(set2); + expectPairs(set, "aacehort"); } void -UnicodeSetTest::expect(const UnicodeSet& set, const UnicodeString& expectedPairs) { - if (set.getPairs() != expectedPairs) { - errln(UnicodeString("FAIL: Expected pair list \"") + - escape(expectedPairs) + "\", got \"" + - escape(set.getPairs()) + '"'); +UnicodeSetTest::expectPattern(UnicodeSet& set, + const UnicodeString& pattern, + const UnicodeString& expectedPairs) { + UErrorCode status = U_ZERO_ERROR; + set.applyPattern(pattern, status); + if (U_FAILURE(status)) { + errln(UnicodeString("FAIL: applyPattern(\"") + pattern + + "\") failed"); + return; + } else { + if (set.getPairs() != expectedPairs) { + errln(UnicodeString("FAIL: applyPattern(\"") + pattern + + "\") => pairs \"" + + escape(set.getPairs()) + "\", expected \"" + + escape(expectedPairs) + "\""); + } else { + logln(UnicodeString("Ok: applyPattern(\"") + pattern + + "\") => pairs \"" + + escape(set.getPairs()) + "\""); + } } } -static char toHexString(int32_t i) { return i + (i < 10 ? '0' : ('A' - 10)); } +void +UnicodeSetTest::expectPairs(const UnicodeSet& set, const UnicodeString& expectedPairs) { + if (set.getPairs() != expectedPairs) { + errln(UnicodeString("FAIL: Expected pair list \"") + + escape(expectedPairs) + "\", got \"" + + escape(set.getPairs()) + "\""); + } +} + +static UChar toHexString(int32_t i) { return i + (i < 10 ? '0' : ('A' - 10)); } UnicodeString UnicodeSetTest::escape(const UnicodeString& s) { @@ -95,9 +132,10 @@ UnicodeSetTest::escape(const UnicodeString& s) { for (int32_t i=0; i> 12); buf += toHexString((c & 0x0F00) >> 8); buf += toHexString((c & 0x00F0) >> 4); diff --git a/icu4c/source/test/intltest/usettest.h b/icu4c/source/test/intltest/usettest.h index f7ab63a69f2..dc2f528c35d 100644 --- a/icu4c/source/test/intltest/usettest.h +++ b/icu4c/source/test/intltest/usettest.h @@ -1,3 +1,12 @@ +/* +********************************************************************** +* Copyright (C) 1999 Alan Liu and others. All rights reserved. +********************************************************************** +* Date Name Description +* 10/20/99 alan Creation. +********************************************************************** +*/ + #ifndef _TESTUNISET #define _TESTUNISET @@ -16,9 +25,14 @@ class UnicodeSetTest: public IntlTest { private: - void Test1(); + void TestPatterns(); + void TestAddRemove(); - void expect(const UnicodeSet& set, const UnicodeString& expectedPairs); + void expectPattern(UnicodeSet& set, + const UnicodeString& pattern, + const UnicodeString& expectedPairs); + void expectPairs(const UnicodeSet& set, + const UnicodeString& expectedPairs); static UnicodeString escape(const UnicodeString& s); };