1 |
|
2 |
|
3 | var expect = require('chai').expect
|
4 | var dtypenet = require('../src/dynatype-network.js')
|
5 | var grlib = require('graphlib')
|
6 | var fs = require('fs')
|
7 |
|
8 | var convertGraph = new grlib.Graph({ directed: true, compound: false, multigraph: false })
|
9 | var processGraph = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/testgraph0.graphlib')))
|
10 | var processGraphGeneric = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/testgraph0_generics.graphlib')))
|
11 | var processGraphGeneric2 = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/testgraph0_generics2.graphlib')))
|
12 |
|
13 | convertGraph.setNode('int', 'int')
|
14 | convertGraph.setNode('string', 'string')
|
15 |
|
16 | convertGraph.setEdge('int', 'string', {from: 'int', to: 'string'})
|
17 | convertGraph.setEdge('string', 'int', {from: 'string', to: 'int'})
|
18 |
|
19 | describe('Dynamic type network graph', function () {
|
20 | it('Creates a processgraph with correct translator nodes', function () {
|
21 | var d = dtypenet.addTypeConversion(processGraph, convertGraph)
|
22 | var curGraph = grlib.json.write(d)
|
23 |
|
24 | var testgraph = JSON.parse(fs.readFileSync('test/fixtures/testgraph.graphlib'))
|
25 | expect(curGraph).to.deep.equal(testgraph)
|
26 | })
|
27 | it('The graph with added translators should not be changed', function () {
|
28 | var d = dtypenet.addTypeConversion(processGraph, convertGraph)
|
29 | var dtrans = dtypenet.addTypeConversion(d, convertGraph)
|
30 | expect(d.nodes.length).to.be.equal(dtrans.nodes.length)
|
31 | expect(d.edges.length).to.be.equal(dtrans.edges.length)
|
32 | })
|
33 | it('Creates a processgraph with correct translator nodes without generics simple', function () {
|
34 | var g = dtypenet.replaceGenerics(processGraphGeneric)
|
35 | var d = dtypenet.addTypeConversion(g, convertGraph)
|
36 | var curGraph = grlib.json.write(d)
|
37 |
|
38 | var testgraph = JSON.parse(fs.readFileSync('test/fixtures/testgraph_generics.graphlib'))
|
39 | expect(curGraph).to.deep.equal(testgraph)
|
40 | })
|
41 | it('Creates a processgraph with correct translator nodes without generics complex', function () {
|
42 | var g = dtypenet.replaceGenerics(processGraphGeneric2)
|
43 | var d = dtypenet.addTypeConversion(g, convertGraph)
|
44 | var curGraph = grlib.json.write(d)
|
45 |
|
46 | var testgraph = JSON.parse(fs.readFileSync('test/fixtures/testgraph_generics2.graphlib'))
|
47 | expect(curGraph).to.deep.equal(testgraph)
|
48 | })
|
49 | })
|