mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-07 22:28:47 -04:00
coordinate values may have slight errors since SQLite 3.7.13
This commit is contained in:
parent
efc60c0f19
commit
d3a0be9dfe
1 changed files with 15 additions and 3 deletions
18
t/44_rtree.t
18
t/44_rtree.t
|
@ -11,6 +11,17 @@ use Test::More;
|
||||||
use DBD::SQLite;
|
use DBD::SQLite;
|
||||||
use Data::Dumper;
|
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 = (
|
my @coords = (
|
||||||
# id, minX, maxX, minY, maxY
|
# id, minX, maxX, minY, maxY
|
||||||
[1, 1, 200, 1, 200], # outside bounding box
|
[1, 1, 200, 1, 200], # outside bounding box
|
||||||
|
@ -74,7 +85,7 @@ my $sql = "SELECT * FROM try_rtree WHERE id = ?";
|
||||||
my $idx = 0;
|
my $idx = 0;
|
||||||
for my $id (1..2) {
|
for my $id (1..2) {
|
||||||
my $results = $dbh->selectrow_arrayref($sql, undef, $id);
|
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++;
|
$idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +95,10 @@ SELECT id FROM try_rtree
|
||||||
WHERE minX >= ? AND maxX <= ?
|
WHERE minX >= ? AND maxX <= ?
|
||||||
AND minY >= ? AND maxY <= ?
|
AND minY >= ? AND maxY <= ?
|
||||||
|
|
||||||
|
# Since SQLite 3.7.13, coordinate values may have slight errors.
|
||||||
for my $region (@test_regions) {
|
for my $region (@test_regions) {
|
||||||
my $results = $dbh->selectcol_arrayref($contained_sql, undef, @$region);
|
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
|
# find overlapping regions
|
||||||
|
@ -97,5 +109,5 @@ SELECT id FROM try_rtree
|
||||||
|
|
||||||
for my $region (@test_regions) {
|
for my $region (@test_regions) {
|
||||||
my $results = $dbh->selectcol_arrayref($overlap_sql, undef, @$region);
|
my $results = $dbh->selectcol_arrayref($overlap_sql, undef, @$region);
|
||||||
is_deeply($results, shift @test_results);
|
is_deeply_approx($results, shift @test_results);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue