Skip to content

Commit 2a77387

Browse files
authored
increase test coverage (#233)
* increase test coverage * add more tests * support more tests
1 parent 2974a67 commit 2a77387

File tree

96 files changed

+5135
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5135
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
export type CountVariantsParams = [];
2+
3+
export interface ICountVariantsResult {
4+
distinctRarityCount: number;
5+
idCount: number;
6+
nonNullRarityCount: number;
7+
totalCount: number;
8+
}
9+
10+
export interface ICountVariantsQuery {
11+
params: CountVariantsParams;
12+
result: ICountVariantsResult;
13+
}
14+
15+
export type SumAndAvgParams = [];
16+
17+
export interface ISumAndAvgResult {
18+
avgId: number;
19+
avgIdRounded: number;
20+
rarity: string | null;
21+
sumId: number;
22+
}
23+
24+
export interface ISumAndAvgQuery {
25+
params: SumAndAvgParams;
26+
result: ISumAndAvgResult;
27+
}
28+
29+
export type MinAndMaxParams = [];
30+
31+
export interface IMinAndMaxResult {
32+
maxId: number;
33+
maxName: number;
34+
minId: number;
35+
minName: number;
36+
rarity: string | null;
37+
}
38+
39+
export interface IMinAndMaxQuery {
40+
params: MinAndMaxParams;
41+
result: IMinAndMaxResult;
42+
}
43+
44+
export type StddevAndVarianceParams = [];
45+
46+
export interface IStddevAndVarianceResult {
47+
rarity: string | null;
48+
stddevId: any;
49+
varianceId: any;
50+
}
51+
52+
export interface IStddevAndVarianceQuery {
53+
params: StddevAndVarianceParams;
54+
result: IStddevAndVarianceResult;
55+
}
56+
57+
export type MultipleAggregatesParams = [];
58+
59+
export interface IMultipleAggregatesResult {
60+
avgId: number;
61+
count: number;
62+
maxId: number;
63+
minId: number;
64+
rarity: string | null;
65+
sumId: number;
66+
}
67+
68+
export interface IMultipleAggregatesQuery {
69+
params: MultipleAggregatesParams;
70+
result: IMultipleAggregatesResult;
71+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
export type CountVariantsParams = [];
2+
3+
export interface ICountVariantsResult {
4+
distinctRarityCount: number;
5+
idCount: number;
6+
nonNullRarityCount: number;
7+
totalCount: number;
8+
}
9+
10+
export interface ICountVariantsQuery {
11+
params: CountVariantsParams;
12+
result: ICountVariantsResult;
13+
}
14+
15+
export type SumAndAvgParams = [];
16+
17+
export interface ISumAndAvgResult {
18+
avgId: number;
19+
avgIdRounded: number;
20+
rarity: string | null;
21+
sumId: number;
22+
}
23+
24+
export interface ISumAndAvgQuery {
25+
params: SumAndAvgParams;
26+
result: ISumAndAvgResult;
27+
}
28+
29+
export type MinAndMaxParams = [];
30+
31+
export interface IMinAndMaxResult {
32+
maxId: number;
33+
maxName: number;
34+
minId: number;
35+
minName: number;
36+
rarity: string | null;
37+
}
38+
39+
export interface IMinAndMaxQuery {
40+
params: MinAndMaxParams;
41+
result: IMinAndMaxResult;
42+
}
43+
44+
export type StddevAndVarianceParams = [];
45+
46+
export interface IStddevAndVarianceResult {
47+
rarity: string | null;
48+
stddevId: any;
49+
varianceId: any;
50+
}
51+
52+
export interface IStddevAndVarianceQuery {
53+
params: StddevAndVarianceParams;
54+
result: IStddevAndVarianceResult;
55+
}
56+
57+
export type MultipleAggregatesParams = [];
58+
59+
export interface IMultipleAggregatesResult {
60+
avgId: number;
61+
count: number;
62+
maxId: number;
63+
minId: number;
64+
rarity: string | null;
65+
sumId: number;
66+
}
67+
68+
export interface IMultipleAggregatesQuery {
69+
params: MultipleAggregatesParams;
70+
result: IMultipleAggregatesResult;
71+
}
72+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { sql } from 'sqlx-ts'
2+
3+
// COUNT variants
4+
const countVariants = sql`
5+
-- @name: count variants
6+
SELECT
7+
COUNT(*) AS total_count,
8+
COUNT(id) AS id_count,
9+
COUNT(DISTINCT rarity) AS distinct_rarity_count,
10+
COUNT(rarity) AS non_null_rarity_count
11+
FROM items
12+
`
13+
14+
// SUM and AVG
15+
const sumAndAvg = sql`
16+
-- @name: sum and avg
17+
SELECT
18+
rarity,
19+
SUM(id) AS sum_id,
20+
AVG(id) AS avg_id,
21+
AVG(id)::INTEGER AS avg_id_rounded
22+
FROM items
23+
GROUP BY rarity
24+
`
25+
26+
// MIN and MAX
27+
const minAndMax = sql`
28+
-- @name: min and max
29+
SELECT
30+
rarity,
31+
MIN(id) AS min_id,
32+
MAX(id) AS max_id,
33+
MIN(name) AS min_name,
34+
MAX(name) AS max_name
35+
FROM items
36+
GROUP BY rarity
37+
`
38+
39+
// STDDEV and VARIANCE
40+
const stddevAndVariance = sql`
41+
-- @name: stddev and variance
42+
SELECT
43+
rarity,
44+
STDDEV(id) AS stddev_id,
45+
VARIANCE(id) AS variance_id
46+
FROM items
47+
GROUP BY rarity
48+
HAVING COUNT(*) > 1
49+
`
50+
51+
// Multiple aggregates combined
52+
const multipleAggregates = sql`
53+
-- @name: multiple aggregates
54+
SELECT
55+
rarity,
56+
COUNT(*) AS count,
57+
SUM(id) AS sum_id,
58+
AVG(id) AS avg_id,
59+
MIN(id) AS min_id,
60+
MAX(id) AS max_id
61+
FROM items
62+
GROUP BY rarity
63+
`
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
export type CountWithFilterParams = [];
2+
3+
export interface ICountWithFilterResult {
4+
countAbove5: number;
5+
countAtOrBelow5: number;
6+
rarity: string | null;
7+
}
8+
9+
export interface ICountWithFilterQuery {
10+
params: CountWithFilterParams;
11+
result: ICountWithFilterResult;
12+
}
13+
14+
export type SumWithFilterParams = [];
15+
16+
export interface ISumWithFilterResult {
17+
rarity: string | null;
18+
sumAbove5: number;
19+
sumAtOrBelow5: number;
20+
}
21+
22+
export interface ISumWithFilterQuery {
23+
params: SumWithFilterParams;
24+
result: ISumWithFilterResult;
25+
}
26+
27+
export type AvgWithFilterParams = [];
28+
29+
export interface IAvgWithFilterResult {
30+
avgAbove5: number;
31+
rarity: string | null;
32+
}
33+
34+
export interface IAvgWithFilterQuery {
35+
params: AvgWithFilterParams;
36+
result: IAvgWithFilterResult;
37+
}
38+
39+
export type MultipleFiltersParams = [];
40+
41+
export interface IMultipleFiltersResult {
42+
countCommon: number;
43+
countLegendary: number;
44+
countRare: number;
45+
countUnknown: number;
46+
}
47+
48+
export interface IMultipleFiltersQuery {
49+
params: MultipleFiltersParams;
50+
result: IMultipleFiltersResult;
51+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
export type CountWithFilterParams = [];
2+
3+
export interface ICountWithFilterResult {
4+
countAbove5: number;
5+
countAtOrBelow5: number;
6+
rarity: string | null;
7+
}
8+
9+
export interface ICountWithFilterQuery {
10+
params: CountWithFilterParams;
11+
result: ICountWithFilterResult;
12+
}
13+
14+
export type SumWithFilterParams = [];
15+
16+
export interface ISumWithFilterResult {
17+
rarity: string | null;
18+
sumAbove5: number;
19+
sumAtOrBelow5: number;
20+
}
21+
22+
export interface ISumWithFilterQuery {
23+
params: SumWithFilterParams;
24+
result: ISumWithFilterResult;
25+
}
26+
27+
export type AvgWithFilterParams = [];
28+
29+
export interface IAvgWithFilterResult {
30+
avgAbove5: number;
31+
rarity: string | null;
32+
}
33+
34+
export interface IAvgWithFilterQuery {
35+
params: AvgWithFilterParams;
36+
result: IAvgWithFilterResult;
37+
}
38+
39+
export type MultipleFiltersParams = [];
40+
41+
export interface IMultipleFiltersResult {
42+
countCommon: number;
43+
countLegendary: number;
44+
countRare: number;
45+
countUnknown: number;
46+
}
47+
48+
export interface IMultipleFiltersQuery {
49+
params: MultipleFiltersParams;
50+
result: IMultipleFiltersResult;
51+
}
52+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { sql } from 'sqlx-ts'
2+
3+
// COUNT with FILTER
4+
const countWithFilter = sql`
5+
-- @name: count with filter
6+
SELECT
7+
rarity,
8+
COUNT(*) FILTER (WHERE id > 5) AS count_above_5,
9+
COUNT(*) FILTER (WHERE id <= 5) AS count_at_or_below_5
10+
FROM items
11+
GROUP BY rarity
12+
`
13+
14+
// SUM with FILTER
15+
const sumWithFilter = sql`
16+
-- @name: sum with filter
17+
SELECT
18+
rarity,
19+
SUM(id) FILTER (WHERE id > 5) AS sum_above_5,
20+
SUM(id) FILTER (WHERE id <= 5) AS sum_at_or_below_5
21+
FROM items
22+
GROUP BY rarity
23+
`
24+
25+
// AVG with FILTER
26+
const avgWithFilter = sql`
27+
-- @name: avg with filter
28+
SELECT
29+
rarity,
30+
AVG(id) FILTER (WHERE id > 5) AS avg_above_5
31+
FROM items
32+
GROUP BY rarity
33+
`
34+
35+
// Multiple FILTER conditions
36+
const multipleFilters = sql`
37+
-- @name: multiple filters
38+
SELECT
39+
COUNT(*) FILTER (WHERE rarity = 'common') AS count_common,
40+
COUNT(*) FILTER (WHERE rarity = 'rare') AS count_rare,
41+
COUNT(*) FILTER (WHERE rarity = 'legendary') AS count_legendary,
42+
COUNT(*) FILTER (WHERE rarity IS NULL) AS count_unknown
43+
FROM items
44+
`

0 commit comments

Comments
 (0)