Skip to content

Commit

Permalink
add test for arrivedAt bounds behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
krisl committed Jul 18, 2023
1 parent da68981 commit 4ff30cc
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1250,4 +1250,50 @@ describe('Exceptions', () => {
expect(nodeB.isLocked()).toBeFalsy()
expect(nodeC.isLocked()).toBeFalsy()
})
test.only('arrivedAt bounds', () => {
const getLockForLink = (from: Lock, to: Lock) => {
return creator.makeLinkLock()
}
const creator = new Graferse()
const nodeA = creator.makeLock()
const nodeB = creator.makeLock()
const nodeC = creator.makeLock()
const nodeX = creator.makeLock()

const makeLocker = makeMakeLocker<Lock,Lock>(
creator,
node => node,
(from, to) => creator.makeLinkLock(),
node => node)

const test1Path = [nodeA, nodeB, nodeC]
var forwardPath: Array<NextNode<Lock>> = []
const test1At = makeLocker("test1").makePathLocker(test1Path)(
(nextNodes) => { forwardPath = nextNodes }
)

expect(nodeA.isLocked()).toBeFalsy()
expect(nodeB.isLocked()).toBeFalsy()
expect(nodeC.isLocked()).toBeFalsy()
expect(forwardPath).toEqual([])

test1At.arrivedAt(-2)
expect(nodeA.isLocked()).toBeFalsy()
expect(nodeB.isLocked()).toBeFalsy()
expect(nodeC.isLocked()).toBeFalsy()
expect(forwardPath).toEqual([])

test1At.arrivedAt(-1)
// first node is locked because the next node is pos 0
expect(nodeA.isLocked()).toBeTruthy()
expect(nodeB.isLocked()).toBeFalsy()
expect(nodeC.isLocked()).toBeFalsy()
expect(forwardPath).toEqual([{index: 0, node: nodeA}])

test1At.arrivedAt(3)
// and all nodes are unlocked again
expect(nodeA.isLocked()).toBeFalsy()
expect(nodeB.isLocked()).toBeFalsy()
expect(nodeC.isLocked()).toBeFalsy()
})
})

0 comments on commit 4ff30cc

Please sign in to comment.