From eb1508a332d871d3cdeeddc38000670ab6793ca2 Mon Sep 17 00:00:00 2001 From: devmil Date: Thu, 28 Jul 2022 08:48:33 +0200 Subject: [PATCH 1/4] uses SplayTreeSet to be independent of the insertion order of a Set for generating hashes --- lib/src/equatable_utils.dart | 7 +++++++ test/equatable_test.dart | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/src/equatable_utils.dart b/lib/src/equatable_utils.dart index 4a18c5b7..d6835b9e 100644 --- a/lib/src/equatable_utils.dart +++ b/lib/src/equatable_utils.dart @@ -1,3 +1,5 @@ +import 'dart:collection'; + import 'package:collection/collection.dart'; import 'package:equatable/equatable.dart'; @@ -46,6 +48,11 @@ int _combine(int hash, dynamic object) { }); return hash; } + if(object is Set) { + // this is needed to have a consistent iteration order so that the produced + // hash is consistent independently of the Set insertion order + object = SplayTreeSet.from(object); + } if (object is Iterable) { for (final value in object) { hash = hash ^ _combine(hash, value); diff --git a/test/equatable_test.dart b/test/equatable_test.dart index 40b326b3..0bffe89c 100644 --- a/test/equatable_test.dart +++ b/test/equatable_test.dart @@ -968,6 +968,17 @@ void main() { expect(instanceA.hashCode == instanceB.hashCode, true); }); + test('should return when Set values are same but in different order', () { + final instanceA = SimpleEquatable>( + Set.from(['A', 'B']), + ); + final instanceB = SimpleEquatable>( + Set.from(['B', 'A']), + ); + expect(instanceA == instanceB, true); + expect(instanceA.hashCode == instanceB.hashCode, true); + }); + test('should return when values are different', () { final instanceA = SimpleEquatable>( Set.from(['A', 'B']), From c12ac2dbe9ce531dc4fe2683d1987496488ec71f Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Wed, 3 Aug 2022 08:39:05 -0500 Subject: [PATCH 2/4] Update lib/src/equatable_utils.dart --- lib/src/equatable_utils.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/equatable_utils.dart b/lib/src/equatable_utils.dart index d6835b9e..e2419c1e 100644 --- a/lib/src/equatable_utils.dart +++ b/lib/src/equatable_utils.dart @@ -48,7 +48,7 @@ int _combine(int hash, dynamic object) { }); return hash; } - if(object is Set) { + if (object is Set) { // this is needed to have a consistent iteration order so that the produced // hash is consistent independently of the Set insertion order object = SplayTreeSet.from(object); From 2e4028015e4f1b99df74b69778693b123eaf71d3 Mon Sep 17 00:00:00 2001 From: devmil Date: Wed, 3 Aug 2022 19:12:13 +0200 Subject: [PATCH 3/4] updates workflow to echo pana output in case score is too low --- .github/workflows/main.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 377f72e5..78381c7c 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -48,4 +48,4 @@ jobs: PANA=$(pana . --no-warning); PANA_SCORE=$(echo $PANA | sed -n "s/.*Points: \([0-9]*\)\/\([0-9]*\)./\1\/\2/p") echo "score: $PANA_SCORE" IFS='/'; read -a SCORE_ARR <<< "$PANA_SCORE"; SCORE=SCORE_ARR[0]; TOTAL=SCORE_ARR[1] - if (( $SCORE < $TOTAL )); then echo "minimum score not met!"; exit 1; fi + if (( $SCORE < $TOTAL )); then echo $PANA; echo "minimum score not met!"; exit 1; fi From 6525cf7cb58c38dfcd5a85c9f19c914a94e9419e Mon Sep 17 00:00:00 2001 From: Michael Lamers Date: Thu, 18 Aug 2022 06:07:33 +0200 Subject: [PATCH 4/4] Check if the given Set is already a SplayTreeSet Co-authored-by: Felix Angelov --- lib/src/equatable_utils.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/equatable_utils.dart b/lib/src/equatable_utils.dart index e2419c1e..e0ae8dd2 100644 --- a/lib/src/equatable_utils.dart +++ b/lib/src/equatable_utils.dart @@ -48,7 +48,7 @@ int _combine(int hash, dynamic object) { }); return hash; } - if (object is Set) { + if (object is Set && object is! SplayTreeSet) { // this is needed to have a consistent iteration order so that the produced // hash is consistent independently of the Set insertion order object = SplayTreeSet.from(object);