import { JSON_DATA_PATH } from "_/config/test_paths" ; import { BaseGraph , IGraph } from "@/core/base/BaseGraph" ; import { ComputeGraph , IComputeGraph } from "@/core/compute/ComputeGraph" ; import { JSONInput } from "@/io/input/JSONInput" ; import { Logger } from "@/utils/Logger" ; const logger = new Logger ( ) ; const tf = require ( "@tensorflow/tfjs-node" ) ; console . log ( tf . getBackend ( ) ) ; /**
 *
 */ describe ( "Clustering coefficient tests - " , ( ) => { const small_graph_file = JSON_DATA_PATH + "/small_graph.json" ; const triangle_graph_file = `${ JSON_DATA_PATH }/triangle_graph.json` ; const triangle_directed = `${ JSON_DATA_PATH }/triangle_directed.json` ; let g = null , cg = null ; beforeEach ( ( ) => { expect ( tf ) . toBeDefined ; } ) ; describe ( "small & triangle graph - " , ( ) => { it ( "triangle Counting should throw an error if not handed a TF handle" , ( ) => { cg = new ComputeGraph ( g ) ; expect ( cg . triangleCount ( ) ) . rejects . toEqual ( new Error ( "Tensorflow & TF matMul function must be present for fast numeric computations." ) ) ; } ) ; it ( "transitivity should throw an error if not handed a TF handle" , ( ) => { cg = new ComputeGraph ( g ) ; expect ( cg . globalCC ( ) ) . rejects . toEqual ( new Error ( "Tensorflow & TF matMul function must be present for fast numeric computations." ) ) ; } ) ; it ( "CC should throw an error if not handed a TF handle" , ( ) => { cg = new ComputeGraph ( g ) ; expect ( cg . localCC ( ) ) . rejects . toEqual ( new Error ( "Tensorflow & TF matMul function must be present for fast numeric computations." ) ) ; } ) ; description describe ( "transitivity UN-directed" , ( ) => { beforeEach ( ( ) => { g = new BaseGraph ( "triangulus" ) ; cg = new ComputeGraph ( g , tf ) ; } ) ; todo it ( "should compute triad counts on small graph " , ( ) => { g = new JSONInput ( { explicit_direction : false , directed : false } ) . readFromJSONFile ( small_graph_file , g ) ; const res = cg . triadCount ( ) ; expect ( res ) . toBe ( 3 ) ; } ) ; it ( "should compute triangle counts on small graph " , done => { g = new JSONInput ( { explicit_direction : false , directed : false } ) . readFromJSONFile ( small_graph_file , g ) ; cg . triangleCount ( ) . then ( res => { expect ( res ) . toBe ( 0 ) ; done ( ) ; } ) ; } ) ; it ( "should compute UNdirected transitivity on small graph " , done => { g = new JSONInput ( ) . readFromJSONFile ( small_graph_file , g ) ; cg . globalCC ( ) . then ( res => { expect ( res ) . toBe ( 0 ) ; done ( ) ; } ) ; } ) ; it ( "should compute triad counts on triangle graph " , ( ) => { g = new JSONInput ( ) . readFromJSONFile ( triangle_graph_file , g ) ; const res = cg . triadCount ( ) ; expect ( res ) . toBe ( 19 ) ; } ) ; todo it ( "should compute triangle counts on triangle graph " , done => { g = new JSONInput ( ) . readFromJSONFile ( triangle_graph_file , g ) ; cg . triangleCount ( ) . then ( res => { expect ( res ) . toBe ( 4 ) ; done ( ) ; } ) ; } ) ; it ( "should compute UNdirected transitivity on triangle graph " , done => { g = new JSONInput ( ) . readFromJSONFile ( triangle_graph_file , g ) ; cg . globalCC ( ) . then ( res => { expect ( res ) . toBe ( 0.631578947368421 ) ; done ( ) ; } ) ; } ) ; } ) ; description description describe ( "transitivity DIRECTED - " , ( ) => { beforeAll ( ( ) => { g = new JSONInput ( { explicit_direction : false , directed : true } ) . readFromJSONFile ( triangle_directed ) ; cg = new ComputeGraph ( g , tf ) ; } ) ; it ( "should compute triad counts on triangle graph " , ( ) => { const res = cg . triadCount ( true ) ; expect ( res ) . toBe ( 10 ) ; } ) ; it ( "should compute triangle counts on triangle graph " , done => { cg . triangleCount ( true ) . then ( res => { expect ( res ) . toBe ( 2 ) ; done ( ) ; } ) ; } ) ; todo it ( "should compute DIRECTED transitivity on triangle graph " , done => { cg . globalCC ( true ) . then ( res => { expect ( res ) . toBe ( 0.6 ) ; done ( ) ; } ) ; } ) ; } ) ; /**
         * Self loops are ignored.
         */ describe ( "clustering coefficient (UN)directed - " , ( ) => { beforeEach ( ( ) => { g = null ; cg = null ; } ) ; it ( "should compute local clustering coefficients per node" , done => { g = new JSONInput ( ) . readFromJSONFile ( triangle_graph_file ) ; cg = new ComputeGraph ( g , tf ) ; const clust_exp = { 0 : 1.0 , 1 : 1.0 , 2 : 0.3 , 3 : 1.0 , 4 : 0 , 5 : 0 } ; cg . localCC ( ) . then ( clust => { expect ( clust ) . toEqual ( clust_exp ) ; done ( ) ; } ) ; } ) ; todo it ( "should compute DIRECTED local clustering coefficients per node" , done => { g = new JSONInput ( { explicit_direction : false , directed : true } ) . readFromJSONFile ( triangle_directed ) ; cg = new ComputeGraph ( g , tf ) ; const clust_exp = { 0 : 1.0 , 1 : 0.6666666666666666 , 2 : 0.2 , 3 : 1.0 , 4 : 0 , 5 : 0 } ; cg . localCC ( true ) . then ( clust => { console . log ( clust ) ; expect ( clust ) . toEqual ( clust_exp ) ; done ( ) ; } ) ; } ) ; } ) ; } ) ; } ) ;