Skip to content

Commit d9d5461

Browse files
committed
Add test for pgSphere output precision with different settings
expected/output_precision.out - PG 10-11 expected/output_precision_1.out - PG 12+
1 parent c2116ae commit d9d5461

File tree

4 files changed

+508
-1
lines changed

4 files changed

+508
-1
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ DATA_built = $(RELEASE_SQL) \
4040
DOCS = README.pg_sphere COPYRIGHT.pg_sphere
4141
TESTS = version tables points euler circle line ellipse poly path box \
4242
index contains_ops contains_ops_compat bounding_box_gist gnomo \
43-
epochprop contains overlaps spoint_brin sbox_brin selectivity knn
43+
epochprop contains overlaps spoint_brin sbox_brin selectivity \
44+
knn output_precision
4445
REGRESS = init $(TESTS)
4546

4647
PG_CFLAGS += -DPGSPHERE_VERSION=$(PGSPHERE_VERSION)

expected/output_precision.out

+212
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
--
2+
-- Test default and custom output precisions for double values.
3+
--
4+
SELECT set_sphere_output( 'RAD' );
5+
set_sphere_output
6+
-------------------
7+
SET RAD
8+
(1 row)
9+
10+
--
11+
-- Check default precision
12+
--
13+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
14+
spoint
15+
------------------------------------------
16+
(0.272707695624114 , 0.0181805130416076)
17+
(1 row)
18+
19+
--
20+
-- Check option extra_float_digits
21+
--
22+
SET extra_float_digits TO -6;
23+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
24+
spoint
25+
-----------------------------
26+
(0.272707696 , 0.018180513)
27+
(1 row)
28+
29+
SET extra_float_digits TO -2;
30+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
31+
spoint
32+
--------------------------------------
33+
(0.2727076956241 , 0.01818051304161)
34+
(1 row)
35+
36+
SET extra_float_digits TO 0;
37+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
38+
spoint
39+
------------------------------------------
40+
(0.272707695624114 , 0.0181805130416076)
41+
(1 row)
42+
43+
SET extra_float_digits TO 1;
44+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
45+
spoint
46+
------------------------------------------
47+
(0.272707695624114 , 0.0181805130416076)
48+
(1 row)
49+
50+
SET extra_float_digits TO 2;
51+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
52+
spoint
53+
----------------------------------------------
54+
(0.27270769562411401 , 0.018180513041607602)
55+
(1 row)
56+
57+
SET extra_float_digits TO 3;
58+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
59+
spoint
60+
-----------------------------------------------
61+
(0.27270769562411401 , 0.0181805130416076016)
62+
(1 row)
63+
64+
SET extra_float_digits TO 6;
65+
ERROR: 6 is outside the valid range for parameter "extra_float_digits" (-15 .. 3)
66+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
67+
spoint
68+
-----------------------------------------------
69+
(0.27270769562411401 , 0.0181805130416076016)
70+
(1 row)
71+
72+
--
73+
-- Check compatibility behaviour
74+
--
75+
SELECT set_sphere_output_precision(10);
76+
set_sphere_output_precision
77+
-----------------------------
78+
SET 10
79+
(1 row)
80+
81+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
82+
spoint
83+
--------------------------------
84+
(0.2727076956 , 0.01818051304)
85+
(1 row)
86+
87+
SELECT set_sphere_output_precision(12);
88+
set_sphere_output_precision
89+
-----------------------------
90+
SET 12
91+
(1 row)
92+
93+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
94+
spoint
95+
------------------------------------
96+
(0.272707695624 , 0.0181805130416)
97+
(1 row)
98+
99+
SELECT set_sphere_output_precision(15);
100+
set_sphere_output_precision
101+
-----------------------------
102+
SET 15
103+
(1 row)
104+
105+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
106+
spoint
107+
------------------------------------------
108+
(0.272707695624114 , 0.0181805130416076)
109+
(1 row)
110+
111+
SELECT set_sphere_output_precision(17);
112+
set_sphere_output_precision
113+
-----------------------------
114+
SET 15
115+
(1 row)
116+
117+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
118+
spoint
119+
------------------------------------------
120+
(0.272707695624114 , 0.0181805130416076)
121+
(1 row)
122+
123+
SELECT set_sphere_output_precision(20);
124+
set_sphere_output_precision
125+
-----------------------------
126+
SET 15
127+
(1 row)
128+
129+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
130+
spoint
131+
------------------------------------------
132+
(0.272707695624114 , 0.0181805130416076)
133+
(1 row)
134+
135+
SELECT set_sphere_output_precision(0);
136+
set_sphere_output_precision
137+
-----------------------------
138+
SET 15
139+
(1 row)
140+
141+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
142+
spoint
143+
------------------------------------------
144+
(0.272707695624114 , 0.0181805130416076)
145+
(1 row)
146+
147+
SELECT set_sphere_output_precision(-3);
148+
set_sphere_output_precision
149+
-----------------------------
150+
SET 15
151+
(1 row)
152+
153+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
154+
spoint
155+
------------------------------------------
156+
(0.272707695624114 , 0.0181805130416076)
157+
(1 row)
158+
159+
--
160+
-- Check extra_float_digits after set_sphere_output_precision.
161+
-- The change of extra_float_digits should not affect the precision of pgsphere
162+
-- output because set_sphere_output_precision enables compatibility mode.
163+
--
164+
SELECT set_sphere_output_precision(10);
165+
set_sphere_output_precision
166+
-----------------------------
167+
SET 10
168+
(1 row)
169+
170+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
171+
spoint
172+
--------------------------------
173+
(0.2727076956 , 0.01818051304)
174+
(1 row)
175+
176+
SET extra_float_digits TO -6;
177+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
178+
spoint
179+
--------------------------------
180+
(0.2727076956 , 0.01818051304)
181+
(1 row)
182+
183+
SET extra_float_digits TO -10;
184+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
185+
spoint
186+
--------------------------------
187+
(0.2727076956 , 0.01818051304)
188+
(1 row)
189+
190+
--
191+
-- Check reset_sphere_output_precision.
192+
-- It should disable compatibility mode - extra_float_digits should work.
193+
--
194+
SELECT reset_sphere_output_precision();
195+
reset_sphere_output_precision
196+
-------------------------------
197+
RESET
198+
(1 row)
199+
200+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
201+
spoint
202+
----------------------
203+
(0.27271 , 0.018181)
204+
(1 row)
205+
206+
SET extra_float_digits TO -6;
207+
SELECT '( 1h 2m 30s , +1d 2m 30s)'::spoint;
208+
spoint
209+
-----------------------------
210+
(0.272707696 , 0.018180513)
211+
(1 row)
212+

0 commit comments

Comments
 (0)