-
Notifications
You must be signed in to change notification settings - Fork 6
/
unit-test.sql
108 lines (95 loc) · 5.04 KB
/
unit-test.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
DROP EXTENSION IF EXISTS pgtap CASCADE;
CREATE EXTENSION pgtap;
DROP EXTENSION IF EXISTS hedb CASCADE;
CREATE EXTENSION hedb;
SELECT enable_client_mode();
\unset ECHO
SELECT plan(48);
SELECT ok('2'::enc_int4 + '1'::enc_int4 = '3'::enc_int4, 'enc_int4: operator +');
SELECT ok('2'::enc_int4 - '1'::enc_int4 = '1'::enc_int4, 'enc_int4: operator -');
SELECT ok('2'::enc_int4 * '2'::enc_int4 = '4'::enc_int4, 'enc_int4: operator *');
SELECT ok('6'::enc_int4 / '2'::enc_int4 = '3'::enc_int4, 'enc_int4: operator /');
SELECT ok('1'::enc_int4 = '1'::enc_int4, 'enc_int4: operator =');
SELECT ok('0'::enc_int4 != '1'::enc_int4, 'enc_int4: operator !=');
SELECT ok('0'::enc_int4 <> '1'::enc_int4, 'enc_int4: operator <>');
SELECT ok('1'::enc_int4 <= '2'::enc_int4, 'enc_int4: operator <=');
SELECT ok('1'::enc_int4 <= '1'::enc_int4, 'enc_int4: operator <=');
SELECT ok('3'::enc_int4 >= '2'::enc_int4, 'enc_int4: operator >=');
SELECT ok('1'::enc_int4 >= '1'::enc_int4, 'enc_int4: operator >=');
SELECT ok('2'::enc_int4 < '3'::enc_int4, 'enc_int4: operator <');
SELECT ok('3'::enc_int4 > '2'::enc_int4, 'enc_int4: operator >');
SELECT ok('2.3'::enc_float4 + '1.1'::enc_float4 = '3.4'::enc_float4, 'enc_float4: operator +');
SELECT ok('2.0'::enc_float4 - '1.1'::enc_float4 = '0.9'::enc_float4, 'enc_float4: operator -');
SELECT ok('2.0'::enc_float4 * '1.1'::enc_float4 = '2.2'::enc_float4, 'enc_float4: operator *');
SELECT ok('9.9'::enc_float4 / '3.3'::enc_float4 = '3'::enc_float4, 'enc_float4: operator /');
SELECT ok('1.1'::enc_float4 = '1.1'::enc_float4, 'enc_float4: operator =');
SELECT ok('0.2'::enc_float4 != '1.1'::enc_float4, 'enc_float4: operator !=');
SELECT ok('0.2'::enc_float4 <> '1.1'::enc_float4, 'enc_float4: operator <>');
SELECT ok('1.1'::enc_float4 <= '2.3'::enc_float4, 'enc_float4: operator <=');
SELECT ok('1.1'::enc_float4 <= '1.1'::enc_float4, 'enc_float4: operator <=');
SELECT ok('3.4'::enc_float4 >= '2.3'::enc_float4, 'enc_float4: operator >=');
SELECT ok('1.1'::enc_float4 >= '1.1'::enc_float4, 'enc_float4: operator >=');
SELECT ok('2.3'::enc_float4 < '3.4'::enc_float4, 'enc_float4: operator <');
SELECT ok('3.4'::enc_float4 > '2.3'::enc_float4, 'enc_float4: operator >');
SELECT ok('11/11/12'::enc_timestamp = '11/11/12'::enc_timestamp, 'enc_timestamp: operator =');
SELECT ok('11/11/12 00:00:01'::enc_timestamp != '11/11/12 00:00:02'::enc_timestamp, 'enc_timestamp: operator !=');
SELECT ok('11/11/12 00:00:01'::enc_timestamp <> '11/11/12 00:00:02'::enc_timestamp, 'enc_timestamp: operator <>');
SELECT ok('11/11/12 00:00:01'::enc_timestamp <= '11/11/12 00:00:01'::enc_timestamp, 'enc_timestamp: operator <=');
SELECT ok('11/11/12 00:00:01'::enc_timestamp <= '11/11/12 00:00:03'::enc_timestamp, 'enc_timestamp: operator <=');
SELECT ok('11/11/12 00:00:01'::enc_timestamp >= '11/11/12 00:00:01'::enc_timestamp, 'enc_timestamp: operator >=');
SELECT ok('11/11/12 00:00:02'::enc_timestamp >= '11/11/12 00:00:01'::enc_timestamp, 'enc_timestamp: operator >=');
SELECT ok('11/11/12 00:00:01'::enc_timestamp < '11/11/12 00:00:03'::enc_timestamp, 'enc_timestamp: operator <');
SELECT ok('11/11/12 00:00:03'::enc_timestamp > '11/11/12 00:00:01'::enc_timestamp, 'enc_timestamp: operator >');
SELECT ok('test1'::enc_text = 'test1'::enc_text, 'enc_text: operator =');
SELECT ok('test1'::enc_text != 'test2'::enc_text, 'enc_text: operator !=');
SELECT ok('test1'::enc_text <> 'test2'::enc_text, 'enc_text: operator <>');
SELECT ok('hello'::enc_text || 'world'::enc_text = 'helloworld'::enc_text, 'enc_text: operator ||');
SELECT ok('edb'::enc_text = substring('hedb'::enc_text, '2'::enc_int4, '3'::enc_int4), 'enc_text: operator substring');
DROP TABLE IF EXISTS test_table;
CREATE TABLE test_table (id int, num_i enc_int4, num_f enc_float4, str enc_text, time enc_timestamp);
INSERT INTO test_table VALUES (1, '1', '1.1', 'hello', '2020-01-01');
INSERT INTO test_table VALUES (2, '2', '2.1', 'world', '2021-01-01');
INSERT INTO test_table VALUES (3, '3', '3.1', 'from', '2022-01-01');
INSERT INTO test_table VALUES (3, '4', '3.1', 'hedb', '2023-01-01');
SELECT results_eq(
'SELECT SUM(num_i) FROM test_table',
$$VALUES ('10'::enc_int4)$$,
'enc_int4: SUM function '
);
SELECT results_eq(
'SELECT AVG(num_i) FROM test_table',
$$VALUES ('2'::enc_int4)$$,
'enc_int4: AVG function (with rounding)'
);
SELECT results_eq(
'SELECT MAX(num_i) FROM test_table',
$$VALUES ('4'::enc_int4)$$,
'enc_int4: MAX function '
);
SELECT results_eq(
'SELECT MIN(num_i) FROM test_table',
$$VALUES ('1'::enc_int4)$$,
'enc_int4: MIN function '
);
SELECT results_eq(
'SELECT SUM(num_f) FROM test_table',
$$VALUES ('9.4'::enc_float4)$$,
'enc_float4: SUM function'
);
SELECT results_eq(
'SELECT AVG(num_f) FROM test_table',
$$VALUES ('2.35'::enc_float4)$$,
'enc_float4: AVG function'
);
SELECT results_eq(
'SELECT MAX(num_f) FROM test_table',
$$VALUES ('3.1'::enc_float4)$$,
'enc_float4: MAX function'
);
SELECT results_eq(
'SELECT MIN(num_f) FROM test_table',
$$VALUES ('1.1'::enc_float4)$$,
'enc_float4: MIN function'
);
SELECT * FROM finish();
DROP TABLE IF EXISTS test_table;