use strict;
use DBI;
use Benchmark;
use Location::GeoTool;
use Location::Area::DoCoMo::iArea;
use Test::More tests => 4;

my $count = 1000;
my @test = map { my ($lat,$lng) = split(/[,\n]/,$_); Location::GeoTool->create_coord($lat,$lng,"tokyo","mapion")->format_degree } <DATA>;

my $dbh = DBI->connect("dbi:Pg:dbname=iareadb", "xxxx", "xxxx");
my $sth = $dbh->prepare("SELECT id FROM iarea WHERE iarea_tokyo && GeomFromText( ?, 4301 ) AND intersects(iarea_tokyo,GeomFromText( ?, 4301 ));");

timethese($count,
   {'TEST1' => '&test1;', 'TEST2' => '&test2;', });

foreach my $obj (@test) {
    is(test1($obj),test2($obj));
}

sub test1 {
    my @loop = @_ ? @_ : @test;
    my $ret;
    foreach my $obj (@loop) {
        my $iobj = Location::Area::DoCoMo::iArea->create_coord($obj);
        $ret = $iobj->id;
    }
    $ret;
}

sub test2 {
    my @loop = @_ ? @_ : @test;
    my $ret;
    foreach my $obj (@loop) {
        $sth->execute(map { "POINT(".$obj->long." ".$obj->lat.")" } (0..1));
        $ret = $sth->fetchrow_hashref->{id};
    }
    $ret;
}

__END__
41/45/58.000,140/43/57.029
26/12/30.726,127/40/51.038
35/39/38.448,139/42/04.550
34/41/26.484,135/30/17.939
