pgvector.git / summary / log / commit / refs
commit 14984a08ea026da283174e00247de9f2b98d2784
Author: Andrew Kane <andrew@ankane.org>
Date: Sat Dec 31 02:54:53 2022 +0000
Improved avg test
test/t/008_avg.pl | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/test/t/008_avg.pl b/test/t/008_avg.pl
index 0cfc2731..e84228a7 100644
--- a/test/t/008_avg.pl
+++ b/test/t/008_avg.pl
@@ -2,7 +2,7 @@ use strict;
use warnings;
use PostgresNode;
use TestLib;
-use Test::More tests => 4;
+use Test::More tests => 5;
# Initialize node
my $node = get_new_node('node');
@@ -13,7 +13,7 @@ $node->start;
$node->safe_psql("postgres", "CREATE EXTENSION vector;");
$node->safe_psql("postgres", "CREATE TABLE tst (v vector(3));");
$node->safe_psql("postgres",
- "INSERT INTO tst SELECT ARRAY[1.01 + random(), 2.01 + random(), 3.01 + random()] FROM generate_series(1, 1000000) i;"
+ "INSERT INTO tst SELECT ARRAY[1.01 + random(), 2.01 + random(), 3.01 + random()] FROM generate_series(1, 1000000) i;"
);
# Test avg
@@ -25,3 +25,12 @@ like($avg, qr/,3\.5/);
# Test explain
my $explain = $node->safe_psql("postgres", "EXPLAIN SELECT AVG(v) FROM tst;");
like($explain, qr/Partial Aggregate/);
+
+# Test matches real
+$node->safe_psql("postgres", "CREATE TABLE tst2 (r real, v vector(1));");
+$node->safe_psql("postgres",
+ "INSERT INTO tst2 SELECT t.r, ARRAY[t.r] FROM (SELECT random() AS r FROM generate_series(1, 1000000) t0) t;"
+);
+my $expected = $node->safe_psql("postgres", "SELECT AVG(r)::float4 FROM tst2;");
+$avg = $node->safe_psql("postgres", "SELECT AVG(v) FROM tst2;");
+is($avg, "[$expected]");
[parent: 30e07a6943c3]