Skip to content

Commit b7139ae

Browse files
authored
Merge pull request #16 from AlphaQuantJS/dev
Dev
2 parents 1c487b1 + 96e9bcb commit b7139ae

20 files changed

Lines changed: 1653 additions & 1984 deletions

test/methods/dataframe/display/display.test.js

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
22
import { DataFrame } from '../../../../src/core/dataframe/DataFrame.js';
33
import { display } from '../../../../src/methods/dataframe/display/display.js';
44

5-
import {
6-
testWithBothStorageTypes,
7-
createDataFrameWithStorage,
8-
} from '../../../utils/storageTestUtils.js';
9-
105
// Mock the module
116
vi.mock('../../../../src/display/web/html.js', () => ({
127
display: vi.fn(),
@@ -21,50 +16,47 @@ describe('DataFrame display method', () => {
2116
mockWebDisplay.mockReset();
2217
});
2318

24-
// Run tests with both storage types
25-
testWithBothStorageTypes((storageType) => {
26-
describe(`with ${storageType} storage`, () => {
27-
// Create test data frame with people data for better readability in tests
28-
const testData = [
29-
{ name: 'Alice', age: 25, city: 'New York' },
30-
{ name: 'Bob', age: 30, city: 'Boston' },
31-
{ name: 'Charlie', age: 35, city: 'Chicago' },
32-
];
33-
34-
// Create DataFrame with the specified storage type
35-
const df = createDataFrameWithStorage(DataFrame, testData, storageType);
19+
describe('with standard storage', () => {
20+
// Create test data frame with people data for better readability in tests
21+
const testData = [
22+
{ name: 'Alice', age: 25, city: 'New York' },
23+
{ name: 'Bob', age: 30, city: 'Boston' },
24+
{ name: 'Charlie', age: 35, city: 'Chicago' },
25+
];
3626

37-
it('should call the web display function with the frame', () => {
38-
// Call display function directly
39-
const displayFn = display();
40-
displayFn(df);
27+
// Create DataFrame using fromRows
28+
const df = DataFrame.fromRows(testData);
4129

42-
// Check that the web display function was called with the frame
43-
expect(mockWebDisplay).toHaveBeenCalledWith(df, expect.any(Object));
44-
});
30+
it('should call the web display function with the frame', () => {
31+
// Call display function directly
32+
const displayFn = display();
33+
displayFn(df);
4534

46-
it('should return the frame for method chaining', () => {
47-
// Call display function and check the return value
48-
const displayFn = display();
49-
const result = displayFn(df);
35+
// Check that the web display function was called with the frame
36+
expect(mockWebDisplay).toHaveBeenCalledWith(df, expect.any(Object));
37+
});
5038

51-
// Check that the function returns the frame
52-
expect(result).toBe(df);
53-
});
39+
it('should return the frame for method chaining', () => {
40+
// Call display function and check the return value
41+
const displayFn = display();
42+
const result = displayFn(df);
5443

55-
it('should pass options to the web display function', () => {
56-
// Call display function with options
57-
const displayFn = display();
58-
const options = {
59-
maxRows: 5,
60-
maxCols: 2,
61-
className: 'custom-table',
62-
};
63-
displayFn(df, options);
44+
// Check that the function returns the frame
45+
expect(result).toBe(df);
46+
});
6447

65-
// Check that the web display function was called with the options
66-
expect(mockWebDisplay).toHaveBeenCalledWith(df, options);
67-
});
48+
it('should pass options to the web display function', () => {
49+
// Call display function with options
50+
const displayFn = display();
51+
const options = {
52+
maxRows: 5,
53+
maxCols: 2,
54+
className: 'custom-table',
55+
};
56+
displayFn(df, options);
57+
58+
// Check that the web display function was called with the options
59+
expect(mockWebDisplay).toHaveBeenCalledWith(df, options);
6860
});
6961
});
7062
});

test/methods/dataframe/display/print.test.js

Lines changed: 113 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ import { describe, it, expect, vi } from 'vitest';
22
import { DataFrame } from '../../../../src/core/dataframe/DataFrame.js';
33
import { print } from '../../../../src/methods/dataframe/display/print.js';
44

5-
import {
6-
testWithBothStorageTypes,
7-
createDataFrameWithStorage,
8-
} from '../../../utils/storageTestUtils.js';
9-
105
// Test data to be used in all tests
116
const sampleData = [
127
{ value: 10, category: 'A', mixed: '20' },
@@ -17,134 +12,119 @@ const sampleData = [
1712
];
1813

1914
describe('DataFrame print method', () => {
20-
// Run tests with both storage types
21-
testWithBothStorageTypes((storageType) => {
22-
describe(`with ${storageType} storage`, () => {
23-
// Create test data frame with people data for better readability in tests
24-
const testData = [
25-
{ name: 'Alice', age: 25, city: 'New York' },
26-
{ name: 'Bob', age: 30, city: 'Boston' },
27-
{ name: 'Charlie', age: 35, city: 'Chicago' },
28-
{ name: 'David', age: 40, city: 'Denver' },
29-
{ name: 'Eve', age: 45, city: 'El Paso' },
30-
];
31-
32-
// Create DataFrame with the specified storage type
33-
const df = createDataFrameWithStorage(DataFrame, testData, storageType);
34-
35-
it('should format data as a table string', () => {
36-
// Mock console.log to check output
37-
const consoleSpy = vi
38-
.spyOn(console, 'log')
39-
.mockImplementation(() => {});
40-
41-
// Call print function directly
42-
const printFn = print();
43-
printFn(df);
44-
45-
// Check that console.log was called
46-
expect(consoleSpy).toHaveBeenCalled();
47-
48-
// Get the argument passed to console.log
49-
const output = consoleSpy.mock.calls[0][0];
50-
51-
// Check that the output contains column headers
52-
expect(output).toContain('name');
53-
expect(output).toContain('age');
54-
expect(output).toContain('city');
55-
56-
// Check that the output contains data
57-
expect(output).toContain('Alice');
58-
expect(output).toContain('25');
59-
expect(output).toContain('New York');
60-
61-
// Restore console.log
62-
consoleSpy.mockRestore();
63-
});
64-
65-
it('should return the frame for method chaining', () => {
66-
// Mock console.log to prevent output
67-
const consoleSpy = vi
68-
.spyOn(console, 'log')
69-
.mockImplementation(() => {});
70-
71-
// Call print function and check the return value
72-
const printFn = print();
73-
const result = printFn(df);
74-
75-
// Check that the function returns the frame
76-
expect(result).toBe(df);
77-
78-
// Restore console.log
79-
consoleSpy.mockRestore();
80-
});
81-
82-
it('should respect rows limit', () => {
83-
// Create a frame with many rows
84-
const largeData = Array.from({ length: 20 }, (_, i) => ({
85-
id: i,
86-
value: i * 10,
87-
}));
88-
89-
const largeDf = createDataFrameWithStorage(
90-
DataFrame,
91-
largeData,
92-
storageType,
93-
);
94-
95-
// Mock console.log
96-
const consoleSpy = vi
97-
.spyOn(console, 'log')
98-
.mockImplementation(() => {});
99-
100-
// Call print function with row limit
101-
const printFn = print();
102-
printFn(largeDf, 5);
103-
104-
// Get the output
105-
const output = consoleSpy.mock.calls[0][0];
106-
107-
// Check that the output contains message about additional rows
108-
expect(output).toContain('more rows');
109-
110-
// Restore console.log
111-
consoleSpy.mockRestore();
112-
});
113-
114-
it('should respect cols limit', () => {
115-
// Create a frame with many columns
116-
const wideData = {
117-
col1: [1, 2, 3],
118-
col2: [4, 5, 6],
119-
col3: [7, 8, 9],
120-
col4: [10, 11, 12],
121-
col5: [13, 14, 15],
122-
};
123-
124-
const wideDf = createDataFrameWithStorage(
125-
DataFrame,
126-
wideData,
127-
storageType,
128-
);
129-
130-
// Mock console.log
131-
const consoleSpy = vi
132-
.spyOn(console, 'log')
133-
.mockImplementation(() => {});
134-
135-
// Call print function with column limit
136-
const printFn = print();
137-
printFn(wideDf, Infinity, 2);
138-
139-
// Get the output
140-
const output = consoleSpy.mock.calls[0][0];
141-
142-
// Check that the output contains message about additional columns
143-
expect(output).toContain('more columns');
144-
145-
// Restore console.log
146-
consoleSpy.mockRestore();
147-
});
15+
describe('with standard storage', () => {
16+
// Create test data frame with people data for better readability in tests
17+
const testData = [
18+
{ name: 'Alice', age: 25, city: 'New York' },
19+
{ name: 'Bob', age: 30, city: 'Boston' },
20+
{ name: 'Charlie', age: 35, city: 'Chicago' },
21+
{ name: 'David', age: 40, city: 'Denver' },
22+
{ name: 'Eve', age: 45, city: 'El Paso' },
23+
];
24+
25+
// Create DataFrame using fromRows
26+
const df = DataFrame.fromRows(testData);
27+
28+
it('should format data as a table string', () => {
29+
// Mock console.log to check output
30+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
31+
32+
// Call print function directly
33+
const printFn = print();
34+
printFn(df);
35+
36+
// Check that console.log was called
37+
expect(consoleSpy).toHaveBeenCalled();
38+
39+
// Get the argument passed to console.log
40+
const output = consoleSpy.mock.calls[0][0];
41+
42+
// Check that the output contains column headers
43+
expect(output).toContain('name');
44+
expect(output).toContain('age');
45+
expect(output).toContain('city');
46+
47+
// Check that the output contains data
48+
expect(output).toContain('Alice');
49+
expect(output).toContain('25');
50+
expect(output).toContain('New York');
51+
52+
// Restore console.log
53+
consoleSpy.mockRestore();
54+
});
55+
56+
it('should return the frame for method chaining', () => {
57+
// Mock console.log to prevent output
58+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
59+
60+
// Call print function and check the return value
61+
const printFn = print();
62+
const result = printFn(df);
63+
64+
// Check that the function returns the frame
65+
expect(result).toBe(df);
66+
67+
// Restore console.log
68+
consoleSpy.mockRestore();
69+
});
70+
71+
it('should respect rows limit', () => {
72+
// Create a frame with many rows
73+
const largeData = Array.from({ length: 20 }, (_, i) => ({
74+
id: i,
75+
value: i * 10,
76+
}));
77+
78+
const largeDf = DataFrame.fromRows(largeData);
79+
80+
// Mock console.log
81+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
82+
83+
// Call print function with row limit
84+
const printFn = print();
85+
printFn(largeDf, 5);
86+
87+
// Get the output
88+
const output = consoleSpy.mock.calls[0][0];
89+
90+
// Check that the output contains message about additional rows
91+
expect(output).toContain('more rows');
92+
93+
// Restore console.log
94+
consoleSpy.mockRestore();
95+
});
96+
97+
it('should respect cols limit', () => {
98+
// Create a frame with many columns
99+
const wideData = {
100+
col1: [1, 2, 3],
101+
col2: [4, 5, 6],
102+
col3: [7, 8, 9],
103+
col4: [10, 11, 12],
104+
col5: [13, 14, 15],
105+
};
106+
107+
const wideDf = DataFrame.fromRows([
108+
{ col1: 1, col2: 4, col3: 7, col4: 10, col5: 13 },
109+
{ col1: 2, col2: 5, col3: 8, col4: 11, col5: 14 },
110+
{ col1: 3, col2: 6, col3: 9, col4: 12, col5: 15 },
111+
]);
112+
113+
// Mock console.log
114+
const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
115+
116+
// Call print function with column limit
117+
const printFn = print();
118+
printFn(wideDf, Infinity, 2);
119+
120+
// Get the output
121+
const output = consoleSpy.mock.calls[0][0];
122+
123+
// Check that the output contains message about additional columns
124+
expect(output).toContain('more columns');
125+
126+
// Restore console.log
127+
consoleSpy.mockRestore();
148128
});
149129
});
150130
});

0 commit comments

Comments
 (0)