-
Notifications
You must be signed in to change notification settings - Fork 3
/
aggregate_test.go
94 lines (79 loc) · 2.13 KB
/
aggregate_test.go
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
package stdlib
import "testing"
func Test_stddev(t *testing.T) {
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"INSERT INTO x VALUES (1), (2)",
"SELECT stddev_pop(n) FROM x",
}, "0.5")
}
func Test_mode(t *testing.T) {
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"INSERT INTO x VALUES (1), (2), (2)",
"SELECT mode(n) FROM x",
}, "2")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n TEXT)",
"INSERT INTO x VALUES ('a'), ('b'), ('a')",
"SELECT mode(n) FROM x",
}, "a")
}
func Test_median(t *testing.T) {
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"INSERT INTO x VALUES (1), (2), (2)",
"SELECT median(n) FROM x",
}, "2")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"INSERT INTO x VALUES (1), (2), (3)",
"SELECT median(n) FROM x",
}, "2")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"INSERT INTO x VALUES (1)",
"SELECT median(n) FROM x",
}, "1")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"SELECT coalesce(median(n), 'null') FROM x",
}, "null")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n TEXT)",
"INSERT INTO x VALUES ('a'), ('b'), ('a'), ('c'), ('d')",
"SELECT median(n) FROM x",
}, "b")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n TEXT)",
"INSERT INTO x VALUES (null), (null)",
"SELECT coalesce(median(n), 'null') FROM x",
}, "null")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n REAL)",
"INSERT INTO x VALUES (1.2), (3.4), (4.4)",
"SELECT median(n) FROM x",
}, "3.4")
}
func Test_percentile(t *testing.T) {
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"INSERT INTO x VALUES (1), (3), (4)",
"SELECT perc_50(n) FROM x",
}, "3")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"INSERT INTO x VALUES (5), (2), (4)",
"SELECT perc(n, 75) FROM x",
}, "5")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"INSERT INTO x VALUES (1), (3), (4)",
"SELECT perc_cont_50(n) FROM x",
}, "2")
assertQueryPrepare(t, []string{
"CREATE TABLE x (n INT)",
"INSERT INTO x VALUES (5), (2), (4)",
"SELECT perc_cont(n, 75) FROM x",
}, "4.25")
}