Implement replace edge operation and cover it with tests.