Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad committed Sep 6, 2024
1 parent d0e373c commit a67235f
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/unit/layouter/graphlib/algorithms/cycles.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.

import {
allBackedges,
simpleCycles,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/layouter/graphlib/di_graph.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/layouter/graphlib/graph.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/layouter/state_machine/sm_layouter.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -304,6 +306,50 @@ function testSkipLoopWithBreakReturn(): void {
expect(graph.get('7')?.rank).toBe(7);
}

function testMultiEntryExit(): void {
const graph = new DiGraph<SMLayouterNode, SMLayouterEdge>();

// 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<SMLayouterNode, SMLayouterEdge>();

// 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);
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/sdfg_diff_viewer.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
82 changes: 82 additions & 0 deletions tests/unit/utils/collections.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
2 changes: 2 additions & 0 deletions tests/unit/utils/sdfg/sdfg_utils.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit a67235f

Please sign in to comment.