@@ -35,9 +35,9 @@ def random_splits(s, n, nsplits=2):
3535 yield s [begin :end ]
3636
3737
38- class TestStandalone (unittest .TestCase ):
38+ class TestAtomic (unittest .TestCase ):
3939
40- """test single-line methods """
40+ """test atomic (functional) interface """
4141
4242 def test_string_unicode_64 (self ):
4343 """Empty Python string has same hash value as empty Unicode string
@@ -98,18 +98,10 @@ def test_func_raises_type_error(self):
9898 with self .assertRaises (TypeError ):
9999 func ([])
100100
101- def test_obj_raises_type_error (self ):
102- """Check that hasher objects raise type error"""
103- hasher_classes = [MetroHash64 , MetroHash128 ]
104- for hasher_class in hasher_classes :
105- hasher = hasher_class ()
106- with self .assertRaises (TypeError ):
107- hasher .update ([])
108101
102+ class TestIncremental (unittest .TestCase ):
109103
110- class TestCombiners (unittest .TestCase ):
111-
112- """test combiners"""
104+ """test incremental hashers"""
113105
114106 def test_compose_64 (self ):
115107 """Test various ways to split a string
@@ -154,3 +146,44 @@ def test_compose_128(self):
154146 whole = hasher2 .intdigest ()
155147 msg = "\n data: %s\n whole: %s\n incremental: %s\n " % (pieces , whole , incremental )
156148 self .assertEqual (whole , incremental , msg )
149+
150+ def test_obj_raises_type_error (self ):
151+ """Check that hasher objects raise type error
152+ """
153+ hasher_classes = [MetroHash64 , MetroHash128 ]
154+ for hasher_class in hasher_classes :
155+ hasher = hasher_class ()
156+ with self .assertRaises (TypeError ):
157+ hasher .update ([])
158+
159+ def test_reset_64 (self ):
160+ """test that 64-bit hasher can be reset"""
161+
162+ seed1 = 42
163+ expected1 = metrohash64 ("ab" , seed = seed1 )
164+ hasher = MetroHash64 (seed1 )
165+ hasher .update ("a" )
166+ hasher .update ("b" )
167+ self .assertEqual (hasher .intdigest (), expected1 )
168+
169+ seed2 = 0
170+ hasher .reset (seed = seed2 )
171+ expected2 = metrohash64 ("c" , seed = seed2 )
172+ hasher .update ("c" )
173+ self .assertEqual (hasher .intdigest (), expected2 )
174+
175+ def test_reset_128 (self ):
176+ """test that 128-bit hasher can be reset"""
177+
178+ seed1 = 42
179+ expected1 = metrohash128 ("ab" , seed = seed1 )
180+ hasher = MetroHash128 (seed1 )
181+ hasher .update ("a" )
182+ hasher .update ("b" )
183+ self .assertEqual (hasher .intdigest (), expected1 )
184+
185+ seed2 = 0
186+ hasher .reset (seed = seed2 )
187+ expected2 = metrohash128 ("c" , seed = seed2 )
188+ hasher .update ("c" )
189+ self .assertEqual (hasher .intdigest (), expected2 )
0 commit comments