Skip to content

Commit

Permalink
test(sorting-service): test sort function with empty onTop attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
JoachimFavre committed Apr 30, 2024
1 parent ec25ee3 commit a99fca3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/services/sorting/post_sorting_service_test.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import "package:collection/collection.dart";
import "package:flutter_test/flutter_test.dart";
import "package:geolocator/geolocator.dart";
import "package:proxima/models/database/post/post_firestore.dart";
import "package:proxima/services/sorting/post_sort_option.dart";
import "package:proxima/services/sorting/post_sorting_service.dart";

import "../../mocks/data/firestore_post.dart";
import "../../mocks/data/geopoint.dart";

void expectSorted(Iterable<double> iterable, bool ascending) {
final factor = ascending ? 1 : -1;
expect(iterable.isSorted((a, b) => factor * a.compareTo(b)), true);
}

void main() {
final sortingService = PostSortingService();

final postGenerator = FirestorePostGenerator();
final positions = GeoPointGenerator.generatePositions(userPosition0, 10, 0);
final posts = postGenerator.generatePostsAtDifferentLocations(positions);
Expand Down Expand Up @@ -98,4 +107,23 @@ void main() {
upvoteDifference,
);
});

group("Empty onTop attribute", () {
for (final option in PostSortOption.values) {
test("Correct sort on option ${option.name}", () {
final sorted = sortingService.sort(
posts,
option,
userPosition0,
);

expect(sorted, unorderedEquals(posts));

final scores = sorted.map(
(post) => option.scoreFunction(post, userPosition0),
);
expectSorted(scores, option.sortIncreasing);
});
}
});
}

0 comments on commit a99fca3

Please sign in to comment.