@@ -0,0 +1,2597 @@
+/*%0A * This file is part of ELKI:%0A * Environment for Developing KDD-Applications Supported by Index-Structures%0A *%0A * Copyright (C) 2018%0A * ELKI Development Team%0A *%0A * This program is free software: you can redistribute it and/or modify%0A * it under the terms of the GNU Affero General Public License as published by%0A * the Free Software Foundation, either version 3 of the License, or%0A * (at your option) any later version.%0A *%0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the%0A * GNU Affero General Public License for more details.%0A *%0A * You should have received a copy of the GNU Affero General Public License%0A * along with this program. If not, see %3Chttp://www.gnu.org/licenses/%3E.%0A */%0Apackage de.lmu.ifi.dbs.elki.database.ids;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * Test for KNNList.%0A *%0A * @author Erich Schubert%0A */%0Apublic class KNNListTest %7B%0A  /**%0A   * Test that the knn distance for k &lt; kmax bug does come back.%0A   */%0A  @Test%0A  public void sublist() %7B%0A    double%5B%5D dists = %7B 1., 2., 4., 8., 4., 6., 2., 0., 6., 8., %7D;%0A    DBIDRange range = DBIDFactory.FACTORY.generateStaticDBIDRange(dists.length);%0A    KNNHeap heap = DBIDUtil.newHeap(7);%0A    for(DBIDArrayIter it = range.iter(); it.valid(); it.advance()) %7B%0A      heap.insert(dists%5Bit.getOffset()%5D, it);%0A    %7D%0A    assertEquals(%22Tie @7 not handled correctly.%22, 8, heap.size());%0A    assertEquals(%227NN distance wrong%22, 6., heap.getKNNDistance(), 0.);%0A    KNNList list = heap.toKNNList();%0A    assertEquals(%22Tie @7 not handled correctly.%22, 8, list.size());%0A    assertEquals(%227NN distance wrong%22, 6., list.getKNNDistance(), 0.);%0A    assertEquals(%22Tie @5 not handled correctly.%22, 6, DBIDUtil.subList(list, 5).size());%0A    assertEquals(%226NN distance wrong%22, 4., DBIDUtil.subList(list, 6).getKNNDistance(), 0.);%0A    assertEquals(%225NN distance wrong%22, 4., DBIDUtil.subList(list, 5).getKNNDistance(), 0.);%0A    assertEquals(%224NN distance wrong%22, 2., DBIDUtil.subList(list, 4).getKNNDistance(), 0.);%0A    assertEquals(%223NN distance wrong%22, 2., DBIDUtil.subList(list, 3).getKNNDistance(), 0.);%0A    assertEquals(%222NN distance wrong%22, 1., DBIDUtil.subList(list, 2).getKNNDistance(), 0.);%0A    assertEquals(%221NN distance wrong%22, 0., DBIDUtil.subList(list, 1).getKNNDistance(), 0.);%0A    for(DoubleDBIDListIter it = list.iter(); it.valid(); it.advance()) %7B%0A      assertEquals(%22Distance wrong @%22 + it.getOffset(), dists%5Brange.getOffset(it)%5D, it.doubleValue(), 0.);%0A    %7D%0A  %7D%0A%7D%0A

add unit test for knn sublist bug.