Skip to content

Commit

Permalink
test(sorting-service): test sort function with non-empty onTop attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
JoachimFavre committed Apr 30, 2024
1 parent a99fca3 commit 5f86966
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/services/sorting/post_sorting_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,49 @@ void main() {
});
}
});

group("Nonempty onTop attribute", () {
final positionsToPutOnTop =
GeoPointGenerator.generatePositions(userPosition0, 5, 0);
final postsToPutOnTop =
postGenerator.generatePostsAtDifferentLocations(positionsToPutOnTop);
final existingPostsToPutOnTop = postsToPutOnTop.take(3).toList();

for (final option in PostSortOption.values) {
test("Correct sort on option ${option.name}", () {
final allPosts = posts + existingPostsToPutOnTop;
allPosts.shuffle();

final sorted = sortingService.sort(
allPosts,
option,
userPosition0,
putOnTop: postsToPutOnTop.toSet(),
);

// Test for the global structure
expect(sorted, unorderedEquals(allPosts));
final top = sorted.take(existingPostsToPutOnTop.length);
expect(
top,
unorderedEquals(existingPostsToPutOnTop),
);
final bottom = sorted.skip(existingPostsToPutOnTop.length);
expect(
bottom,
unorderedEquals(posts),
);

// Also verify the substructure
final scoresTop = top.map(
(post) => option.scoreFunction(post, userPosition0),
);
expectSorted(scoresTop, option.sortIncreasing);
final scoresBottom = bottom.map(
(post) => option.scoreFunction(post, userPosition0),
);
expectSorted(scoresBottom, option.sortIncreasing);
});
}
});
}

0 comments on commit 5f86966

Please sign in to comment.