From d3a0be9dfea6c88073d70f1ea367d0fb87d062b5 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Tue, 4 Sep 2012 17:44:45 +0000 Subject: [PATCH] coordinate values may have slight errors since SQLite 3.7.13 --- t/44_rtree.t | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/t/44_rtree.t b/t/44_rtree.t index ac82a30..3fea4bf 100644 --- a/t/44_rtree.t +++ b/t/44_rtree.t @@ -11,6 +11,17 @@ use Test::More; use DBD::SQLite; use Data::Dumper; +# NOTE: It seems to be better to compare rounded values +# because stored coordinate values may have slight errors +# since SQLite 3.7.13 (DBD::SQLite 1.38_01). + +sub is_deeply_approx { + my ($got, $expected, $name) = @_; + my $got_approx = [map { sprintf "%0.2f", $_ } @$got]; + my $expected_approx = [map { sprintf "%0.2f", $_ } @$expected]; + is_deeply($got_approx, $expected_approx, $name); +} + my @coords = ( # id, minX, maxX, minY, maxY [1, 1, 200, 1, 200], # outside bounding box @@ -74,7 +85,7 @@ my $sql = "SELECT * FROM try_rtree WHERE id = ?"; my $idx = 0; for my $id (1..2) { my $results = $dbh->selectrow_arrayref($sql, undef, $id); - is_deeply($results, $coords[$idx], "Coords for $id match"); + is_deeply_approx($results, $coords[$idx], "Coords for $id match"); $idx++; } @@ -84,9 +95,10 @@ SELECT id FROM try_rtree WHERE minX >= ? AND maxX <= ? AND minY >= ? AND maxY <= ? +# Since SQLite 3.7.13, coordinate values may have slight errors. for my $region (@test_regions) { my $results = $dbh->selectcol_arrayref($contained_sql, undef, @$region); - is_deeply($results, shift @test_results); + is_deeply_approx($results, shift @test_results); } # find overlapping regions @@ -97,5 +109,5 @@ SELECT id FROM try_rtree for my $region (@test_regions) { my $results = $dbh->selectcol_arrayref($overlap_sql, undef, @$region); - is_deeply($results, shift @test_results); + is_deeply_approx($results, shift @test_results); }