ICU-114 Addional tests

X-SVN-Rev: 1011
This commit is contained in:
Madhu K 2000-03-28 23:51:25 +00:00
parent 47e7f6a816
commit 0ebfa05d46
3 changed files with 221 additions and 27 deletions

View File

@ -1,11 +1,18 @@
/******************************************************************** /*
* COPYRIGHT: *****************************************************************************************
* Copyright (c) 2000, International Business Machines Corporation and * *
* others. All Rights Reserved. * COPYRIGHT: *
********************************************************************/ * (C) Copyright International Business Machines Corporation, 2000 *
* Licensed Material - Program-Property of IBM - All Rights Reserved. *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*****************************************************************************************
*/
/*********************************************************************** /***********************************************************************
* Date Name Description * Date Name Description
* 01/03/2000 Madhu Creation. * 01/03/2000 Madhu Creation.
* 03/2000 Madhu Added additional tests
***********************************************************************/ ***********************************************************************/
/** /**
* IntlTestTransliterator is the medium level test class for Transliterator * IntlTestTransliterator is the medium level test class for Transliterator
@ -15,6 +22,12 @@
#include "ittrans.h" #include "ittrans.h"
#include "transtst.h" #include "transtst.h"
#include "transapi.h" #include "transapi.h"
#include "cpdtrtst.h"
#include "unhxtrts.h"
#include "hxuntrts.h"
#include "jahatrts.h"
#include "hajatrts.h"
#include "ufltlgts.h"
void IntlTestTransliterator::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par ) void IntlTestTransliterator::runIndexedTest( int32_t index, bool_t exec, char* &name, char* par )
{ {
@ -37,6 +50,55 @@ void IntlTestTransliterator::runIndexedTest( int32_t index, bool_t exec, char* &
callTest( test, par ); callTest( test, par );
} }
break; break;
case 2:
name = "CompoundTransliteratorTest";
if (exec) {
logln("CompoundTransliteratorTest---"); logln("");
CompoundTransliteratorTest test;
callTest( test, par );
}
break;
case 3:
name = "UniToHexTransliteratorTest";
if (exec) {
logln("UnicodeToHexadecimalTransliteratorTest---"); logln("");
UniToHexTransliteratorTest test;
callTest( test, par );
}
break;
case 4:
name = "HexToUniTransliteratorTest";
if (exec) {
logln("HexadecimalToUnicodeTransliteratorTest---"); logln("");
HexToUniTransliteratorTest test;
callTest( test, par );
}
break;
case 5:
name = "JamoToHangTransliteratorTest";
if (exec) {
logln("JamoToHangulTransliteratorTest---"); logln("");
JamoToHangTransliteratorTest test;
callTest( test, par );
}
break;
case 6:
name = "HangToJamoTransliteratorTest";
if (exec) {
logln("HangulToJamoTransliteratorTest---"); logln("");
HangToJamoTransliteratorTest test;
callTest( test, par );
}
break;
case 7:
name = "UnicodeFilterLogicTest";
if (exec) {
logln("UnicodeFilterLogicTest---"); logln("");
UnicodeFilterLogicTest test;
callTest( test, par );
}
break;
default: name=""; break; default: name=""; break;
} }

View File

@ -1,10 +1,10 @@
/* /*
********************************************************************** **********************************************************************
* Copyright (C) 1999, International Business Machines * Copyright (C) 1999 Alan Liu and others. All rights reserved.
* Corporation and others. All Rights Reserved.
********************************************************************** **********************************************************************
* Date Name Description * Date Name Description
* 10/20/99 alan Creation. * 10/20/99 alan Creation.
* 03/22/2000 Madhu Added additional tests
********************************************************************** **********************************************************************
*/ */
@ -29,7 +29,8 @@ UnicodeSetTest::runIndexedTest(int32_t index, bool_t exec,
CASE(0,TestPatterns) CASE(0,TestPatterns)
CASE(1,TestAddRemove) CASE(1,TestAddRemove)
CASE(2,TestCategories) CASE(2,TestCategories)
default: name = ""; break; CASE(3,TestCloneEqualHash)
default: name = ""; break;
} }
} }
@ -46,7 +47,7 @@ UnicodeSetTest::TestPatterns(void) {
// Throw in a test of complement // Throw in a test of complement
set.complement(); set.complement();
UnicodeString exp; UnicodeString exp;
exp.append((UChar)0x0000).append(UNICODE_STRING("aeeoouu", 7)).append(0x7b).append((UChar)0xFFFF); exp.append((UChar)0x0000).append("aeeoouu").append((UChar)('z'+1)).append((UChar)0xFFFF);
expectPairs(set, exp); expectPairs(set, exp);
} }
@ -61,28 +62,111 @@ UnicodeSetTest::TestCategories(void) {
expectContainment(set, pat, "ABC", "abc"); expectContainment(set, pat, "ABC", "abc");
} }
} }
void
UnicodeSetTest::TestCloneEqualHash(void) {
UErrorCode status = U_ZERO_ERROR;
int8_t category=Unicode::LOWERCASE_LETTER;
UnicodeSet *set1=new UnicodeSet(category, status); // :Li: Letter, lowercase
if (U_FAILURE(status)){
errln((UnicodeString)"FAIL: Can't construst set with cateegory->Ll");
return;
}
category=Unicode::DECIMAL_DIGIT_NUMBER;
UnicodeSet *set2=new UnicodeSet(category, status); //Number, Decimal digit
if (U_FAILURE(status)){
errln((UnicodeString)"FAIL: Can't construct set with cateegory->Nd");
return;
}
logln("Testing copy construction");
UnicodeSet *set1copy=new UnicodeSet(*set1);
if(*set1 != *set1copy || *set1 == *set2 ||
set1->getPairs() != set1copy->getPairs() ||
set1->hashCode() != set1copy->hashCode()){
errln("FAIL : Error in copy construction");
return;
}
logln("Testing =operator");
UnicodeSet set1equal=*set1;
UnicodeSet set2equal=*set2;
if(set1equal != *set1 || set1equal != *set1copy || set2equal != *set2 ||
set2equal == *set1 || set2equal == *set1copy || set2equal == set1equal){
errln("FAIL: Error in =operator");
}
logln("Testing clone()");
UnicodeSet *set1clone=(UnicodeSet*)set1->clone();
UnicodeSet *set2clone=(UnicodeSet*)set2->clone();
if(*set1clone != *set1 || *set1clone != *set1copy || *set1clone != set1equal ||
*set2clone != *set2 || *set2clone == *set1copy || *set2clone != set2equal ||
*set2clone == *set1 || *set2clone == set1equal || *set2clone == *set1clone){
errln("FAIL: Error in clone");
}
logln("Testing hashcode");
if(set1->hashCode() != set1equal.hashCode() || set1->hashCode() != set1clone->hashCode() ||
set2->hashCode() != set2equal.hashCode() || set2->hashCode() != set2clone->hashCode() ||
set1copy->hashCode() != set1equal.hashCode() || set1copy->hashCode() != set1clone->hashCode() ||
set1->hashCode() == set2->hashCode() || set1copy->hashCode() == set2->hashCode() ||
set2->hashCode() == set1clone->hashCode() || set2->hashCode() == set1equal.hashCode() ){
errln("FAIL: Error in hashCode()");
}
delete set1;
delete set1copy;
delete set2;
}
void void
UnicodeSetTest::TestAddRemove(void) { UnicodeSetTest::TestAddRemove(void) {
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
UnicodeSet set; // Construct empty set UnicodeSet set; // Construct empty set
set.add(0x61, 0x7a); doAssert(set.isEmpty() == TRUE, "set should be empty");
doAssert(set.size() == 0, "size should be 0");
set.add('a', 'z');
expectPairs(set, "az"); expectPairs(set, "az");
set.remove(0x6d, 0x70); doAssert(set.isEmpty() == FALSE, "set should not be empty");
expectPairs(set, "alqz"); doAssert(set.size() != 0, "size should not be equal to 0");
set.remove(0x65, 0x67); doAssert(set.size() == 26, "size should be equal to 26");
set.remove('m', 'p');
expectPairs(set, "alqz");
doAssert(set.size() == 22, "size should be equal to 22");
set.remove('e', 'g');
expectPairs(set, "adhlqz"); expectPairs(set, "adhlqz");
set.remove(0x64, 0x69); doAssert(set.size() == 19, "size should be equal to 19");
set.remove('d', 'i');
expectPairs(set, "acjlqz"); expectPairs(set, "acjlqz");
set.remove(0x63, 0x72); doAssert(set.size() == 16, "size should be equal to 16");
set.remove('c', 'r');
expectPairs(set, "absz"); expectPairs(set, "absz");
set.add(0x66, 0x71); doAssert(set.size() == 10, "size should be equal to 10");
set.add('f', 'q');
expectPairs(set, "abfqsz"); expectPairs(set, "abfqsz");
set.remove(0x61, 0x67); doAssert(set.size() == 22, "size should be equal to 22");
set.remove('a', 'g');
expectPairs(set, "hqsz"); expectPairs(set, "hqsz");
set.remove(0x61, 0x7a); set.remove('a', 'z');
expectPairs(set, ""); expectPairs(set, "");
doAssert(set.isEmpty() == TRUE, "set should be empty");
doAssert(set.size() == 0, "size should be 0");
set.add('a');
doAssert(set.isEmpty() == FALSE, "set should not be empty");
doAssert(set.size() == 1, "size should not be equal to 1");
set.add('b');
set.add('c');
expectPairs(set, "ac");
doAssert(set.size() == 3, "size should not be equal to 3");
set.add('p');
set.add('q');
expectPairs(set, "acpq");
doAssert(set.size() == 5, "size should not be equal to 5");
set.clear();
expectPairs(set, "");
doAssert(set.isEmpty() == TRUE, "set should be empty");
doAssert(set.size() == 0, "size should be 0");
// Try removing an entire set from another set // Try removing an entire set from another set
expectPattern(set, "[c-x]", "cx"); expectPattern(set, "[c-x]", "cx");
@ -96,14 +180,40 @@ UnicodeSetTest::TestAddRemove(void) {
expectPattern(set2, "[hitoshinamekatajamesanderson]", "aadehkmort"); expectPattern(set2, "[hitoshinamekatajamesanderson]", "aadehkmort");
set.addAll(set2); set.addAll(set2);
expectPairs(set, "aacehort"); expectPairs(set, "aacehort");
doAssert(set.containsAll(set2) == TRUE, "set should contain all the elements in set2");
// Try retaining an set of elements contained in another set (intersection)
UnicodeSet set3;
expectPattern(set3, "[a-c]", "ac");
doAssert(set.containsAll(set3) == FALSE, "set doesn't contain all the elements in set3");
set3.remove('b');
expectPairs(set3, "aacc");
doAssert(set.containsAll(set3) == TRUE, "set should contain all the elements in set3");
set.retainAll(set3);
expectPairs(set, "aacc");
doAssert(set.size() == set3.size(), "set.size() should be set3.size()");
doAssert(set.containsAll(set3) == TRUE, "set should contain all the elements in set3");
set.clear();
doAssert(set.size() != set3.size(), "set.size() != set3.size()");
// Test commutativity // Test commutativity
expectPattern(set, "[hitoshinamekatajamesanderson]", "aadehkmort"); expectPattern(set, "[hitoshinamekatajamesanderson]", "aadehkmort");
expectPattern(set2, "[jackiemclean]", "aacceein"); expectPattern(set2, "[jackiemclean]", "aacceein");
set.addAll(set2); set.addAll(set2);
expectPairs(set, "aacehort"); expectPairs(set, "aacehort");
} doAssert(set.containsAll(set2) == TRUE, "set should contain all the elements in set2");
}
void
UnicodeSetTest::doAssert(bool_t condition, const char *message)
{
if (!condition) {
errln(UnicodeString("ERROR : ") + message);
}
}
void void
UnicodeSetTest::expectContainment(const UnicodeSet& set, UnicodeSetTest::expectContainment(const UnicodeSet& set,
const UnicodeString& setName, const UnicodeString& setName,
@ -142,15 +252,15 @@ UnicodeSetTest::expectContainment(const UnicodeSet& set,
void void
UnicodeSetTest::expectPattern(UnicodeSet& set, UnicodeSetTest::expectPattern(UnicodeSet& set,
const UnicodeString& pattern, const UnicodeString& pattern,
const UnicodeString& expectedPairs) { const UnicodeString& expectedPairs){
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
set.applyPattern(pattern, status); set.applyPattern(pattern, status);
if (U_FAILURE(status)) { if (U_FAILURE(status)) {
errln(UnicodeString("FAIL: applyPattern(\"") + pattern + errln(UnicodeString("FAIL: applyPattern(\"") + pattern +
"\") failed"); "\") failed");
return; return;
} else { } else {
if (set.getPairs() != expectedPairs) { if (set.getPairs() != expectedPairs ) {
errln(UnicodeString("FAIL: applyPattern(\"") + pattern + errln(UnicodeString("FAIL: applyPattern(\"") + pattern +
"\") => pairs \"" + "\") => pairs \"" +
escape(set.getPairs()) + "\", expected \"" + escape(set.getPairs()) + "\", expected \"" +
@ -161,6 +271,25 @@ UnicodeSetTest::expectPattern(UnicodeSet& set,
escape(set.getPairs()) + "\""); escape(set.getPairs()) + "\"");
} }
} }
// the result of calling set.toPattern(), which is the string representation of
// this set(set), is passed to a UnicodeSet constructor, and tested that it
// will produce another set that is equal to this one.
UnicodeString temppattern;
set.toPattern(temppattern);
UnicodeSet *tempset=new UnicodeSet(temppattern, status);
if (U_FAILURE(status)) {
errln(UnicodeString("FAIL: Construction with the pattern derived from toPattern() failed"));
return;
}
if(*tempset != set || tempset->getPairs() != set.getPairs()){
errln(UnicodeString("FAIL: "+ pattern + "!=>" + temppattern + ". Pairs \""+ escape(tempset->getPairs()) + "\" expected->\"" +
escape(set.getPairs()) + "\""));
} else{
logln(UnicodeString("OK: "+ pattern + "==>" + temppattern + ". Pairs \"" + escape(tempset->getPairs()) + "\""));
}
delete tempset;
} }
void void
@ -180,10 +309,10 @@ UnicodeSetTest::escape(const UnicodeString& s) {
for (int32_t i=0; i<s.length(); ++i) for (int32_t i=0; i<s.length(); ++i)
{ {
UChar c = s[(UTextOffset)i]; UChar c = s[(UTextOffset)i];
if (0x20 <= c && c <= (UChar)0x7F) { if (' ' <= c && c <= (UChar)0x7F) {
buf += c; buf += c;
} else { } else {
buf += 0x5c; buf += 'u'; buf += '\\'; buf += 'u';
buf += toHexString((c & 0xF000) >> 12); buf += toHexString((c & 0xF000) >> 12);
buf += toHexString((c & 0x0F00) >> 8); buf += toHexString((c & 0x0F00) >> 8);
buf += toHexString((c & 0x00F0) >> 4); buf += toHexString((c & 0x00F0) >> 4);

View File

@ -1,10 +1,10 @@
/* /*
********************************************************************** **********************************************************************
* Copyright (C) 1999, International Business Machines * Copyright (C) 1999 Alan Liu and others. All rights reserved.
* Corporation and others. All Rights Reserved.
********************************************************************** **********************************************************************
* Date Name Description * Date Name Description
* 10/20/99 alan Creation. * 10/20/99 alan Creation.
* 03/22/2000 Madhu Added additional tests
********************************************************************** **********************************************************************
*/ */
@ -29,6 +29,9 @@ private:
void TestPatterns(void); void TestPatterns(void);
void TestCategories(void); void TestCategories(void);
void TestAddRemove(void); void TestAddRemove(void);
void TestCloneEqualHash(void);
void doAssert(bool_t, const char*);
void expectContainment(const UnicodeSet& set, void expectContainment(const UnicodeSet& set,
const UnicodeString& setName, const UnicodeString& setName,