2
2
3
3
import { assertEquals } from "https://deno.land/[email protected] /testing/asserts.ts" ;
4
4
import { Graph } from '../src/graph.js' ;
5
+ const short = props => props . name . split ( / \n / ) [ 0 ]
6
+ const nameof = ( graph , nid ) => short ( graph . nodes [ nid ] . props )
7
+ const names = graph => graph . nodes . map ( node => short ( node . props ) ) . sort ( )
8
+ const relations = graph => graph . rels . map ( rel => `${ nameof ( graph , rel . from ) } -> ${ nameof ( graph , rel . to ) } ` ) . sort ( )
5
9
6
10
// Tests for copying subtrees from this sample input
7
11
@@ -24,5 +28,32 @@ const input = await Graph.fetch(url)
24
28
25
29
Deno . test ( "We have expected input" , async ( ) => {
26
30
assertEquals ( input . nodes . length , 7 ) ;
27
- assertEquals ( input . rels . length , 5 )
31
+ assertEquals ( input . rels . length , 5 ) ;
32
+ assertEquals ( names ( input ) , [ "Indexing" , "Mixing" , "Search" , "Sites" , "Solo" , "Transmission" , "Watch" , ] ) ;
33
+ assertEquals ( relations ( input ) , [ "Mixing -> Transmission" , "Mixing -> Watch" , "Search -> Sites" , "Search -> Solo" , "Transmission -> Mixing" ] ) ;
34
+ } ) ;
35
+ Deno . test ( "We have right nodes and rels in a copy" , async ( ) => {
36
+ const cluster = new Graph ( )
37
+ input . copy ( 0 , cluster )
38
+ assertEquals ( names ( cluster ) , [ "Mixing" , "Transmission" , "Watch" , ] ) ;
39
+ assertEquals ( relations ( cluster ) , [ "Mixing -> Transmission" , "Mixing -> Watch" , "Transmission -> Mixing" ] ) ;
40
+ } ) ;
41
+ Deno . test ( "We have aliased props in the copy" , async ( ) => {
42
+ const local = Graph . load ( JSON . parse ( input . stringify ( ) ) )
43
+ assertEquals ( names ( local ) , [ "Indexing" , "Mixing" , "Search" , "Sites" , "Solo" , "Transmission" , "Watch" ] ) ;
44
+ const cluster = new Graph ( )
45
+ local . copy ( 0 , cluster )
46
+ cluster . nodes [ 0 ] . props . name = 'Hello'
47
+ assertEquals ( names ( cluster ) , [ "Hello" , "Transmission" , "Watch" ] ) ;
48
+ assertEquals ( names ( local ) , [ "Hello" , "Indexing" , "Search" , "Sites" , "Solo" , "Transmission" , "Watch" ] ) ;
49
+ } ) ;
50
+ Deno . test ( "We don't have aliased relations in the copy" , async ( ) => {
51
+ const local = Graph . load ( JSON . parse ( input . stringify ( ) ) )
52
+ const cluster = new Graph ( )
53
+ local . copy ( 0 , cluster )
54
+ cluster . addRel ( "" , 0 , cluster . addNode ( "Page" , { name :"Good Bye" } ) )
55
+ assertEquals ( names ( local ) , [ "Indexing" , "Mixing" , "Search" , "Sites" , "Solo" , "Transmission" , "Watch" ] ) ;
56
+ assertEquals ( names ( cluster ) , [ "Good Bye" , "Mixing" , "Transmission" , "Watch" ] ) ;
57
+ assertEquals ( relations ( local ) , [ "Mixing -> Transmission" , "Mixing -> Watch" , "Search -> Sites" , "Search -> Solo" , "Transmission -> Mixing" ] ) ;
58
+ assertEquals ( relations ( cluster ) , [ "Mixing -> Good Bye" , "Mixing -> Transmission" , "Mixing -> Watch" , "Transmission -> Mixing" ] ) ;
28
59
} ) ;
0 commit comments