package org.forkalsrud.util;

import java.util.Arrays;
import java.util.List;

import org.forkalsrud.util.VpTree.Metric;
import static org.junit.Assert.*;
import org.junit.Test;

public class VpTreeTest {

    @Test
    public void testSearch() {
        
        double epsilon = 0.0003d;
        
        VpTree<Integer> vp = new VpTree<Integer>(Arrays.asList(4, 1, 7, 2, 9, 3, 5), new Metric<Integer>() {

            @Override
            public double distance(Integer a, Integer b) {
                return Math.abs(b - a);
            }
            
        });
        
        
        List<VpTree<Integer>.WithDistance> result = vp.search(6, 3);
        assertEquals(3, result.size());
        assertEquals(1d, result.get(0).getDistance(), epsilon);
        assertEquals(1d, result.get(1).getDistance(), epsilon);
        assertEquals(2d, result.get(2).getDistance(), epsilon);
    }

}
