Commit 2bb5b508 authored by Michael Vrána's avatar Michael Vrána

Detect cycle tests

parent 96878844
Pipeline #80104 passed with stages
in 4 minutes and 1 second
import { Set } from 'immutable'
import { detectCycles } from "../detectCycle";
import AlgorithmEdge from '../../interfaces/AlgorithmEdge';
const edges = Set<Omit<AlgorithmEdge, 'endParamIndex'>>([
{ id: '1', startNodeId: '1', endNodeId: '2' },
{ id: '2', startNodeId: '2', endNodeId: '3' },
{ id: '3', startNodeId: '3', endNodeId: '4' },
{ id: '4', startNodeId: '4', endNodeId: '2' }
])
describe('detectCycle', () => {
it('detects cycle', () => {
const result = detectCycles(edges).toArray();
['2', '3', '4'].forEach(edge => expect(result).toContain(edge));
expect(result).toHaveLength(3)
})
it("doesn't detect cycle", () => {
expect(detectCycles(edges.remove(edges.last())).toArray()).toHaveLength(0)
})
})
\ No newline at end of file
......@@ -9,7 +9,7 @@ interface PathEntry {
/** Detects cycle in algorithm graph
* @returns Set of edge IDs that are in a cycle in a component that contains startNodeId
*/
export const detectCycles = (edges: Set<AlgorithmEdge>): Set<string> => {
export const detectCycles = (edges: Set<Omit<AlgorithmEdge, 'endParamIndex'>>): Set<string> => {
let visited = Set<string>()
const _detectCycle = (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment