[test][algorithms] factor-out common code