Skip to content

Commit

Permalink
Merge pull request #44 from skunkteam/branch-name-aggregation-queries…
Browse files Browse the repository at this point in the history
…-fix

refactor: Update aggregation query tests to include known limitation of Rust emulator with floating point numbers.
  • Loading branch information
pavadeli authored Mar 18, 2024
2 parents ab80599 + 020d28f commit 9657433
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions test-suite/tests/2-basic-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,33 +415,36 @@ describe('aggregation queries', () => {
test('sum', async () => {
const sumArea = fs.exported.AggregateField.sum('area');
await expect(getAggregate(allCities.aggregate({ sumArea }))).resolves.toEqual({
sumArea: 308.4,
// Known current limitation of the Rust emulator, depending of the order of the aggregation we
// either get the first or the second number (you know, floating point).
sumArea: expect.toBeWithin(308.4, 308.40000000000003),
});

await expect(getAggregate(biggerCities.aggregate({ sumArea }))).resolves.toEqual({
sumArea: 129.97,
});
});

fs.notImplementedInRust ||
test('all together now', async () => {
const fields = {
count: fs.exported.AggregateField.count(),
sumArea: fs.exported.AggregateField.sum('area'),
averagePopulation: fs.exported.AggregateField.average('population'),
};
await expect(getAggregate(allCities.aggregate(fields))).resolves.toEqual({
count: 4,
sumArea: 308.4,
averagePopulation: 62_499,
});
test('all together now', async () => {
const fields = {
count: fs.exported.AggregateField.count(),
sumArea: fs.exported.AggregateField.sum('area'),
averagePopulation: fs.exported.AggregateField.average('population'),
};
await expect(getAggregate(allCities.aggregate(fields))).resolves.toEqual({
count: 4,
// Known current limitation of the Rust emulator, depending of the order of the aggregation we
// either get the first or the second number (you know, floating point).
sumArea: expect.toBeWithin(308.4, 308.40000000000003),
averagePopulation: 62_499,
});

await expect(getAggregate(biggerCities.aggregate(fields))).resolves.toEqual({
count: 2,
sumArea: 129.97,
averagePopulation: 90_150,
});
await expect(getAggregate(biggerCities.aggregate(fields))).resolves.toEqual({
count: 2,
sumArea: 129.97,
averagePopulation: 90_150,
});
});

async function getAggregate(
aggregate: FirebaseFirestore.AggregateQuery<FirebaseFirestore.AggregateSpec, unknown, FirebaseFirestore.DocumentData>,
Expand Down

0 comments on commit 9657433

Please sign in to comment.