### ----------------------------------------------------
### -- Geo::Basic
### -- Licenses: Artistic-1.0-Perl
### -- Authors: Brian Duggan
### -- File: t/01-geohash.rakutest
### ----------------------------------------------------
#!raku

use Geo::Basic;
use Test;

# examples are all from https://rosettacode.org/wiki/Geohash#Raku
for 51.433718,   -0.214126,  2, 'gc',                "Ireland, most of England and Wales, small part of Scotland",
    51.433718,   -0.214126,  9, 'gcpue5hp4',         "the umpire's chair on Center Court at Wimbledon",
    51.433718,   -0.214126, 17, 'gcpue5hp4ebnf8unc', "likely an individual molecule of the chair",
    57.649110,   10.407440, 11, 'u4pruydqqvj',       "Wikipedia test value - Råbjerg Mile in Denmark",
    59.358639,   24.744778,  7, 'ud99ejf',           "Lake Raku in Estonia",
    29.2021188, 81.5324561,  7, 'tv1ypk4',           "Village Raku in Nepal"
  -> $lat, $lon, $precision, $hash, $desc {
     my $enc = geohash-encode :$lat, :$lon, :$precision;
     is $enc, $hash, "encoded $desc to $hash"; 
     my $dec = geohash-decode($enc);
     my $lat-accuracy = abs($dec<lat-max> - $dec<lat-min>)/2;
     ok $lat - $lat-accuracy <= (($dec<lat-min> + $dec<lat-max>) / 2) <= $lat + $lat-accuracy, "lat is within $lat-accuracy of $lat";
     my $lon-accuracy = abs($dec<lon-max> - $dec<lon-min>)/2;
     ok $lon - $lon-accuracy <= (($dec<lon-min> + $dec<lon-max>) / 2) <= $lon + $lon-accuracy, "lon is within $lon-accuracy of $lon";
}

done-testing;



