package Ġinfo . k fg odel . sandbox . d graph . impl Ċ Ċ import Ġinfo . k fg odel . js pe k . api . Java Spec Runner Ċ import Ġinfo . k fg odel . js pe k . api . Kotlin Spec Ċ import Ġorg . assertj . core . api . Assertions . assertThat Ċ import Ġorg . junit . runner . RunWith Ċ import Ġjava . util . stream . Stream Ċ Ċ /** Ċ Ġ* ĠTest Ġthe Ġbasic ĠDi Graph Ġinterface Ċ Ġ* ĠDate : Ġ 2 2 / 0 4 / 2 1 Ġ- Ġ 0 0 : 3 2 Ċ Ġ*/ Ċ @ RunWith ( Java Spec Runner :: class ) Ċ class ĠDefault Graph Test Ġ: ĠKotlin Spec () Ġ{ ĊĊĠ Ġoverride Ġfun Ġdefine () Ġ{ ĊĠĠĠ Ġdescribe (" a ĠD Graph ") Ġ{ ĊĠĠĠĠĠ Ġval Ġgraph Ġby Ġlet Ġ{ ĠDefault Graph () Ġ} ĊĊĠĠĠĠĠ Ġit (" is Ġcreated Ġwithout Ġnodes Ġor Ġedges ") Ġ{ ĊĠĠĠĠĠĠĠ ĠassertThat ( graph (). nodes () Ġas ĠStream < *> ). isEmpty () ĊĠĠĠĠĠĠĠ ĠassertThat ( graph (). edges () Ġas ĠStream < *> ). isEmpty () ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġdescribe (" node ") Ġ{ ĊĠĠĠĠĠĠĠ Ġit (" is Ġcreated Ġto Ġrepresent Ġan Ġobject Ġin Ġthe Ġgraph ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġcreated Node Ġ= Ġgraph (). getNode For (" an Ġobject ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( graph (). nodes () Ġas ĠStream < *> ). contains ( created Node ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" is Ġreused Ġwhen Ġrepresenting Ġequal Ġobjects ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġfirst Node Ġ= Ġgraph (). getNode For ( StringBuilder (" a Ġdifferent Ġobject "). toString ()) ĊĠĠĠĠĠĠĠĠĠ Ġval Ġsecond Node Ġ= Ġgraph (). getNode For ( StringBuilder (" a Ġdifferent Ġobject "). toString ()) ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( first Node ). is Same As ( second Node ) ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( graph (). nodes () Ġas ĠStream < *> ). has Size ( 1 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġdescribe (" edge ") Ġ{ ĊĠĠĠĠĠĠĠ Ġit (" is Ġcreated Ġto Ġrepresent Ġa Ġdirected Ġlink Ġfrom Ġone Ġobject Ġto Ġother , Ġwith Ġan Ġedge Ġtype Ġdefined Ġby Ġa Ġthird Ġobject ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġcreated Edge Ġ= Ġgraph (). get Edge From (" A ", Ġ" Ġto Ġ", Ġ" B ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( graph (). edges () Ġas ĠStream < *> ). contains ( created Edge ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" is Ġreused Ġwhen Ġrepresenting Ġequal Ġlink ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġfirst Edge Ġ= Ġgraph (). get Edge From (" A ", Ġ" Ġto Ġ", Ġ" B ") ĊĠĠĠĠĠĠĠĠĠ Ġval Ġsecond Edge Ġ= Ġgraph (). get Edge From (" A ", Ġ" Ġto Ġ", Ġ" B ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( first Edge ). is Same As ( second Edge ) ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( graph (). edges () Ġas ĠStream < *> ). has Size ( 1 ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" may Ġimplicitly Ġcreate Ġnodes Ġfor Ġeach Ġlinked Ġobject ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġcreated Edge Ġ= Ġgraph (). get Edge From (" A ", Ġ" Ġto Ġ", Ġ" B ") ĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( graph (). nodes () Ġas ĠStream < *> ). contains ( created Edge . source , Ġcreated Edge . type , Ġcreated Edge . target ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġit (" has Ġa Ġstring Ġrepresentation Ġusing Ġthe Ġedges Ġand Ġun connected Ġnodes ") Ġ{ ĊĠĠĠĠĠĠĠ Ġgraph (). get Edge From (" A ", Ġ" B ", Ġ" C ") ĊĠĠĠĠĠĠĠ Ġgraph (). get Edge From (" A ", Ġ" B ", Ġ" D ") ĊĠĠĠĠĠĠĠ Ġgraph (). getNode For (" E ") ĊĊĠĠĠĠĠĠĠ ĠassertThat ( graph (). toString ()). isEqualTo ("{ A -[ B ]-> C ,\ n " Ġ+ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" A -[ B ]-> D , ĠE }") ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġdescribe (" equality ") Ġ{ ĊĠĠĠĠĠĠĠ ĠbeforeEach Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġgraph (). get Edge From (" A ", Ġ" is ", Ġ" B ") ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" is Ġdefined Ġby Ġits Ġcontents Ġ( nodes Ġand Ġedges )") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġother Graph Ġ= ĠDefault Graph () ĊĠĠĠĠĠĠĠĠĠ Ġother Graph . get Edge From (" A ", Ġ" is ", Ġ" B ") ĊĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( graph ()). isEqualTo ( other Graph ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" diff ers Ġif Ġnodes Ġdon 't Ġmatch ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġextra Node Graph Ġ= ĠDefault Graph () ĊĠĠĠĠĠĠĠĠĠ Ġextra Node Graph . get Edge From (" A ", Ġ" is ", Ġ" B ") ĊĠĠĠĠĠĠĠĠĠ Ġextra Node Graph . getNode For (" extra Ġnode ") ĊĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( graph ()). isNot EqualTo ( extra Node Graph ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġit (" diff ers Ġif Ġedges Ġdon 't Ġmatch ") Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġinverted Graph Ġ= ĠDefault Graph () ĊĠĠĠĠĠĠĠĠĠ Ġinverted Graph . get Edge From (" B ", Ġ" is ", Ġ" A ") ĊĊĠĠĠĠĠĠĠĠĠ ĠassertThat ( graph ()). isNot EqualTo ( inverted Graph ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ } Ċ