-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtemporal.test.ts
More file actions
50 lines (44 loc) · 1.74 KB
/
Copy pathtemporal.test.ts
File metadata and controls
50 lines (44 loc) · 1.74 KB
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
import Database from 'better-sqlite3';
import { describe, expect, it } from 'vitest';
import { initSchema } from '../../../src/db/index.js';
import { buildTemporalGraph } from '../../../src/graph/builders/temporal.js';
function createTestDb() {
const db = new Database(':memory:');
db.pragma('journal_mode = WAL');
initSchema(db);
return db;
}
describe('buildTemporalGraph', () => {
it('returns empty graph when co_changes table has no rows', () => {
const db = createTestDb();
// initSchema creates co_changes; just leave it empty
const graph = buildTemporalGraph(db);
expect(graph.nodeCount).toBe(0);
expect(graph.directed).toBe(false);
db.close();
});
it('builds undirected graph from co_changes table', () => {
const db = createTestDb();
db.exec(`
INSERT INTO co_changes (file_a, file_b, commit_count, jaccard) VALUES ('a.js', 'b.js', 5, 0.8);
INSERT INTO co_changes (file_a, file_b, commit_count, jaccard) VALUES ('b.js', 'c.js', 2, 0.3);
`);
const graph = buildTemporalGraph(db);
expect(graph.nodeCount).toBe(3);
expect(graph.hasEdge('a.js', 'b.js')).toBe(true);
expect(graph.hasEdge('b.js', 'a.js')).toBe(true); // undirected
db.close();
});
it('filters by minJaccard', () => {
const db = createTestDb();
db.exec(`
INSERT INTO co_changes (file_a, file_b, commit_count, jaccard) VALUES ('a.js', 'b.js', 5, 0.8);
INSERT INTO co_changes (file_a, file_b, commit_count, jaccard) VALUES ('b.js', 'c.js', 2, 0.3);
`);
const graph = buildTemporalGraph(db, { minJaccard: 0.5 });
expect([...graph.edges()]).toHaveLength(1);
expect(graph.hasEdge('a.js', 'b.js')).toBe(true);
expect(graph.hasEdge('b.js', 'c.js')).toBe(false);
db.close();
});
});