### ----------------------------------------------------
### -- Math::Nearest
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: t/02-Finder-as-object.rakutest
### ----------------------------------------------------
use v6.d;
use Test;

use lib <. lib>;

use Math::Nearest;

plan *;

my @points = ([(^100).rand, (^100).rand] xx 100).unique;

## 1
my $finder1;
$finder1 = Math::Nearest::Finder.new(@points);
isa-ok $finder1, Math::Nearest::Finder:D;

## 2
my @searchPoint1 = |@points.head;
is-deeply $finder1.nearest(@searchPoint1).Array, [@searchPoint1,];

## 3
is-deeply $finder1.nearest(@searchPoint1, 3), $finder1.nearest(@searchPoint1, (3, Whatever));

## 4
is-deeply $finder1.nearest(@searchPoint1, 5).sort, $finder1.nearest(@searchPoint1, (5, 60)).sort;

## 5
my $finder2;
$finder2 = Math::Nearest::Finder.new(@points, method => 'Scan');
isa-ok $finder2.finder, Math::Nearest::Scan:D;

## 6
is $finder1.nearest(@searchPoint1), $finder2.nearest(@searchPoint1);

## 7
is $finder1.nearest(@searchPoint1, 12), $finder2.nearest(@searchPoint1, 12);

## 8
is-deeply
        $finder1.nearest(@searchPoint1, (Whatever, 20)).sort,
        $finder2.nearest(@searchPoint1, (Whatever, 20)).sort,
        'Ball';

done-testing;


