Report for lv.id.jc.algorithm.graph.GraphSpec


Summary:

Created on Sun Oct 16 12:33:47 EEST 2022 by jegors
Executed features Passed Failures Errors Skipped Success rate Time
5 5 0 0 0 100.0% 0.032 seconds
Generic Graph
A generic implementation of Graph structure

Features:

should return edges for a given node Return
(0)
Given:
a simple graph with three nodes
def graph = Graph.of([
        A: [B: 7, C: 2],
        B: [A: 3, C: 5],
        C: [A: 1, B: 3]
])
Expect:
The method returns expected edges for given node
graph.edges(node) == expected
Examples:
node expected
A [B:7, C:2] OK (0)
B [A:3, C:5] OK (0)
C [A:1, B:3] OK (0)
3/3 passed
should calculate distance for a path Return
(0)
Given:
a complex graph with eight nodes
def graph = Graph.of([
        A: [B: 5, H: 2],
        B: [A: 5, C: 7],
        C: [B: 7, D: 3, G: 4],
        D: [C: 20, E: 4],
        E: [F: 5],
        F: [G: 6],
        G: [C: 4],
        H: [G: 3]
])
Expect:
the distance for a path correctly calculated
graph.getDistance(path) == distance as double
Where:
path and expected distance
Examples:
path distance
[A] 0 OK (0)
[A, B] 5 OK (0)
[B, A] 5 OK (0)
[A, B, A] 10 OK (0)
[A, B, A, B] 15 OK (0)
[C, D] 3 OK (0)
[D, C] 20 OK (0)
[D, E, F, G, C] 19 OK (0)
8/8 passed
should be zero distance for an empty path Return
(0.020 seconds)
Given:
any graph
def graph = Graph.of(_ as Map)
Expect:
the distance is zero for an empty path
graph.getDistance([]) == 0
should be zero distance for any one node path Return
(0)
Given:
any graph
def graph = Graph.of(_ as Map)
Expect:
the zero distance for any one-node path
graph.getDistance(oneNodePath) == 0
Where:
the node may be of any type and even non-existent
Examples:
oneNodePath
[A] OK (0)
[B] OK (0)
[2] OK (0)
[X] OK (0)
[12.56] OK (0)
5/5 passed
should throw NPE for incorrect path Return
(0)
Given:
a medium graph with five nodes
def graph = Graph.of([
        A: [B: 5],
        B: [A: 5, C: 10],
        C: [B: 20, D: 5],
        D: [E: 5],
        E: [B: 5]
])
When:
we call the method with incorrect path
graph.getDistance(incorrectPath)
Then:
the NPE thrown
thrown NullPointerException
Where:
path is more then one node
Examples:
incorrectPath
[E, D] OK (0)
[A, C] OK (0)
[A, B, D] OK (0)
3/3 passed