import * as $G from "@/core/base/BaseGraph" ; import * as $FW from "@/traversal/FloydWarshall" ; import { CSVInput , ICSVInConfig } from "@/io/input/CSVInput" ; import { JSONInput , IJSONInConfig } from "@/io/input/JSONInput" ; import { Logger } from "@/utils/Logger" ; import { GraphStats } from "@/core/interfaces" ; import { CSV_SN_PATH , JSON_DATA_PATH } from "_/config/test_paths" ; const logger = new Logger ( ) ; let social_graph = `${ CSV_SN_PATH }/social_network_edges_1K.csv` ; let search_graph = `${ JSON_DATA_PATH }/search_graph_multiple_SPs.json` ; let bernd_graph = `${ JSON_DATA_PATH }/bernd_ares_pos.json` ; let intermediate = `${ JSON_DATA_PATH }/bernd_ares_intermediate_pos.json` ; let search_graph_pos = `${ JSON_DATA_PATH }/search_graph_multiple_SPs_positive.json` ; const csv_config = { separator : " " , explicit_direction : false , direction_mode : false , weighted : false , } ; const json_in_config = { explicit_direction : true , directed : false , weighted : true , } ; /**
 *
 */ describe ( "GRAPH SEARCH Tests - Floyd-Warshall - " , ( ) => { let json , csv , graph_search , graph_nullcycle , graph_bernd , graph_intermediate , graph_social , stats , FW_res ; beforeAll ( ( ) => { json = new JSONInput ( json_in_config ) ; csv = new CSVInput ( csv_config ) ; graph_search = json . readFromJSONFile ( search_graph_pos ) ; graph_bernd = json . readFromJSONFile ( bernd_graph ) ; graph_nullcycle = json . readFromJSONFile ( search_graph ) ; graph_intermediate = json . readFromJSONFile ( intermediate ) ; graph_social = csv . readFromEdgeListFile ( social_graph ) ; } ) ; test ( "should correctly instantiate the search graph" , ( ) => { stats = graph_search . getStats ( ) ; expect ( stats . nr_nodes ) . toBe ( 6 ) ; expect ( stats . nr_dir_edges ) . toBe ( 12 ) ; expect ( stats . nr_und_edges ) . toBe ( 2 ) ; } ) ; test ( "should refuse to compute FW APSP on empty graph" , ( ) => { let empty_graph = new $G . BaseGraph ( "iamempty" ) ; expect ( $FW . FloydWarshallAPSP . bind ( $FW . FloydWarshallAPSP , empty_graph ) ) . toThrowError ( "Cowardly refusing to traverse graph without edges." ) ; } ) ; test ( "should refuse to compute FW array on empty graph" , ( ) => { let empty_graph = new $G . BaseGraph ( "iamempty" ) ; expect ( $FW . FloydWarshallArray . bind ( $FW . FloydWarshallArray , empty_graph ) ) . toThrowError ( "Cowardly refusing to traverse graph without edges." ) ; } ) ; describe ( "FW on small search graph - " , ( ) => { describe ( "computing distances in UNDIRECTED _mode - " , ( ) => { test ( "should correctly compute distance matrix for graph" , ( ) => { FW_res = $FW . FloydWarshallAPSP ( graph_search ) ; logger . log ( FW_res [ 1 ] ) ; const expected_result = [ [ 0 , 3 , 4 , 1 , 2 , 4 ] , [ 2 , 0 , 1 , 3 , 2 , 1 ] , [ 1 , 4 , 0 , 2 , 1 , 5 ] , [ 7 , 6 , 6 , 0 , 1 , 7 ] , [ 7 , 5 , 6 , 1 , 0 , 6 ] , [ 4 , 7 , 3 , 5 , 4 , 0 ] , ] ; expect ( FW_res [ 0 ] ) . toEqual ( expected_result ) ; } ) ; test ( "should correctly compute distance matrix for graph, Array version" , ( ) => { FW_res = $FW . FloydWarshallArray ( graph_search ) ; const expected_result = [ [ 0 , 3 , 4 , 1 , 2 , 4 ] , [ 2 , 0 , 1 , 3 , 2 , 1 ] , [ 1 , 4 , 0 , 2 , 1 , 5 ] , [ 7 , 6 , 6 , 0 , 1 , 7 ] , [ 7 , 5 , 6 , 1 , 0 , 6 ] , [ 4 , 7 , 3 , 5 , 4 , 0 ] , ] ; expect ( FW_res ) . toEqual ( expected_result ) ; } ) ; } ) ; test ( "75 nodes - FW with and without next should return same distance matrix" , ( ) => { let FW_with_next = $FW . FloydWarshallAPSP ( graph_bernd ) [ 0 ] ; let FW_normal = $FW . FloydWarshallArray ( graph_bernd ) ; expect ( FW_with_next ) . toEqual ( FW_normal ) ; } ) ; } ) ; } ) ; param graph_l param FW_res todo todo