import { EdgeDupeChecker , PotentialEdgeInfo } from "@/io/common/Dupes" ; import { IBaseEdge , BaseEdge } from "@/core/base/BaseEdge" ; import { IGraph } from "@/core/base/BaseGraph" ; import { ITypedEdge , TypedEdge } from "@/core/typed/TypedEdge" ; import { ITypedNode , TypedNode } from "@/core/typed/TypedNode" ; import { TypedGraph } from "@/core/typed/TypedGraph" ; import { Logger } from "@/utils/Logger" ; const logger = new Logger ( ) ; import * as uuid from "uuid" ; const v4 = uuid . v4 ; todo describe ( "Edge DUPE tests" , function ( ) { enum relations { LIKES = "likes" , DRINKS = "drinks" , COLOCATED = "colocated" , WORKS_AT = "works_at" , CLEANS = "cleans" , RAN_OUT_OF = "ran_out_of" } const nodeTypeA = "PERSON" , nodeTypeB = "COFFEE" , nodeTypeC = "PERSON" , nodeTypeD = "OFFICE" ; let edc , a , b , c , d , e_1 , e_2 , graph ; /**
     * build a skeleton test graph
     */ beforeEach ( ( ) => { graph = new TypedGraph ( "Duplius Testus" ) ; edc = new EdgeDupeChecker ( graph ) ; a = graph . addNode ( new TypedNode ( "A" , { type : nodeTypeA } ) ) ; b = graph . addNode ( new TypedNode ( "B" , { type : nodeTypeB } ) ) ; c = graph . addNode ( new TypedNode ( "C" , { type : nodeTypeC } ) ) ; d = graph . addNode ( new TypedNode ( "D" , { type : nodeTypeD } ) ) ; } ) ; description description describe ( "same endpoints? - " , function ( ) { it ( "endpoints are completely different (same direction type)" , ( ) => { e_2 = graph . addEdgeByNodeIDs ( v4 ( ) , c . id , d . id , { directed : true } ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; todo it ( "endpoints are completely different (different direction type)" , ( ) => { e_2 = graph . addEdgeByNodeIDs ( v4 ( ) , c . id , d . id ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; it ( "only one endpoint is the same (a, same direction type)" , ( ) => { e_2 = graph . addEdgeByNodeIDs ( v4 ( ) , a . id , d . id , { directed : true } ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; todo it ( "only one endpoint is the same (a, different direction type)" , ( ) => { e_2 = graph . addEdgeByNodeIDs ( v4 ( ) , a . id , d . id ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; it ( "only one endpoint is the same (b, same direction type)" , ( ) => { e_2 = graph . addEdgeByNodeIDs ( v4 ( ) , c . id , a . id , { directed : true } ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; todo it ( "only one endpoint is the same (b, different direction type)" , ( ) => { e_2 = graph . addEdgeByNodeIDs ( v4 ( ) , c . id , a . id ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; it ( "same endpoints, but undirected & directed edges can never be dupes " , ( ) => { e_2 = graph . addEdgeByNodeIDs ( v4 ( ) , a . id , b . id , { directed : true } ) ; const newEdgeInfo = { a , b , dir : false , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; it ( "same endpoints, undirected & directed edges can never be dupes (reversed direction)" , ( ) => { e_1 = graph . addEdgeByNodeIDs ( v4 ( ) , b . id , a . id , { directed : true } ) ; const newEdgeInfo = { a , b , dir : false , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; it ( "same endpoints, both directed, but reversed direction" , ( ) => { e_1 = graph . addEdgeByNodeIDs ( v4 ( ) , b . id , a . id , { directed : true } ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; it ( "same endpoints, both directed, but reversed direction" , ( ) => { e_1 = graph . addEdgeByNodeIDs ( v4 ( ) , a . id , b . id , { directed : true } ) ; const newEdgeInfo = { a : b , b : a , dir : true , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( ) ) ; } ) ; } ) ; /**
     * Same endpoints - check sets
     */ it ( "same endpoints, both directed & same direction" , ( ) => { e_1 = graph . addEdgeByNodeIDs ( v4 ( ) , a . id , b . id , { directed : true } ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( [ e_1 ] ) ) ; } ) ; it ( "same endpoints, both UNdirected" , ( ) => { e_1 = graph . addEdgeByNodeIDs ( v4 ( ) , a . id , b . id ) ; const newEdgeInfo = { a , b , dir : false , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( [ e_1 ] ) ) ; } ) ; todo it ( "same endpoints, both UNdirected" , ( ) => { e_1 = graph . addEdgeByNodeIDs ( v4 ( ) , b . id , a . id ) ; const newEdgeInfo = { a , b , dir : false , weighted : false , typed : false , } ; expect ( edc . potentialEndpoints ( newEdgeInfo ) ) . toEqual ( new Set ( [ e_1 ] ) ) ; } ) ; description describe ( "weighted & typed? - " , function ( ) { it ( "weighted & unweighted cannot be dupes" , ( ) => { e_1 = graph . addEdge ( new TypedEdge ( v4 ( ) , a , b , { weighted : true } ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( EdgeDupeChecker . checkTypeWeightEquality ( newEdgeInfo , e_1 ) ) . toBe ( false ) ; } ) ; it ( "weighted & unweighted cannot be dupes (reversed)" , ( ) => { e_1 = graph . addEdge ( new TypedEdge ( v4 ( ) , a , b , { weighted : false } ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : true , typed : false , } ; expect ( EdgeDupeChecker . checkTypeWeightEquality ( newEdgeInfo , e_1 ) ) . toBe ( false ) ; } ) ; description it ( "typed & untyped cannot be dupes (both weighted)" , ( ) => { e_1 = graph . addEdge ( new BaseEdge ( v4 ( ) , a , b , { weighted : true } ) ) ; logger . log ( BaseEdge . isTyped ( e_1 ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : true , typed : true , } ; expect ( EdgeDupeChecker . checkTypeWeightEquality ( newEdgeInfo , e_1 ) ) . toBe ( false ) ; } ) ; it ( "typed & untyped cannot be dupes (both UNweighted)" , ( ) => { e_1 = graph . addEdge ( new BaseEdge ( v4 ( ) , a , b ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : true , } ; expect ( EdgeDupeChecker . checkTypeWeightEquality ( newEdgeInfo , e_1 ) ) . toBe ( false ) ; } ) ; it ( "both weighted & typed => DUPE" , ( ) => { e_1 = graph . addEdge ( new TypedEdge ( v4 ( ) , a , b , { weighted : true } ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : true , typed : true , } ; expect ( EdgeDupeChecker . checkTypeWeightEquality ( newEdgeInfo , e_1 ) ) . toBe ( true ) ; } ) ; } ) ; it ( "NO Type & no weight to distinguish -> DUPES - " , ( ) => { e_1 = graph . addEdge ( new BaseEdge ( v4 ( ) , a , b , { directed : true , weighted : false } ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : false , typed : false , } ; expect ( edc . isDupe ( newEdgeInfo ) ) . toBe ( true ) ; } ) ; it ( "NO Type & same weight -> DUPES - " , ( ) => { e_1 = graph . addEdge ( new BaseEdge ( v4 ( ) , a , b , { directed : true , weighted : true , weight : 42 } ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : true , weight : 42 , typed : false , } ; expect ( edc . isDupe ( newEdgeInfo ) ) . toBe ( true ) ; } ) ; it ( "NO Type & NOT same weight -> NO DUPES - " , ( ) => { e_1 = graph . addEdge ( new BaseEdge ( v4 ( ) , a , b , { directed : true , weighted : true , weight : 41 } ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : true , weight : 42 , typed : false , } ; expect ( edc . isDupe ( newEdgeInfo ) ) . toBe ( false ) ; } ) ; it ( "Typed & SAME type -> DUPES - " , ( ) => { e_1 = graph . addEdge ( new TypedEdge ( v4 ( ) , a , b , { directed : true , type : relations . LIKES , weighted : true , weight : 42 , } ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : true , weight : 42 , typed : true , type : relations . LIKES , } ; expect ( edc . isDupe ( newEdgeInfo ) ) . toBe ( true ) ; } ) ; it ( "Typed & NOT same type -> NO DUPES - " , ( ) => { e_1 = graph . addEdge ( new TypedEdge ( v4 ( ) , a , b , { directed : true , type : relations . LIKES , weighted : true , weight : 42 , } ) ) ; const newEdgeInfo = { a , b , dir : true , weighted : true , weight : 42 , typed : true , type : relations . WORKS_AT , } ; expect ( edc . isDupe ( newEdgeInfo ) ) . toBe ( false ) ; } ) ; } ) ;