Eliminate StupidHashString Using a LockFreeRegistry with capacity 1 should have the same effect.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/2bff7818 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/2bff7818 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/2bff7818 Branch: refs/heads/master Commit: 2bff78180371063549cabe3dbf1a4b04d7b31bd6 Parents: 603c261 Author: Nick Wellnhofer <[email protected]> Authored: Tue May 12 19:04:39 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Tue May 12 19:57:45 2015 +0200 ---------------------------------------------------------------------- .../core/Clownfish/Test/TestLockFreeRegistry.c | 37 +++++++------------- .../Clownfish/Test/TestLockFreeRegistry.cfh | 11 ------ 2 files changed, 12 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2bff7818/runtime/core/Clownfish/Test/TestLockFreeRegistry.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestLockFreeRegistry.c b/runtime/core/Clownfish/Test/TestLockFreeRegistry.c index 8f41f33..b030984 100644 --- a/runtime/core/Clownfish/Test/TestLockFreeRegistry.c +++ b/runtime/core/Clownfish/Test/TestLockFreeRegistry.c @@ -22,6 +22,7 @@ #include "Clownfish/Test/TestLockFreeRegistry.h" #include "Clownfish/LockFreeRegistry.h" +#include "Clownfish/String.h" #include "Clownfish/Test.h" #include "Clownfish/TestHarness/TestBatchRunner.h" #include "Clownfish/Class.h" @@ -31,42 +32,28 @@ TestLFReg_new() { return (TestLockFreeRegistry*)Class_Make_Obj(TESTLOCKFREEREGISTRY); } -StupidHashString* -StupidHashString_new(const char *text) { - StupidHashString *self - = (StupidHashString*)Class_Make_Obj(STUPIDHASHSTRING); - return (StupidHashString*)Str_init_from_trusted_utf8((String*)self, text, - strlen(text)); -} - -size_t -StupidHashString_Hash_Sum_IMP(StupidHashString *self) { - UNUSED_VAR(self); - return 1; -} - static void test_all(TestBatchRunner *runner) { - LockFreeRegistry *registry = LFReg_new(10); - StupidHashString *foo = StupidHashString_new("foo"); - StupidHashString *bar = StupidHashString_new("bar"); - StupidHashString *baz = StupidHashString_new("baz"); - StupidHashString *foo_dupe = StupidHashString_new("foo"); + LockFreeRegistry *registry = LFReg_new(1); + String *foo = Str_newf("foo"); + String *bar = Str_newf("bar"); + String *baz = Str_newf("baz"); + String *foo_dupe = Str_newf("foo"); - TEST_TRUE(runner, LFReg_register(registry, (String*)foo, (Obj*)foo), + TEST_TRUE(runner, LFReg_register(registry, foo, (Obj*)foo), "Register() returns true on success"); TEST_FALSE(runner, - LFReg_register(registry, (String*)foo_dupe, (Obj*)foo_dupe), + LFReg_register(registry, foo_dupe, (Obj*)foo_dupe), "Can't Register() keys that test equal"); - TEST_TRUE(runner, LFReg_register(registry, (String*)bar, (Obj*)bar), + TEST_TRUE(runner, LFReg_register(registry, bar, (Obj*)bar), "Register() key with the same Hash_Sum but that isn't Equal"); - TEST_TRUE(runner, LFReg_fetch(registry, (String*)foo_dupe) == (Obj*)foo, + TEST_TRUE(runner, LFReg_fetch(registry, foo_dupe) == (Obj*)foo, "Fetch()"); - TEST_TRUE(runner, LFReg_fetch(registry, (String*)bar) == (Obj*)bar, + TEST_TRUE(runner, LFReg_fetch(registry, bar) == (Obj*)bar, "Fetch() again"); - TEST_TRUE(runner, LFReg_fetch(registry, (String*)baz) == NULL, + TEST_TRUE(runner, LFReg_fetch(registry, baz) == NULL, "Fetch() non-existent key returns NULL"); DECREF(foo_dupe); http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/2bff7818/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh b/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh index c2cca6e..784f745 100644 --- a/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh +++ b/runtime/core/Clownfish/Test/TestLockFreeRegistry.cfh @@ -26,15 +26,4 @@ class Clownfish::Test::TestLockFreeRegistry nickname TestLFReg Run(TestLockFreeRegistry *self, TestBatchRunner *runner); } -/** Private test-only class for stressing LockFreeRegistry. - */ -class Clownfish::Test::StupidHashString inherits Clownfish::String { - inert incremented StupidHashString* - new(const char *text); - - /** Always returns 1, guaranteeing collisions. */ - size_t - Hash_Sum(StupidHashString *self); -} -
