Fix tests
This commit is contained in:
@@ -2,8 +2,11 @@ import 'mocha'
|
|||||||
|
|
||||||
import { TreeNodeFactory } from '../'
|
import { TreeNodeFactory } from '../'
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
|
import { Base64Message } from '../Base64Message';
|
||||||
|
|
||||||
describe('TreeNode', () => {
|
describe('TreeNode', () => {
|
||||||
|
const number3 = Base64Message.fromString("3")
|
||||||
|
const number5 = Base64Message.fromString("5")
|
||||||
it('firstNode should retrieve first node', () => {
|
it('firstNode should retrieve first node', () => {
|
||||||
const topics = 'foo/bar'.split('/')
|
const topics = 'foo/bar'.split('/')
|
||||||
const leaf = TreeNodeFactory.fromEdgesAndValue(topics, undefined)
|
const leaf = TreeNodeFactory.fromEdgesAndValue(topics, undefined)
|
||||||
@@ -13,40 +16,40 @@ describe('TreeNode', () => {
|
|||||||
|
|
||||||
it('updateWithNode should update value', () => {
|
it('updateWithNode should update value', () => {
|
||||||
const topics = 'foo/bar'.split('/')
|
const topics = 'foo/bar'.split('/')
|
||||||
const leaf = TreeNodeFactory.fromEdgesAndValue(topics, '3')
|
const leaf = TreeNodeFactory.fromEdgesAndValue(topics, Base64Message.fromString('3'))
|
||||||
expect(leaf.message && leaf.message.value).to.eq('3')
|
expect(Base64Message.toUnicodeString(leaf.message!.value!)).to.eq('3')
|
||||||
const updateLeave = TreeNodeFactory.fromEdgesAndValue(topics, '5')
|
const updateLeave = TreeNodeFactory.fromEdgesAndValue(topics, Base64Message.fromString('5'))
|
||||||
|
|
||||||
const root = leaf.firstNode()
|
const root = leaf.firstNode()
|
||||||
root.updateWithNode(updateLeave.firstNode())
|
root.updateWithNode(updateLeave.firstNode())
|
||||||
|
|
||||||
expect(root.sourceEdge).to.eq(undefined)
|
expect(root.sourceEdge).to.eq(undefined)
|
||||||
expect(leaf.message && leaf.message.value).to.eq('5')
|
expect(Base64Message.toUnicodeString(leaf.message!.value!)).to.eq('5')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updateWithNode should update intermediate nodes', () => {
|
it('updateWithNode should update intermediate nodes', () => {
|
||||||
const topics1 = 'foo/bar/baz'.split('/')
|
const topics1 = 'foo/bar/baz'.split('/')
|
||||||
const leaf = TreeNodeFactory.fromEdgesAndValue(topics1, '3')
|
const leaf = TreeNodeFactory.fromEdgesAndValue(topics1, Base64Message.fromString('3'))
|
||||||
expect(leaf.message && leaf.message.value).to.eq('3')
|
expect(Base64Message.toUnicodeString(leaf.message!.value!)).to.eq('3')
|
||||||
|
|
||||||
const topics2 = 'foo/bar'.split('/')
|
const topics2 = 'foo/bar'.split('/')
|
||||||
const updateLeave = TreeNodeFactory.fromEdgesAndValue(topics2, '5')
|
const updateLeave = TreeNodeFactory.fromEdgesAndValue(topics2, Base64Message.fromString('5'))
|
||||||
leaf.firstNode().updateWithNode(updateLeave.firstNode())
|
leaf.firstNode().updateWithNode(updateLeave.firstNode())
|
||||||
|
|
||||||
const barNode = leaf.firstNode().findNode('foo/bar')
|
const barNode = leaf.firstNode().findNode('foo/bar')
|
||||||
expect(barNode && barNode.sourceEdge && barNode.sourceEdge.name).to.eq('bar')
|
expect(barNode && barNode.sourceEdge && barNode.sourceEdge.name).to.eq('bar')
|
||||||
expect(barNode && barNode.message && barNode.message.value).to.eq('5')
|
expect(Base64Message.toUnicodeString(barNode!.message!.value!)).to.eq('5')
|
||||||
|
|
||||||
expect(leaf.sourceEdge && leaf.sourceEdge.name).to.eq('baz')
|
expect(leaf.sourceEdge && leaf.sourceEdge.name).to.eq('baz')
|
||||||
expect(leaf.message && leaf.message.value).to.eq('3')
|
expect(Base64Message.toUnicodeString(leaf.message!.value!)).to.eq('3')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('updateWithNode should add nodes to the tree', () => {
|
it('updateWithNode should add nodes to the tree', () => {
|
||||||
const topics1 = 'foo/bar'.split('/')
|
const topics1 = 'foo/bar'.split('/')
|
||||||
const leaf1 = TreeNodeFactory.fromEdgesAndValue(topics1, 'foo')
|
const leaf1 = TreeNodeFactory.fromEdgesAndValue(topics1, Base64Message.fromString('foo'))
|
||||||
|
|
||||||
const topics2 = 'foo/bar/baz'.split('/')
|
const topics2 = 'foo/bar/baz'.split('/')
|
||||||
const leaf2 = TreeNodeFactory.fromEdgesAndValue(topics2, 'bar')
|
const leaf2 = TreeNodeFactory.fromEdgesAndValue(topics2, Base64Message.fromString('bar'))
|
||||||
|
|
||||||
leaf1.firstNode().updateWithNode(leaf2.firstNode())
|
leaf1.firstNode().updateWithNode(leaf2.firstNode())
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'mocha'
|
|||||||
|
|
||||||
import { TreeNodeFactory } from '../'
|
import { TreeNodeFactory } from '../'
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
|
import { Base64Message } from '../Base64Message';
|
||||||
|
|
||||||
describe('TreeNodeFactory', () => {
|
describe('TreeNodeFactory', () => {
|
||||||
it('root node must not have a sourceEdge', () => {
|
it('root node must not have a sourceEdge', () => {
|
||||||
@@ -15,7 +16,7 @@ describe('TreeNodeFactory', () => {
|
|||||||
it('should create node', () => {
|
it('should create node', () => {
|
||||||
const topic = 'foo/bar'
|
const topic = 'foo/bar'
|
||||||
const edges = topic.split('/')
|
const edges = topic.split('/')
|
||||||
const node = TreeNodeFactory.fromEdgesAndValue(edges, '5')
|
const node = TreeNodeFactory.fromEdgesAndValue(edges, Base64Message.fromString('5'))
|
||||||
|
|
||||||
if (!node.sourceEdge || !node.sourceEdge.source || !node.message) {
|
if (!node.sourceEdge || !node.sourceEdge.source || !node.message) {
|
||||||
expect.fail('should not happen')
|
expect.fail('should not happen')
|
||||||
@@ -24,7 +25,7 @@ describe('TreeNodeFactory', () => {
|
|||||||
|
|
||||||
expect(node).to.not.eq(undefined)
|
expect(node).to.not.eq(undefined)
|
||||||
expect(node.sourceEdge.name).to.eq('bar')
|
expect(node.sourceEdge.name).to.eq('bar')
|
||||||
expect(node.message.value).to.eq('5')
|
expect(Base64Message.toUnicodeString(node.message.value!)).to.eq('5')
|
||||||
|
|
||||||
const foo = node.firstNode().findNode('foo')
|
const foo = node.firstNode().findNode('foo')
|
||||||
expect(foo && foo.sourceEdge && foo.sourceEdge.name).to.eq('foo')
|
expect(foo && foo.sourceEdge && foo.sourceEdge.name).to.eq('foo')
|
||||||
@@ -33,14 +34,14 @@ describe('TreeNodeFactory', () => {
|
|||||||
it('node should contain edges in order', () => {
|
it('node should contain edges in order', () => {
|
||||||
const topic = 'foo/bar/baz'
|
const topic = 'foo/bar/baz'
|
||||||
const edges = topic.split('/')
|
const edges = topic.split('/')
|
||||||
const node = TreeNodeFactory.fromEdgesAndValue(edges, '5')
|
const node = TreeNodeFactory.fromEdgesAndValue(edges, Base64Message.fromString('5'))
|
||||||
|
|
||||||
if (!node.sourceEdge || !node.sourceEdge.source || !node.message) {
|
if (!node.sourceEdge || !node.sourceEdge.source || !node.message) {
|
||||||
expect.fail('should not happen')
|
expect.fail('should not happen')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(node.message.value).to.eq('5')
|
expect(Base64Message.toUnicodeString(node.message.value!)).to.eq('5')
|
||||||
expect(node.sourceEdge.name).to.eq('baz')
|
expect(node.sourceEdge.name).to.eq('baz')
|
||||||
|
|
||||||
const barNode = node.sourceEdge.source
|
const barNode = node.sourceEdge.source
|
||||||
|
|||||||
Reference in New Issue
Block a user