Skip to content

Commit cb76527

Browse files
committed
adjust tests to new schema
1 parent c65d761 commit cb76527

2 files changed

Lines changed: 56 additions & 44 deletions

File tree

databases/catdat/scripts/redundancies.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import {
88
get_deduced_satisfied_properties,
99
get_deduced_unsatisfied_properties,
1010
} from './deduce-structure-properties'
11-
import { get_property_assignments_by_deduction, StructureMeta } from './utils/deduction'
11+
import {
12+
get_property_assignments_by_deduction,
13+
type StructureMeta,
14+
} from './utils/deduction'
1215
import { get_functors, get_normalized_functor_implications } from './utils/functors'
1316
import { StructureType } from './config'
1417

@@ -166,12 +169,12 @@ function get_redundant_unsatisfied_property(
166169
*/
167170
function get_ignored_redundant_assignments(type: StructureType) {
168171
const rows = db
169-
.prepare(
170-
`SELECT ${type}_id as structure_id, property_id
171-
FROM ${type}_property_assignments
172-
WHERE check_redundancy = FALSE`,
172+
.prepare<[string], { structure_id: string; property_id: string }>(
173+
`SELECT structure_id, property_id
174+
FROM property_assignments
175+
WHERE type = ? AND check_redundancy = FALSE`,
173176
)
174-
.all() as { structure_id: string; property_id: string }[]
177+
.all(type)
175178

176179
const grouped: Record<string, Set<string>> = {}
177180

databases/catdat/scripts/test.ts

Lines changed: 47 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,23 @@ execute_tests()
2424
function execute_tests() {
2525
try {
2626
console.info('\n--- Test categories ---')
27-
test_mutual_category_duals()
27+
test_mutual_structure_duals('category')
2828
test_properties_of_trivial_category()
2929
test_mutual_property_duals('category')
3030
test_decided_structures(decided_categories, 'category')
31-
test_properties_of_selected_structures(
32-
{ Set: Set_expected, Ab: Ab_expected, Top: Top_expected },
33-
'category',
34-
)
31+
test_properties_of_selected_structures({
32+
Set: Set_expected,
33+
Ab: Ab_expected,
34+
Top: Top_expected,
35+
})
3536

3637
console.info('\n--- Test functors ---')
3738
test_mutual_property_duals('functor')
3839
test_decided_structures(decided_functors, 'functor')
39-
test_properties_of_selected_structures(
40-
{ forget_vector: forget_vector_expected, id_Set: id_Set_expected },
41-
'functor',
42-
)
40+
test_properties_of_selected_structures({
41+
forget_vector: forget_vector_expected,
42+
id_Set: id_Set_expected,
43+
})
4344
} catch (err) {
4445
if (err instanceof Error) {
4546
console.error(err.message)
@@ -51,27 +52,30 @@ function execute_tests() {
5152
}
5253

5354
/**
54-
* Tests for all categories C,D that if C is dual to D, then D is dual to C.
55+
* Tests for all structures C,D that if C is dual to D, then D is dual to C.
5556
*/
56-
function test_mutual_category_duals() {
57+
function test_mutual_structure_duals(type: StructureType) {
5758
const dict: Record<string, string | null> = {}
5859

59-
const categories = db
60-
.prepare('SELECT id, dual_category_id FROM categories')
61-
.all() as { id: string; dual_category_id: string | null }[]
60+
const structures = db
61+
.prepare<[string], { id: string; dual_structure_id: string | null }>(
62+
`SELECT structure_id as id, dual_structure_id
63+
FROM dual_structures WHERE type = ?`,
64+
)
65+
.all(type)
6266

63-
for (const { id, dual_category_id } of categories) {
64-
dict[id] = dual_category_id
67+
for (const { id, dual_structure_id } of structures) {
68+
dict[id] = dual_structure_id
6569
}
6670

6771
for (const id in dict) {
6872
const dual = dict[id]
6973
if (dual && dict[dual] !== id) {
70-
throw new Error(`❌ Found non-mutual category duality: ${id}, ${dual}`)
74+
throw new Error(`❌ Found non-mutual structure duality: ${id}, ${dual}`)
7175
}
7276
}
7377

74-
console.info(`✅ Categories are mutually dual`)
78+
console.info(`✅ Structures of type ${type} are mutually dual`)
7579
}
7680

7781
/**
@@ -81,8 +85,10 @@ function test_mutual_category_duals() {
8185
function test_properties_of_trivial_category() {
8286
const rows = db
8387
.prepare(
84-
`SELECT property_id FROM category_property_assignments
85-
WHERE category_id = '1' AND is_satisfied = FALSE`,
88+
`SELECT property_id FROM property_assignments
89+
WHERE
90+
type = 'category' AND structure_id = '1'
91+
AND is_satisfied = FALSE`,
8692
)
8793
.all()
8894

@@ -100,19 +106,22 @@ function test_properties_of_trivial_category() {
100106
* if p is dual to q, then q is dual to p.
101107
*/
102108
function test_mutual_property_duals(type: StructureType) {
103-
const dict: Record<string, string | null> = {}
109+
const dict: Record<string, string> = {}
104110

105111
const properties = db
106-
.prepare(`SELECT id, dual_property_id FROM ${type}_properties`)
107-
.all() as { id: string; dual_property_id: string | null }[]
112+
.prepare<[string], { id: string; dual_property_id: string }>(
113+
`SELECT property_id AS id, dual_property_id
114+
FROM dual_properties WHERE type = ?`,
115+
)
116+
.all(type)
108117

109118
for (const { id, dual_property_id } of properties) {
110119
dict[id] = dual_property_id
111120
}
112121

113122
for (const id in dict) {
114123
const dual = dict[id]
115-
if (dual && dict[dual] !== id) {
124+
if (dict[dual] !== id) {
116125
throw new Error(`❌ Found non-mutual property duality: ${id}, ${dual}`)
117126
}
118127
}
@@ -125,17 +134,18 @@ function test_mutual_property_duals(type: StructureType) {
125134
* been decided. If this test fails, property assignments or implications are missing.
126135
*/
127136
function test_decided_structures(structure_ids: string[], type: StructureType) {
128-
const unknown_query = db.prepare(
129-
`SELECT p.id FROM ${type}_properties p WHERE NOT EXISTS
130-
(SELECT 1 FROM ${type}_property_assignments
131-
WHERE ${type}_id = ? AND property_id = p.id
137+
const unknown_query = db.prepare<[string, string], { id: string }>(
138+
`SELECT p.id FROM properties p WHERE type = ? AND NOT EXISTS
139+
(SELECT 1 FROM property_assignments
140+
WHERE structure_id = ? AND property_id = p.id
132141
)
133142
`,
134143
)
135144

136145
for (const structure_id of structure_ids) {
137-
const res = unknown_query.all(structure_id) as { id: string }[]
138-
const unknown_properties = res.map((row) => row.id)
146+
const unknown_properties = unknown_query
147+
.all(type, structure_id)
148+
.map((row) => row.id)
139149

140150
if (unknown_properties.length > 0) {
141151
throw new Error(
@@ -155,18 +165,17 @@ function test_decided_structures(structure_ids: string[], type: StructureType) {
155165
*/
156166
function test_properties_of_selected_structures(
157167
expected: Record<string, Record<string, boolean>>,
158-
type: StructureType,
159168
) {
160-
const property_query = db.prepare(
161-
`SELECT property_id, is_satisfied FROM ${type}_property_assignments
162-
WHERE ${type}_id = ? AND is_satisfied IS NOT NULL`,
169+
const property_query = db.prepare<
170+
[string],
171+
{ property_id: string; is_satisfied: 0 | 1 }
172+
>(
173+
`SELECT property_id, is_satisfied FROM property_assignments
174+
WHERE structure_id = ? AND is_satisfied IS NOT NULL`,
163175
)
164176

165177
for (const structure_id in expected) {
166-
const properties = property_query.all(structure_id) as {
167-
property_id: string
168-
is_satisfied: 0 | 1
169-
}[]
178+
const properties = property_query.all(structure_id)
170179

171180
for (const { property_id, is_satisfied } of properties) {
172181
const ok = Boolean(is_satisfied) === expected[structure_id][property_id]

0 commit comments

Comments
 (0)