Skip to content

Commit

Permalink
order of feature collections should not matter
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiedentop committed Feb 26, 2024
1 parent 6bbfe12 commit ce2617e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/src/turf_equality_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ class Equality {
(g2 as FeatureCollection).features.length) {
return false;
}
for (var i = 0; i < g1.features.length; i++) {
if (!compare(g1.features[i], g2.features[i])) {
for (final g1Feature in g1.features) {
final hasMatch = g2.features.any(
(g2Feature) => compare(g1Feature, g2Feature),
);
if (!hasMatch) {
return false;
}
}
Expand Down
30 changes: 30 additions & 0 deletions test/geojson_equality_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,36 @@ void main() {
true,
);
});

test('order does not matter', () {
expect(
eq.compare(
FeatureCollection(features: [
Feature(id: '1'),
Feature(id: '2'),
]),
FeatureCollection(features: [
Feature(id: '2'),
Feature(id: '1'),
]),
),
true,
);
});

test('different ids affect equality', () {
expect(
eq.compare(
FeatureCollection(features: [
Feature(id: '1'),
]),
FeatureCollection(features: [
Feature(id: '2'),
]),
),
false,
);
});
});

group(
Expand Down

0 comments on commit ce2617e

Please sign in to comment.