diff options
author | Tobia Tesan | 2013-04-24 00:09:10 +0200 |
---|---|---|
committer | Tobia Tesan | 2013-07-10 13:22:01 +0200 |
commit | e9406fad246efe975ce63dab207be76edf3e0998 (patch) | |
tree | 006b8c75fb99d07dc5d5a90fee6ca24c2085d617 /test/common | |
parent | 6245a68632875fb4a58eb5ca9fe2e321c171127b (diff) | |
download | scummvm-rg350-e9406fad246efe975ce63dab207be76edf3e0998.tar.gz scummvm-rg350-e9406fad246efe975ce63dab207be76edf3e0998.tar.bz2 scummvm-rg350-e9406fad246efe975ce63dab207be76edf3e0998.zip |
TEST: removed fixed hashes in test/common/hash-str.h
The hash function does not necessarily have to conform to one specific algorithm as long as equals/differs is respected.
Diffstat (limited to 'test/common')
-rw-r--r-- | test/common/hash-str.h | 59 | ||||
-rw-r--r-- | test/common/util.h | 46 |
2 files changed, 43 insertions, 62 deletions
diff --git a/test/common/hash-str.h b/test/common/hash-str.h index b106f66eda..9eadea5755 100644 --- a/test/common/hash-str.h +++ b/test/common/hash-str.h @@ -26,8 +26,8 @@ class HashStrTestSuite : public CxxTest::TestSuite { const Common::String spaced("test "); const Common::String doublespaced("test "); const Common::String tabbed("test\t"); - const Common::String plus128("t\xE5est"); - // 'e'+128 = 0xE5 + const Common::String plus128("t\345est"); + // 'e'+128 = 0xE5 = 0o345 Common::CaseSensitiveString_EqualTo css_et; TS_ASSERT_EQUALS(css_et(lower, mixed), false); @@ -56,7 +56,7 @@ class HashStrTestSuite : public CxxTest::TestSuite { const Common::String mixedspaced("tESt "); const Common::String doublespaced("test "); const Common::String tabbed("test\t"); - const Common::String plus128("t\xE5est"); + const Common::String plus128("t\345est"); Common::IgnoreCase_EqualTo ic_et; TS_ASSERT_EQUALS(ic_et(lower, mixed), true); @@ -78,79 +78,64 @@ class HashStrTestSuite : public CxxTest::TestSuite { // Here we compute string hashes for different // strings and see that the functor is case sensitive // and does not ignore spaces. - // The hashes come from Python's hash() function. const Common::String lower("test"); - const uint lower_hash = 1308370872; const Common::String lower1("test"); const Common::String mixed("tESt"); - const uint mixed_hash = -1217273608; const Common::String spaced("test "); - const uint spaced_hash = -1086267887; const Common::String mixedspaced("tESt "); const Common::String doublespaced("test "); const Common::String tabbed("test\t"); - const uint tabbed_hash = -1086267848; Common::CaseSensitiveString_Hash css_h; - TS_ASSERT_EQUALS(css_h(lower), lower_hash); - TS_ASSERT_EQUALS(css_h(mixed), mixed_hash); - TS_ASSERT_EQUALS(css_h(spaced), spaced_hash); - TS_ASSERT_EQUALS(css_h(tabbed), tabbed_hash); + TS_ASSERT_EQUALS(css_h(lower), css_h(lower1)); + TS_ASSERT_DIFFERS(css_h(mixed), css_h(lower)); + TS_ASSERT_DIFFERS(css_h(spaced), css_h(lower)); + TS_ASSERT_DIFFERS(css_h(tabbed), css_h(spaced)); TS_ASSERT_DIFFERS(css_h(spaced), css_h(doublespaced)); } void test_ignore_case_hash() { // Same as test_case_sensitive_string_hash, but case insensitive. const Common::String lower("test"); - const uint lower_hash = 1308370872; const Common::String lower1("test"); const Common::String mixed("tESt"); const Common::String spaced("test "); - const uint spaced_hash = -1086267887; const Common::String mixedspaced("tESt "); const Common::String doublespaced("test "); const Common::String tabbed("test\t"); - const uint tabbed_hash = -1086267848; Common::IgnoreCase_Hash ic_h; - TS_ASSERT_EQUALS(ic_h(lower), lower_hash); - TS_ASSERT_EQUALS(ic_h(mixed), lower_hash); - TS_ASSERT_EQUALS(ic_h(spaced), spaced_hash); - TS_ASSERT_EQUALS(ic_h(tabbed), tabbed_hash); - TS_ASSERT_EQUALS(ic_h(mixedspaced), spaced_hash); + TS_ASSERT_EQUALS(ic_h(lower), ic_h(lower1)); + TS_ASSERT_EQUALS(ic_h(mixed), ic_h(lower)); + TS_ASSERT_EQUALS(ic_h(spaced), ic_h(mixedspaced)); + TS_ASSERT_DIFFERS(ic_h(tabbed), ic_h(lower)); TS_ASSERT_DIFFERS(ic_h(spaced), ic_h(doublespaced)); } - void test_cpp_string_hash () + void test_cpp_string_hash() { // We run the same tests with Hash<String>, // a template specialization of Hash, also a functor. // It is supposed to be case sensitive. - // Again, hashes come from Python's hash(). const Common::String lower("test"); - const uint lower_hash = 1308370872; const Common::String lower1("test"); const Common::String mixed("tESt"); - const uint mixed_hash = -1217273608; const Common::String spaced("test "); - const uint spaced_hash = -1086267887; const Common::String mixedspaced("tESt "); const Common::String doublespaced("test "); const Common::String tabbed("test\t"); - const uint tabbed_hash = -1086267848; Common::Hash<Common::String> h; - TS_ASSERT_EQUALS(h(lower), lower_hash); TS_ASSERT_EQUALS(h(lower), h(lower1)); - TS_ASSERT_EQUALS(h(mixed), mixed_hash); - TS_ASSERT_EQUALS(h(spaced), spaced_hash); - TS_ASSERT_EQUALS(h(tabbed), tabbed_hash); + TS_ASSERT_DIFFERS(h(mixed), h(lower)); + TS_ASSERT_DIFFERS(h(spaced), h(lower)); + TS_ASSERT_DIFFERS(h(tabbed), h(spaced)); TS_ASSERT_DIFFERS(h(spaced), h(doublespaced)); } - void test_c_style_string_hash () + void test_c_style_string_hash() { // Same as test_cpp_string_hash but with Hash<const char*>, // a template specialization of Hash, also a functor, @@ -158,25 +143,21 @@ class HashStrTestSuite : public CxxTest::TestSuite { // It is supposed to be case sensitive. char lower[] = "test"; - const uint lower_hash = 1308370872; // CPython told me so char lower1[] = "test"; char mixed[] = "tESt"; - const uint mixed_hash = -1217273608; char spaced[] = "test "; - const uint spaced_hash = -1086267887; char mixedspaced[] = "tESt "; char doublespaced[] = "test "; char tabbed[] = "test\t"; - const uint tabbed_hash = -1086267848; Common::Hash<const char*> h; - TS_ASSERT_EQUALS(h(lower), lower_hash); TS_ASSERT_EQUALS(h(lower), h(lower1)); - TS_ASSERT_EQUALS(h(mixed), mixed_hash); - TS_ASSERT_EQUALS(h(spaced), spaced_hash); + TS_ASSERT_DIFFERS(h(mixed), h(lower)); + TS_ASSERT_DIFFERS(h(spaced), h(lower)); TS_ASSERT_DIFFERS(h(spaced), h(mixedspaced)); - TS_ASSERT_EQUALS(h(tabbed), tabbed_hash); + TS_ASSERT_DIFFERS(h(tabbed), h(spaced)); TS_ASSERT_DIFFERS(h(spaced), h(doublespaced)); + } diff --git a/test/common/util.h b/test/common/util.h index 57688ff30b..05e6243885 100644 --- a/test/common/util.h +++ b/test/common/util.h @@ -14,13 +14,13 @@ class UtilTestSuite : public CxxTest::TestSuite { bool valasbool; bool success; - Common::String string_1 ("Yes"); - success = Common::parseBool (string_1, valasbool); + Common::String string_1("Yes"); + success = Common::parseBool(string_1, valasbool); TS_ASSERT_EQUALS(success, 1); TS_ASSERT_EQUALS(valasbool, 1); - Common::String string_2 ("nO"); - success = Common::parseBool (string_2, valasbool); + Common::String string_2("nO"); + success = Common::parseBool(string_2, valasbool); TS_ASSERT_EQUALS(success, 1); TS_ASSERT_EQUALS(valasbool, 0); } @@ -33,13 +33,13 @@ class UtilTestSuite : public CxxTest::TestSuite { bool valasbool; bool success; - Common::String string_3 ("tRuE"); - success = Common::parseBool (string_3, valasbool); + Common::String string_3("tRuE"); + success = Common::parseBool(string_3, valasbool); TS_ASSERT_EQUALS(success, 1); TS_ASSERT_EQUALS(valasbool, 1); - Common::String string_4 ("fAlSe"); - success = Common::parseBool (string_4, valasbool); + Common::String string_4("fAlSe"); + success = Common::parseBool(string_4, valasbool); TS_ASSERT_EQUALS(success, 1); TS_ASSERT_EQUALS(valasbool, 0); } @@ -56,12 +56,12 @@ class UtilTestSuite : public CxxTest::TestSuite { bool success; Common::String string_5 ("1"); - success = Common::parseBool (string_5, valasbool); + success = Common::parseBool(string_5, valasbool); TS_ASSERT_EQUALS(success, 1); TS_ASSERT_EQUALS(valasbool, 1); - Common::String string_6 ("0"); - success = Common::parseBool (string_6, valasbool); + Common::String string_6("0"); + success = Common::parseBool(string_6, valasbool); TS_ASSERT_EQUALS(success, 1); TS_ASSERT_EQUALS(valasbool, 0); @@ -74,33 +74,33 @@ class UtilTestSuite : public CxxTest::TestSuite { // Bad cases that should not return success #1: // Random string - Common::String string_1 ("u_f1ght_l1k3_a_c0w"); - success = Common::parseBool (string_1, valasbool); + Common::String string_1("u_f1ght_l1k3_a_c0w"); + success = Common::parseBool(string_1, valasbool); TS_ASSERT_EQUALS(success, 0); // Bad cases that should not return success #2, #3: // The function should NOT accept trailing whitespaces: - Common::String string_2 (" yes"); - success = Common::parseBool (string_2, valasbool); + Common::String string_2(" yes"); + success = Common::parseBool(string_2, valasbool); TS_ASSERT_EQUALS(success, 0); - Common::String string_3 ("yes "); - success = Common::parseBool (string_3, valasbool); + Common::String string_3("yes "); + success = Common::parseBool(string_3, valasbool); TS_ASSERT_EQUALS(success, 0); // While 'a-z'+0x20 must work just fine, // '0-1'+0x20 should NOT. '2' is not good either. - Common::String string_4 ("\x50"); - success = Common::parseBool (string_4, valasbool); + Common::String string_4("\x50"); + success = Common::parseBool(string_4, valasbool); TS_ASSERT_EQUALS(success, 0); - Common::String string_5 ("\x51"); - success = Common::parseBool (string_5, valasbool); + Common::String string_5("\x51"); + success = Common::parseBool(string_5, valasbool); TS_ASSERT_EQUALS(success, 0); - Common::String string_6 ("2"); - success = Common::parseBool (string_6, valasbool); + Common::String string_6("2"); + success = Common::parseBool(string_6, valasbool); TS_ASSERT_EQUALS(success, 0); } |