From 489bf69cc2381eb51ad42c912d364117b14cb596 Mon Sep 17 00:00:00 2001 From: Braulio Rivas Abad Date: Sat, 1 Jun 2024 20:29:41 -0500 Subject: [PATCH] [FIX] update test based on new filtering logic (new id's for links) --- js/menu/filter/reconnect.js | 12 +++--- test/filter.test.js | 78 +++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 48 deletions(-) diff --git a/js/menu/filter/reconnect.js b/js/menu/filter/reconnect.js index 54cc71f0..c60b2f1f 100644 --- a/js/menu/filter/reconnect.js +++ b/js/menu/filter/reconnect.js @@ -1,13 +1,13 @@ import { Link } from "../../objects.js"; export function reconnect(criteriaFunction, particlesHandler) { - const { parentLinks, childrenLinks, infoBoxes: particles } = particlesHandler; + const { parentLinks, childrenLinks, infoBoxes } = particlesHandler; const newParentLinks = []; const newChildrenLinks = []; const filteredParticles = []; - for (const particle of particles) { + for (const particle of infoBoxes) { if (!criteriaFunction(particle)) { filteredParticles.push(null); @@ -15,13 +15,13 @@ export function reconnect(criteriaFunction, particlesHandler) { const childrenParticles = []; for (const parent of particle.parents) { - if (criteriaFunction(particles[parent])) { + if (criteriaFunction(infoBoxes[parent])) { parentParticles.push(parent); } } for (const child of particle.children) { - if (criteriaFunction(particles[child])) { + if (criteriaFunction(infoBoxes[child])) { childrenParticles.push(child); } } @@ -43,7 +43,7 @@ export function reconnect(criteriaFunction, particlesHandler) { for (const parentLinkId of particle.parentLinks) { const parentLink = parentLinks[parentLinkId]; - const parent = particles[parentLink.from]; + const parent = infoBoxes[parentLink.from]; if (criteriaFunction(parent)) { const parentLinkCopy = new Link( newParentLinks.length, @@ -57,7 +57,7 @@ export function reconnect(criteriaFunction, particlesHandler) { for (const childrenLinkId of particle.childrenLinks) { const childrenLink = childrenLinks[childrenLinkId]; - const child = particles[childrenLink.to]; + const child = infoBoxes[childrenLink.to]; if (criteriaFunction(child)) { const childrenLinkCopy = new Link( newChildrenLinks.length, diff --git a/test/filter.test.js b/test/filter.test.js index 01e08c5f..04981236 100644 --- a/test/filter.test.js +++ b/test/filter.test.js @@ -8,7 +8,7 @@ import { const parentLinks = []; const childrenLinks = []; -const particles = []; +const infoBoxes = []; beforeAll(() => { for (let i = 0; i < 5; i++) { @@ -17,7 +17,7 @@ beforeAll(() => { particle.charge = i; particle.mass = i * 10; particle.simStatus = i + 23; - particles.push(particle); + infoBoxes.push(particle); } parentLinks.push(new Link(0, 0, 1)); @@ -32,28 +32,34 @@ beforeAll(() => { childrenLinks.push(new Link(3, 2, 4)); childrenLinks.push(new Link(4, 3, 4)); - particles[0].children = [1, 2]; - particles[0].childrenLinks = [0, 1]; + infoBoxes[0].children = [1, 2]; + infoBoxes[0].childrenLinks = [0, 1]; - particles[1].parents = [0]; - particles[1].children = [3]; - particles[1].parentLinks = [0]; - particles[1].childrenLinks = [2]; + infoBoxes[1].parents = [0]; + infoBoxes[1].children = [3]; + infoBoxes[1].parentLinks = [0]; + infoBoxes[1].childrenLinks = [2]; - particles[2].parents = [0]; - particles[2].children = [4]; - particles[2].parentLinks = [1]; - particles[2].childrenLinks = [3]; + infoBoxes[2].parents = [0]; + infoBoxes[2].children = [4]; + infoBoxes[2].parentLinks = [1]; + infoBoxes[2].childrenLinks = [3]; - particles[3].parents = [1]; - particles[3].children = [4]; - particles[3].parentLinks = [3]; - particles[3].childrenLinks = [4]; + infoBoxes[3].parents = [1]; + infoBoxes[3].children = [4]; + infoBoxes[3].parentLinks = [3]; + infoBoxes[3].childrenLinks = [4]; - particles[4].parents = [2, 3]; - particles[4].parentLinks = [2, 4]; + infoBoxes[4].parents = [2, 3]; + infoBoxes[4].parentLinks = [2, 4]; }); +const particlesHandler = { + parentLinks, + childrenLinks, + infoBoxes, +}; + describe("filter by ranges", () => { it("filter by a single range parameter", () => { const momentum = new Range("momentum"); @@ -64,13 +70,11 @@ describe("filter by ranges", () => { const [newParentLinks, newChildrenLinks, filteredParticles] = reconnect( criteriaFunction, - parentLinks, - childrenLinks, - particles + particlesHandler ); - expect(newChildrenLinks.map((link) => link.id)).toEqual([4]); - expect(newParentLinks.map((link) => link.id)).toEqual([4]); + expect(newChildrenLinks.map((link) => link.id)).toEqual([0]); + expect(newParentLinks.map((link) => link.id)).toEqual([0]); expect( filteredParticles.filter((p) => p).map((particle) => particle.id) ).toEqual([3, 4]); @@ -87,13 +91,11 @@ describe("filter by ranges", () => { const [newParentLinks, newChildrenLinks, filteredParticles] = reconnect( criteriaFunction, - parentLinks, - childrenLinks, - particles + particlesHandler ); - expect(newChildrenLinks.map((link) => link.id)).toEqual([4]); - expect(newParentLinks.map((link) => link.id)).toEqual([4]); + expect(newChildrenLinks.map((link) => link.id)).toEqual([0]); + expect(newParentLinks.map((link) => link.id)).toEqual([0]); expect( filteredParticles.filter((p) => p).map((particle) => particle.id) ).toEqual([3, 4]); @@ -109,9 +111,7 @@ describe("filter by checkboxes", () => { const [newParentLinks, newChildrenLinks, filteredParticles] = reconnect( criteriaFunction, - parentLinks, - childrenLinks, - particles + particlesHandler ); expect(newChildrenLinks.map((link) => link.id)).toEqual([]); @@ -137,13 +137,11 @@ describe("filter by checkboxes", () => { const [newParentLinks, newChildrenLinks, filteredParticles] = reconnect( criteriaFunction, - parentLinks, - childrenLinks, - particles + particlesHandler ); - expect(newChildrenLinks.map((link) => link.id)).toEqual([0, 1, 4]); - expect(newParentLinks.map((link) => link.id)).toEqual([0, 1, 4]); + expect(newChildrenLinks.map((link) => link.id)).toEqual([0, 1, 2]); + expect(newParentLinks.map((link) => link.id)).toEqual([0, 1, 2]); expect( filteredParticles.filter((p) => p).map((particle) => particle.id) ).toEqual([0, 3, 4]); @@ -163,9 +161,7 @@ describe("filter by ranges and checkboxes", () => { const [newParentLinks, newChildrenLinks, filteredParticles] = reconnect( criteriaFunction, - parentLinks, - childrenLinks, - particles + particlesHandler ); expect(newParentLinks.map((link) => link.id).sort()).toEqual([ @@ -193,9 +189,7 @@ describe("filter by ranges and checkboxes", () => { const [newParentLinks, newChildrenLinks, filteredParticles] = reconnect( criteriaFunction, - parentLinks, - childrenLinks, - particles + particlesHandler ); expect(newChildrenLinks.map((link) => link.id)).toEqual([]);