forked from AIObjectives/talk-to-the-city-reports
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_tokens.test.ts
31 lines (28 loc) · 1.46 KB
/
count_tokens.test.ts
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
import { describe, it } from 'vitest';
import { expect } from 'vitest';
import CountTokensNode, { count_tokens_node_data } from '$lib/compute/count_tokens_v0';
import deepCopy from 'deep-copy';
describe('CountTokensNode class', () => {
it('should correctly count tokens in input data', async () => {
const inputData = { csv: [{ 'comment-body': 'Hello' }, { 'comment-body': 'World' }] };
const node = new CountTokensNode(deepCopy(count_tokens_node_data));
const count = await node.compute(inputData, 'run', console.log, console.log, console.log, '/');
expect(count).toBe(2);
expect(node.data.dirty).toBe(false);
});
it('should not count tokens if input data length matches and node is not dirty', async () => {
const inputData = { csv: [{ 'comment-body': 'Hello' }, { 'comment-body': 'World' }] };
const node = new CountTokensNode(deepCopy(count_tokens_node_data));
node.data.csv_length = inputData.csv.length;
node.data.dirty = false;
const count = await node.compute(inputData, 'run', console.log, console.log, console.log, '/');
expect(count).toBe(node.data.num_tokens);
});
it('should count tokens if the input data is a string', async () => {
const inputData = { csv: 'Hello World' };
const node = new CountTokensNode(deepCopy(count_tokens_node_data));
const count = await node.compute(inputData, 'run', console.log, console.log, console.log, '/');
expect(count).toBe(2);
expect(node.data.dirty).toBe(false);
});
});