From a67235fdd66a9b671b64d71e1fe1b082454875d9 Mon Sep 17 00:00:00 2001 From: Philipp Schaad Date: Fri, 6 Sep 2024 12:36:26 +0200 Subject: [PATCH] Add more tests --- .../graphlib/algorithms/cycles.test.ts | 2 + tests/unit/layouter/graphlib/di_graph.test.ts | 2 + tests/unit/layouter/graphlib/graph.test.ts | 2 + .../state_machine/sm_layouter.test.ts | 47 +++++++++++ tests/unit/sdfg_diff_viewer.test.ts | 2 + tests/unit/utils/collections.test.ts | 82 +++++++++++++++++++ tests/unit/utils/sdfg/sdfg_utils.test.ts | 2 + 7 files changed, 139 insertions(+) create mode 100644 tests/unit/utils/collections.test.ts diff --git a/tests/unit/layouter/graphlib/algorithms/cycles.test.ts b/tests/unit/layouter/graphlib/algorithms/cycles.test.ts index c3b8bcf2..06faa5e1 100644 --- a/tests/unit/layouter/graphlib/algorithms/cycles.test.ts +++ b/tests/unit/layouter/graphlib/algorithms/cycles.test.ts @@ -1,3 +1,5 @@ +// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. + import { allBackedges, simpleCycles, diff --git a/tests/unit/layouter/graphlib/di_graph.test.ts b/tests/unit/layouter/graphlib/di_graph.test.ts index d7181147..ad2fd05a 100644 --- a/tests/unit/layouter/graphlib/di_graph.test.ts +++ b/tests/unit/layouter/graphlib/di_graph.test.ts @@ -1,3 +1,5 @@ +// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. + import { DiGraph } from '../../../../src/layouter/graphlib/di_graph'; function testAddEdges(): void { diff --git a/tests/unit/layouter/graphlib/graph.test.ts b/tests/unit/layouter/graphlib/graph.test.ts index fe8566c7..555380ee 100644 --- a/tests/unit/layouter/graphlib/graph.test.ts +++ b/tests/unit/layouter/graphlib/graph.test.ts @@ -1,3 +1,5 @@ +// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. + import { Graph } from '../../../../src/layouter/graphlib/graph'; function testInsertNode(): void { diff --git a/tests/unit/layouter/state_machine/sm_layouter.test.ts b/tests/unit/layouter/state_machine/sm_layouter.test.ts index 37380ba9..978fbc69 100644 --- a/tests/unit/layouter/state_machine/sm_layouter.test.ts +++ b/tests/unit/layouter/state_machine/sm_layouter.test.ts @@ -1,3 +1,5 @@ +// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. + import { DiGraph } from '../../../../src/layouter/graphlib/di_graph'; import { BACKEDGE_SPACING, @@ -304,6 +306,50 @@ function testSkipLoopWithBreakReturn(): void { expect(graph.get('7')?.rank).toBe(7); } +function testMultiEntryExit(): void { + const graph = new DiGraph(); + + // Construct graph. + // 0 1 + // | | + // 2--| + // | + // 3 + + constructEdge(graph, '0', '2'); + constructEdge(graph, '1', '2'); + constructEdge(graph, '2', '3'); + + const layouter = new SMLayouter(graph); + layouter.doLayout(); + + expect(graph.get('0')?.rank).toBe(1); + expect(graph.get('1')?.rank).toBe(1); + expect(graph.get('2')?.rank).toBe(2); + expect(graph.get('3')?.rank).toBe(3); + + const graph2 = new DiGraph(); + + // Construct graph. + // 0 + // | + // 1--| + // | | + // 2 3 + + constructEdge(graph2, '0', '1'); + constructEdge(graph2, '1', '2'); + constructEdge(graph2, '1', '3'); + + const layouter2 = new SMLayouter(graph2); + layouter2.doLayout(); + + expect(graph2.get('0')?.rank).toBe(0); + expect(graph2.get('1')?.rank).toBe(1); + expect(graph2.get('2')?.rank).toBe(2); + expect(graph2.get('3')?.rank).toBe(2); +} + describe('Test vertical state machine layout ranking', () => { test('Basic branching', testBasicBranching); test('Nested branching', testNestedBranching); @@ -320,6 +366,7 @@ describe('Test vertical state machine layout ranking', () => { 'Test conditionally skipped loop with break and returns', testSkipLoopWithBreakReturn ); + test('Test multiple source nodes and sink nodes', testMultiEntryExit); }); function testEdgeRoutingSelfLoop(): void { diff --git a/tests/unit/sdfg_diff_viewer.test.ts b/tests/unit/sdfg_diff_viewer.test.ts index bb04dd74..f8fbdcec 100644 --- a/tests/unit/sdfg_diff_viewer.test.ts +++ b/tests/unit/sdfg_diff_viewer.test.ts @@ -1,3 +1,5 @@ +// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. + import path from 'path'; import fs from 'fs'; import { diff --git a/tests/unit/utils/collections.test.ts b/tests/unit/utils/collections.test.ts new file mode 100644 index 00000000..7f11091f --- /dev/null +++ b/tests/unit/utils/collections.test.ts @@ -0,0 +1,82 @@ +// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. + +import { AccessStack, LinkedStack } from "../../../src/utils/collections"; + +function testLinkedStackConstruction(): void { + const lStack = new LinkedStack(); + expect(lStack.size).toBe(0); + expect(lStack.top).toBeUndefined(); + expect(lStack.pop()).toBeUndefined(); +} + +function testLinkedStackInsertion(): void { + const lStack = new LinkedStack(); + + lStack.push(0); + lStack.push(1); + lStack.push(2); + const rVal = lStack.push(3); + + expect(lStack.size).toBe(4); + expect(lStack.top?.value).toBe(3); + expect(rVal).toBe(4); +} + +function testLinkedStackPop(): void { + const lStack = new LinkedStack(); + + lStack.push(0); + lStack.push(1); + lStack.push(2); + lStack.push(3); + + const rval = lStack.pop(); + + expect(lStack.size).toBe(3); + expect(lStack.top?.value).toBe(2); + expect(rval).toBe(3); +} + +describe('Test linked stack data structure', () => { + test('Construction', testLinkedStackConstruction); + test('Insertion', testLinkedStackInsertion); + test('Popping', testLinkedStackPop); +}); + +function testAccessStackConstruction(): void { + const aStack = new AccessStack(); + expect(aStack.size).toBe(0); + expect(aStack.top).toBeUndefined(); + expect(aStack.pop()).toBeUndefined(); +} + +function testAccessStackTouching(): void { + const aStack = new AccessStack(); + + aStack.push(0); + aStack.push(1); + aStack.push(2); + aStack.push(3); + aStack.push(4); + aStack.push(5); + const rval = aStack.pop(); + + expect(aStack.size).toBe(5); + expect(aStack.top?.value).toBe(4); + expect(rval).toBe(5); + + expect(aStack.touch(0)).toBe(4); + expect(aStack.touch(0)).toBe(0); + expect(aStack.top?.value).toBe(0); + expect(aStack.touch(2)).toBe(3); + expect(aStack.touch(2)).toBe(0); + expect(aStack.top?.value).toBe(2); + expect(aStack.touch(5)).toBe(-1); + expect(aStack.top?.value).toBe(5); + expect(aStack.size).toBe(6); +} + +describe('Test Access Stack data structure', () => { + test('Construction', testAccessStackConstruction); + test('Touching', testAccessStackTouching); +}); diff --git a/tests/unit/utils/sdfg/sdfg_utils.test.ts b/tests/unit/utils/sdfg/sdfg_utils.test.ts index 9584e6bb..b99cf97e 100644 --- a/tests/unit/utils/sdfg/sdfg_utils.test.ts +++ b/tests/unit/utils/sdfg/sdfg_utils.test.ts @@ -1,3 +1,5 @@ +// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved. + import path from 'path'; import fs from 'fs'; import {