Graph implementation and tests