UNPKG

2.65 kBJavaScriptView Raw
1/* global describe, it */
2
3var expect = require('chai').expect
4var dtypenet = require('../src/dynatype-network.js')
5var grlib = require('graphlib')
6var fs = require('fs')
7
8var convertGraph = new grlib.Graph({ directed: true, compound: false, multigraph: false })
9var processGraph = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/testgraph0.graphlib')))
10var processGraphGeneric = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/testgraph0_generics.graphlib')))
11var processGraphGeneric2 = grlib.json.read(JSON.parse(fs.readFileSync('./test/fixtures/testgraph0_generics2.graphlib')))
12
13convertGraph.setNode('int', 'int')
14convertGraph.setNode('string', 'string')
15
16convertGraph.setEdge('int', 'string', {from: 'int', to: 'string'})
17convertGraph.setEdge('string', 'int', {from: 'string', to: 'int'})
18
19describe('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 // fs.writeFileSync('test/fixtures/testgraph.graphlib', JSON.stringify(grlib.json.write(d), null, 2))
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 // fs.writeFileSync('test/fixtures/testgraph_generics.graphlib', JSON.stringify(grlib.json.write(d), null, 2))
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 // fs.writeFileSync('test/fixtures/testgraph_generics2.graphlib', JSON.stringify(grlib.json.write(d), null, 2))
46 var testgraph = JSON.parse(fs.readFileSync('test/fixtures/testgraph_generics2.graphlib'))
47 expect(curGraph).to.deep.equal(testgraph)
48 })
49})