### ----------------------------------------------------
### -- Math::Nearest
### -- Licenses: Artistic-2.0
### -- Authors: Anton Antonov
### -- File: xt/11-Same-NNs-for-words-hamming.rakutest
### ----------------------------------------------------
use v6.d;
use Test;

use lib <. lib>;
use Math::Nearest;

my @words = (('a'..'k').pick(4).join xx 30).unique;
say @words;

my $distance-function = 'hamming-distance';
my &nScan = nearest(@words, :$distance-function, method => 'Scan');
my &nKDTree = nearest(@words, :$distance-function, method => 'KDTree');

## 1
# Sometimes passes, sometimes fails.
my $word1 = @words.head;
say (:$word1);
say &nScan($word1, 3, prop => <distance>);
say &nKDTree($word1, 3, prop => <distance>);
is &nKDTree($word1, 3, prop => <distance>), &nScan($word1, 3, prop => <distance>);

## 2
# Always fails with Scan retrieving larger set of words.
my $word2 = 'aabk';
say (:$word2);
say &nScan($word2, (Whatever, 3), prop => <point distance>);
say &nKDTree($word2, (Whatever, 3.1), prop => <point distance>);
is &nKDTree($word2, (Whatever, 3)).sort, &nScan($word2, (Whatever, 3)).sort;


done-testing;


