tests for graph. Refactoring