public function testClosestNodes() { $zeros = str_repeat('00', N / 8); $node_array = []; for ($i = 0; $i < N / 8; $i++) { $id = str_repeat('00', N / 8); $id[2 * $i + 1] = '1'; array_push($node_array, KademliaTestFactory::constructNode(['id' => $id])); } $expected_nearest_node_id = str_repeat('00', N / 8 - 1) . '01'; $expected_second_nearest_node_id = str_repeat('00', N / 8 - 2) . '0100'; shuffle($node_array); $node_list = new Kademlia\NodeList($node_array); $two_closest_nodes = $node_list->closestNodes($zeros, 2)->toArray(); $nearest_node = $two_closest_nodes[0]; $second_nearest_node = $two_closest_nodes[1]; $this->assertNotEqual($nearest_node->idStr(), $second_nearest_node->idStr()); $this->assertEqual($nearest_node->idStr(), $expected_nearest_node_id); $this->assertEqual($second_nearest_node->idStr(), $expected_second_nearest_node_id); }