Graph reducer and tests for it