-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust overlaps check for zones and communities in /company route (#154)
* Adjust overlaps check for zones and communities in /company route * Format * Add test for overlap check in /company route closes #143 * Run unit tests after e2e tests * wip * wip * wip * Rename tests for intersects * Change intersects test * Format * wip
- Loading branch information
1 parent
2472849
commit 7ce13f2
Showing
5 changed files
with
140 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { db } from '$lib/database'; | ||
import { sql } from 'kysely'; | ||
import { describe, expect, it } from 'vitest'; | ||
import { intersects } from '$lib/sqlHelpers'; | ||
|
||
type ZonePair = { | ||
compulsory: number; | ||
community: number; | ||
}; | ||
|
||
describe('intersects test', () => { | ||
const useOldMethod = (zones: ZonePair[]) => { | ||
return zones.map( | ||
async (z) => | ||
(await db | ||
.selectFrom('zone as compulsory_area') | ||
.where('compulsory_area.id', '=', z.compulsory) | ||
.innerJoin( | ||
(eb) => eb.selectFrom('zone').where('id', '=', z.community).selectAll().as('community'), | ||
(join) => join.onTrue() | ||
) | ||
.where(sql<boolean>`ST_Intersects(compulsory_area.area, community.area)`) | ||
.selectAll() | ||
.executeTakeFirst()) != undefined | ||
); | ||
}; | ||
|
||
const useNewMethod = (zones: ZonePair[]) => { | ||
return zones.map(async (z) => await intersects(z.compulsory, z.community)); | ||
}; | ||
|
||
const noOverlaps = [ | ||
{ compulsory: 1, community: 34 }, | ||
{ compulsory: 1, community: 36 }, | ||
{ compulsory: 1, community: 37 }, | ||
{ compulsory: 1, community: 39 }, | ||
{ compulsory: 1, community: 40 }, | ||
{ compulsory: 1, community: 41 } | ||
]; | ||
const oneDimensionalOverlaps = [ | ||
{ compulsory: 1, community: 35 }, | ||
{ compulsory: 1, community: 38 }, | ||
{ compulsory: 1, community: 49 }, | ||
{ compulsory: 1, community: 57 }, | ||
{ compulsory: 1, community: 59 }, | ||
{ compulsory: 1, community: 68 } | ||
]; | ||
const twoDimensionalOverlaps = [ | ||
{ compulsory: 1, community: 7 }, | ||
{ compulsory: 1, community: 8 }, | ||
{ compulsory: 1, community: 9 }, | ||
{ compulsory: 1, community: 10 }, | ||
{ compulsory: 1, community: 11 }, | ||
{ compulsory: 1, community: 12 } | ||
]; | ||
|
||
it('compare old and new Intersects method on zones and companies with no overlap', async () => { | ||
const old = useOldMethod(noOverlaps); | ||
for (let i = 0; i != old.length; ++i) { | ||
expect(await old[i]).toBe(false); | ||
} | ||
const newIntersects = useNewMethod(noOverlaps); | ||
for (let i = 0; i != newIntersects.length; ++i) { | ||
expect(await newIntersects[i]).toBe(false); | ||
} | ||
}); | ||
it('compare old and new Intersects method on zones and companies with 1-dim overlap', async () => { | ||
const old = useOldMethod(oneDimensionalOverlaps); | ||
for (let i = 0; i != old.length; ++i) { | ||
expect(await old[i]).toBe(true); | ||
} | ||
const newIntersects = useNewMethod(oneDimensionalOverlaps); | ||
for (let i = 0; i != newIntersects.length; ++i) { | ||
expect(await newIntersects[i]).toBe(false); | ||
} | ||
}); | ||
it('compare old and new Intersects method on zones and companies with 2-dim overlap', async () => { | ||
const old = useOldMethod(twoDimensionalOverlaps); | ||
for (let i = 0; i != old.length; ++i) { | ||
expect(await old[i]).toBe(true); | ||
} | ||
const newIntersects = useNewMethod(twoDimensionalOverlaps); | ||
for (let i = 0; i != newIntersects.length; ++i) { | ||
expect(await newIntersects[i]).toBe(true); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters