Improve data model & fix tests
This commit is contained in:
@@ -1,36 +1,44 @@
|
||||
import { Edge, Tree, TreeNode, TreeNodeFactory } from '../'
|
||||
import { expect } from 'chai';
|
||||
import 'mocha';
|
||||
|
||||
import { TreeNodeFactory } from '../'
|
||||
import './TreeNode.findNode'
|
||||
import { expect } from 'chai'
|
||||
import 'mocha'
|
||||
|
||||
describe('TreeNode', () => {
|
||||
it('firstNode should retrieve first node', () => {
|
||||
const topics = 'foo/bar'.split('/')
|
||||
const leaf = TreeNodeFactory.fromEdgesAndValue(topics, 3)
|
||||
|
||||
expect(leaf.firstNode().edges['foo']).to.not.eq(undefined)
|
||||
})
|
||||
|
||||
it('updateWithNode should update value', () => {
|
||||
const topics = 'foo/bar'.split('/')
|
||||
const leaf = TreeNodeFactory.fromEdgesAndValue(topics, 3)
|
||||
expect(leaf.value).to.eq(3)
|
||||
expect(leaf.message && leaf.message.value).to.eq(3)
|
||||
const updateLeave = TreeNodeFactory.fromEdgesAndValue(topics, 5)
|
||||
leaf.firstNode().updateWithNode(updateLeave.firstNode())
|
||||
|
||||
expect(leaf.firstNode().sourceEdge.name).to.eq(updateLeave.firstNode().sourceEdge.name)
|
||||
expect(leaf.value).to.eq(5)
|
||||
let root = leaf.firstNode()
|
||||
root.updateWithNode(updateLeave.firstNode())
|
||||
|
||||
expect(root.sourceEdge).to.eq(undefined)
|
||||
expect(leaf.message && leaf.message.value).to.eq(5)
|
||||
})
|
||||
|
||||
it('updateWithNode should update intermediate nodes', () => {
|
||||
const topics1 = 'foo/bar/baz'.split('/')
|
||||
const leaf = TreeNodeFactory.fromEdgesAndValue(topics1, 3)
|
||||
expect(leaf.value).to.eq(3)
|
||||
expect(leaf.message && leaf.message.value).to.eq(3)
|
||||
|
||||
const topics2 = 'foo/bar'.split('/')
|
||||
const updateLeave = TreeNodeFactory.fromEdgesAndValue(topics2, 5)
|
||||
leaf.firstNode().updateWithNode(updateLeave.firstNode())
|
||||
|
||||
let barNode = leaf.firstNode().findNode('foo/bar')
|
||||
expect(barNode && barNode.sourceEdge.name).to.eq('bar')
|
||||
expect(barNode && barNode.value).to.eq(5)
|
||||
expect(barNode && barNode.sourceEdge && barNode.sourceEdge.name).to.eq('bar')
|
||||
expect(barNode && barNode.message && barNode.message.value).to.eq(5)
|
||||
|
||||
expect(leaf.sourceEdge.name).to.eq('baz')
|
||||
expect(leaf.value).to.eq(3)
|
||||
expect(leaf.sourceEdge && leaf.sourceEdge.name).to.eq('baz')
|
||||
expect(leaf.message && leaf.message.value).to.eq(3)
|
||||
})
|
||||
|
||||
it('updateWithNode should add nodes to the tree', () => {
|
||||
|
||||
Reference in New Issue
Block a user