Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

evaluator.progress.test.ts 4.7 KB

You have to be logged in to leave a comment. Sign In
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
  1. import type { RunEvalOptions } from '../src/types';
  2. // Mock dependencies
  3. jest.mock('cli-progress', () => {
  4. const mockBar = {
  5. increment: jest.fn(),
  6. update: jest.fn(),
  7. getTotal: jest.fn().mockImplementation(function (this: any) {
  8. return this._total || 10;
  9. }),
  10. };
  11. return {
  12. default: {
  13. MultiBar: jest.fn().mockImplementation(() => ({
  14. create: jest.fn().mockImplementation((total: number) => {
  15. const bar = { ...mockBar, _total: total };
  16. return bar;
  17. }),
  18. stop: jest.fn(),
  19. })),
  20. Presets: {
  21. shades_classic: {},
  22. },
  23. },
  24. };
  25. });
  26. jest.mock('../src/logger', () => ({
  27. __esModule: true,
  28. default: {
  29. warn: jest.fn(),
  30. debug: jest.fn(),
  31. info: jest.fn(),
  32. error: jest.fn(),
  33. },
  34. logger: {
  35. warn: jest.fn(),
  36. debug: jest.fn(),
  37. info: jest.fn(),
  38. error: jest.fn(),
  39. },
  40. setLogLevel: jest.fn(),
  41. }));
  42. // Import after mocking - we need to extract ProgressBarManager from evaluator
  43. // Since it's a private class, we'll test it through its usage patterns
  44. describe('Progress Bar Management', () => {
  45. afterEach(() => {
  46. jest.clearAllMocks();
  47. });
  48. describe('ProgressBarManager Work Distribution', () => {
  49. it('should correctly separate serial and group (concurrent) tasks', () => {
  50. const runEvalOptions: Partial<RunEvalOptions>[] = [
  51. { test: { options: { runSerially: true } } },
  52. { test: {} },
  53. { test: { options: { runSerially: true } } },
  54. { test: {} },
  55. { test: {} },
  56. ];
  57. let serialCount = 0;
  58. let groupCount = 0;
  59. for (const option of runEvalOptions) {
  60. if (option.test?.options?.runSerially) {
  61. serialCount++;
  62. } else {
  63. groupCount++;
  64. }
  65. }
  66. expect(serialCount).toBe(2);
  67. expect(groupCount).toBe(3);
  68. });
  69. it('should map indices correctly to execution contexts', () => {
  70. const indexToContext = new Map();
  71. const runEvalOptions: Partial<RunEvalOptions>[] = [
  72. { test: { options: { runSerially: true } } }, // index 0 -> serial
  73. { test: {} }, // index 1 -> concurrent bar 0
  74. { test: { options: { runSerially: true } } }, // index 2 -> serial
  75. { test: {} }, // index 3 -> concurrent bar 1
  76. { test: {} }, // index 4 -> concurrent bar 2
  77. ];
  78. let concurrentCount = 0;
  79. const concurrency = 3;
  80. const maxBars = Math.min(concurrency, 20);
  81. for (let i = 0; i < runEvalOptions.length; i++) {
  82. const option = runEvalOptions[i];
  83. if (option.test?.options?.runSerially) {
  84. indexToContext.set(i, { phase: 'serial', barIndex: 0 });
  85. } else {
  86. indexToContext.set(i, {
  87. phase: 'concurrent',
  88. barIndex: concurrentCount % maxBars,
  89. });
  90. concurrentCount++;
  91. }
  92. }
  93. expect(indexToContext.get(0)).toEqual({ phase: 'serial', barIndex: 0 });
  94. expect(indexToContext.get(1)).toEqual({ phase: 'concurrent', barIndex: 0 });
  95. expect(indexToContext.get(2)).toEqual({ phase: 'serial', barIndex: 0 });
  96. expect(indexToContext.get(3)).toEqual({ phase: 'concurrent', barIndex: 1 });
  97. expect(indexToContext.get(4)).toEqual({ phase: 'concurrent', barIndex: 2 });
  98. });
  99. it('should calculate correct totals for each progress bar', () => {
  100. const concurrentCount = 10;
  101. const numBars = 3;
  102. const perBar = Math.floor(concurrentCount / numBars);
  103. const remainder = concurrentCount % numBars;
  104. const barTotals = [];
  105. for (let i = 0; i < numBars; i++) {
  106. const total = i < remainder ? perBar + 1 : perBar;
  107. barTotals.push(total);
  108. }
  109. expect(barTotals).toEqual([4, 3, 3]);
  110. expect(barTotals.reduce((a, b) => a + b, 0)).toBe(concurrentCount);
  111. });
  112. it('should handle dynamic comparison bar creation correctly', () => {
  113. // This test validates that comparison bars are created with the correct total
  114. // after we know the actual count of comparisons needed
  115. const cliProgress = require('cli-progress').default;
  116. const mockMultibar = new cliProgress.MultiBar();
  117. // Simulate creating progress bars without knowing comparison count initially
  118. mockMultibar.create(2, 0); // 2 serial tasks
  119. mockMultibar.create(3, 0); // 3 concurrent tasks
  120. // Later, when we know we need 5 comparisons, create the comparison bar
  121. mockMultibar.create(5, 0);
  122. // Verify the create method was called with correct totals
  123. expect(mockMultibar.create).toHaveBeenCalledTimes(3);
  124. expect(mockMultibar.create).toHaveBeenNthCalledWith(1, 2, 0);
  125. expect(mockMultibar.create).toHaveBeenNthCalledWith(2, 3, 0);
  126. expect(mockMultibar.create).toHaveBeenNthCalledWith(3, 5, 0);
  127. });
  128. });
  129. });
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...