### Question:
Knn extends Algorithm<Knn, Knn.Result> { @Override public Result compute() { HugeObjectArray<NeighborList> neighbors; try (var ignored1 = ProgressTimer.start(this::logOverallTime)) { try (var ignored2 = ProgressTimer.start(this::logInitTime)) { neighbors = this.initializeRandomNeighbors(); } if (neighbors == null) { return new EmptyResult(); } var maxIterations = this.config.maxIterations(); var maxUpdates = (long) Math.ceil(config.sampleRate() * config.topK() * nodeCount); var updateThreshold = (long) Math.floor(this.config.deltaThreshold() * maxUpdates); long updateCount; int iteration = 0; boolean didConverge = false; for (; iteration < maxIterations; iteration++) { int currentIteration = iteration; try (var ignored3 = ProgressTimer.start(took -> logIterationTime(currentIteration, took))) { progressLogger.logMessage("KNN-Graph starting iteration " + iteration + "/" + maxIterations); updateCount = this.iteration(neighbors); progressLogger.logMessage("KNN-Graph ending iteration " + iteration + ": updated " + updateCount + "/" + maxUpdates + " nodes"); } if (updateCount <= updateThreshold) { iteration++; didConverge = true; break; } } return ImmutableResult.of(neighbors, iteration, didConverge); } } Knn(Graph graph, KnnBaseConfig config, KnnContext context);  Knn(
        long nodeCount,
        KnnBaseConfig config,
        SimilarityComputer similarityComputer,
        KnnContext context
    ); long nodeCount(); KnnContext context(); @Override Result compute(); @Override Knn me(); @Override void release();  }### Answer:
@Test void shouldRun() { var knnConfig = ImmutableKnnBaseConfig.builder() .nodeWeightProperty("knn") .topK(1) .build(); var knnContext = ImmutableKnnContext.builder().build(); var knn = new Knn(graph, knnConfig, knnContext); var result = knn.compute(); assertThat(result).isNotNull(); assertThat(result.size()).isEqualTo(3); long nodeAId = idFunction.of("a"); long nodeBId = idFunction.of("b"); long nodeCId = idFunction.of("c"); assertCorrectNeighborList(result, nodeAId, nodeBId); assertCorrectNeighborList(result, nodeBId, nodeAId); assertCorrectNeighborList(result, nodeCId, nodeAId); }
@Test void shouldHaveEachNodeConnected() { var knnConfig = ImmutableKnnBaseConfig.builder() .nodeWeightProperty("knn") .topK(2) .build(); var knnContext = ImmutableKnnContext.builder().build(); var knn = new Knn(graph, knnConfig, knnContext); var result = knn.compute(); assertThat(result).isNotNull(); assertThat(result.size()).isEqualTo(3); long nodeAId = idFunction.of("a"); long nodeBId = idFunction.of("b"); long nodeCId = idFunction.of("c"); assertCorrectNeighborList(result, nodeAId, nodeBId, nodeCId); assertCorrectNeighborList(result, nodeBId, nodeAId, nodeCId); assertCorrectNeighborList(result, nodeCId, nodeAId, nodeBId); }