Weighted graph implementation with tests