@@ -174,4 +174,48 @@ describe('Graph', () => {
174174 expect ( edges [ 0 ] ) . toEqual ( edgeAB ) ;
175175 expect ( edges [ 1 ] ) . toEqual ( edgeBC ) ;
176176 } ) ;
177+
178+ it ( 'should calculate total graph weight for default graph' , ( ) => {
179+ const graph = new Graph ( ) ;
180+
181+ const vertexA = new GraphVertex ( 'A' ) ;
182+ const vertexB = new GraphVertex ( 'B' ) ;
183+ const vertexC = new GraphVertex ( 'C' ) ;
184+ const vertexD = new GraphVertex ( 'D' ) ;
185+
186+ const edgeAB = new GraphEdge ( vertexA , vertexB ) ;
187+ const edgeBC = new GraphEdge ( vertexB , vertexC ) ;
188+ const edgeCD = new GraphEdge ( vertexC , vertexD ) ;
189+ const edgeAD = new GraphEdge ( vertexA , vertexD ) ;
190+
191+ graph
192+ . addEdge ( edgeAB )
193+ . addEdge ( edgeBC )
194+ . addEdge ( edgeCD )
195+ . addEdge ( edgeAD ) ;
196+
197+ expect ( graph . getWeight ( ) ) . toBe ( 0 ) ;
198+ } ) ;
199+
200+ it ( 'should calculate total graph weight for weighted graph' , ( ) => {
201+ const graph = new Graph ( ) ;
202+
203+ const vertexA = new GraphVertex ( 'A' ) ;
204+ const vertexB = new GraphVertex ( 'B' ) ;
205+ const vertexC = new GraphVertex ( 'C' ) ;
206+ const vertexD = new GraphVertex ( 'D' ) ;
207+
208+ const edgeAB = new GraphEdge ( vertexA , vertexB , 1 ) ;
209+ const edgeBC = new GraphEdge ( vertexB , vertexC , 2 ) ;
210+ const edgeCD = new GraphEdge ( vertexC , vertexD , 3 ) ;
211+ const edgeAD = new GraphEdge ( vertexA , vertexD , 4 ) ;
212+
213+ graph
214+ . addEdge ( edgeAB )
215+ . addEdge ( edgeBC )
216+ . addEdge ( edgeCD )
217+ . addEdge ( edgeAD ) ;
218+
219+ expect ( graph . getWeight ( ) ) . toBe ( 10 ) ;
220+ } ) ;
177221} ) ;
0 commit comments