@@ -152,11 +152,11 @@ test('updates specific indexes and returns correct sums', t => {
152
152
}
153
153
} ) ;
154
154
155
- test ( 'random updates' , t => {
155
+ test ( 'random updates (sum) ' , t => {
156
156
const largeInputCopy = largeInput . slice ( ) ;
157
157
const tree = new SegmentTree ( largeInput , ( a , b ) => a + b ) ;
158
158
159
- const testCases = 1e7 ;
159
+ const testCases = 1e6 ;
160
160
161
161
for ( let i = 0 ; i < testCases ; ++ i ) {
162
162
const randomIndex = generateNumber ( 0 , largeInput . length - 1 ) ;
@@ -170,3 +170,41 @@ test('random updates', t => {
170
170
findSumLinear ( largeInputCopy , 0 , largeInputCopy . length - 1 )
171
171
) ;
172
172
} ) ;
173
+
174
+ test ( 'random updates (max)' , t => {
175
+ const largeInputCopy = largeInput . slice ( ) ;
176
+ const tree = new SegmentTree ( largeInput , Math . max ) ;
177
+
178
+ const testCases = 1e6 ;
179
+
180
+ for ( let i = 0 ; i < testCases ; ++ i ) {
181
+ const randomIndex = generateNumber ( 0 , largeInput . length - 1 ) ;
182
+ const randomValue = generateNumber ( - 1e7 , 1e7 ) ;
183
+ tree . update ( randomIndex , randomValue , false ) ;
184
+ largeInputCopy [ randomIndex ] = randomValue ;
185
+ }
186
+
187
+ t . is (
188
+ tree . query ( ) ,
189
+ findMaxLinear ( largeInputCopy , 0 , largeInputCopy . length - 1 )
190
+ ) ;
191
+ } ) ;
192
+
193
+ test ( 'random updates (min)' , t => {
194
+ const largeInputCopy = largeInput . slice ( ) ;
195
+ const tree = new SegmentTree ( largeInput , Math . min ) ;
196
+
197
+ const testCases = 1e6 ;
198
+
199
+ for ( let i = 0 ; i < testCases ; ++ i ) {
200
+ const randomIndex = generateNumber ( 0 , largeInput . length - 1 ) ;
201
+ const randomValue = generateNumber ( - 1e7 , 1e7 ) ;
202
+ tree . update ( randomIndex , randomValue , false ) ;
203
+ largeInputCopy [ randomIndex ] = randomValue ;
204
+ }
205
+
206
+ t . is (
207
+ tree . query ( ) ,
208
+ findMinLinear ( largeInputCopy , 0 , largeInputCopy . length - 1 )
209
+ ) ;
210
+ } ) ;
0 commit comments