isomorphism
Version:
Find subgraph isomorphisms with Ullman's 1976 algorithm.
309 lines (289 loc) • 5.13 kB
JavaScript
/* @flow */
/* global describe, it */
import { clone } from 'ramda'
import assert from 'assert'
import { allIsomorphismsForDigraphs, allIsomorphismsForWeightedDigraphs } from '../lib/index'
declare class describe {
static (description: string, spec: () => void): void;
}
declare class it {
static (description: string, spec: () => void): void;
}
// TODO test for every error type
describe('Weighted', function () {
it('Three-cycle with one two-weighted edge has one isomorpism to a certain directed Hajos graph', function () {
assert.deepEqual(
allIsomorphismsForWeightedDigraphs(
[
[[1,200]],
[[2,1]],
[[0,1]]
],
[
[[1,800]],
[[2,1],[3,1]],
[[0,1],[4,1]],
[[4,1]],
[[1,1],[5,1]],
[[2,1]]
],
null
),
[
[]
]
)
})
it('Self-reference in target graph does not match three-cycle', function () {
assert.deepEqual(
allIsomorphismsForWeightedDigraphs(
[
[[1,1]],
[[2,1]],
[[0,1]]
],
[
[],
[[1,1]],
[]
],
null
),
[]
)
})
it('Self-reference in target graph does not match three-chain', function () {
assert.deepEqual(
allIsomorphismsForWeightedDigraphs(
[
[[1,1]],
[[2,1]],
[]
],
[
[],
[[1,1]],
[]
],
null
),
[]
)
})
})
describe('Unweighted', function () {
it('a -> b has only one isomorphism to a -> b', function () {
assert.deepEqual(
allIsomorphismsForDigraphs(
[
[],
[]
],
[
[],
[]
],
null
),
[
[]
]
)
})
it('Three-cycle isomorphic to every cycle', function () {
assert.deepEqual(
allIsomorphismsForDigraphs(
[
[],
[],
[]
],
[
[],
[],
[]
],
null
),
[
[],
[],
[]
]
)
})
it('Isomorphisms for three-chain pattern on ten-chain', function () {
assert.deepEqual(
allIsomorphismsForDigraphs(
[
[],
[],
[]
],
[
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
],
null
),
[
[],
[],
[],
[],
[],
[],
[],
[]
]
)
})
it('Isomorphisms for three-chain pattern on ten-cycle', function () {
assert.deepEqual(
allIsomorphismsForDigraphs(
[
[],
[],
[]
],
[
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
],
null
),
[
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
]
)
})
// TODO firecracker graph and Y?
it('Pattern larger than graph produces no isomorphisms', function () {
assert.deepEqual(
allIsomorphismsForDigraphs(
[
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
],
[
[],
[],
[]
],
null
),
[]
)
})
// http://mathworld.wolfram.com/HajosGraph.html
it('Three-cycle has twelve isomorpisms to a certain directed Hajos graph', function () {
assert.deepEqual(
allIsomorphismsForDigraphs(
[
[],
[],
[]
],
[
[],
[],
[],
[],
[],
[]
],
null
),
[
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
]
)
})
it('Isomorphisms for three-chain pattern on ten-cycle with orphans', function () {
assert.deepEqual(
allIsomorphismsForDigraphs(
[
[],
[],
[]
],
[
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
],
null
),
[
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
]
)
})
})