diff --git a/include/etl/pearson.h b/include/etl/pearson.h index fffae1d8..2b1d0ab2 100644 --- a/include/etl/pearson.h +++ b/include/etl/pearson.h @@ -93,6 +93,7 @@ namespace etl void reset() { hash.fill(0); + first = true; } //************************************************************************* diff --git a/test/test_pearson.cpp b/test/test_pearson.cpp index 4b5e5609..aa3eea30 100644 --- a/test/test_pearson.cpp +++ b/test/test_pearson.cpp @@ -144,6 +144,25 @@ namespace CHECK(compare == hash); } + //************************************************************************* + TEST(test_pearson_reset) + { + std::string data("123456789"); + + etl::pearson pearson_calculator; + + // Use the calculator, then reset it and reuse it for the same data. + pearson_calculator.add(data.begin(), data.end()); + pearson_calculator.reset(); + pearson_calculator.add(data.begin(), data.end()); + + hash_t compare = Pearson_Compare(data); + hash_t hash = pearson_calculator.value(); + + // A reset calculator must produce the same hash as a fresh one. + CHECK(compare == hash); + } + //************************************************************************* TEST(test_pearson_add_range_endian) {