|
1 | 1 | package coll |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "errors" |
5 | 4 | "testing" |
6 | 5 | ) |
7 | 6 |
|
@@ -306,129 +305,3 @@ func testLastIndexOf[C cmpInternal[int]](t *testing.T, builder testCollectionBui |
306 | 305 | }) |
307 | 306 | } |
308 | 307 | } |
309 | | - |
310 | | -func getMaxCases[C any](builder testCollectionBuilder[C]) []testCase[C, int] { |
311 | | - return []testCase[C, int]{ |
312 | | - { |
313 | | - name: "Max() on empty collection", |
314 | | - coll: builder.Empty(), |
315 | | - want1: 0, |
316 | | - err: ErrEmptyCollection, |
317 | | - }, |
318 | | - { |
319 | | - name: "Max() on one-item collection", |
320 | | - coll: builder.One(), |
321 | | - want1: 111, |
322 | | - }, |
323 | | - { |
324 | | - name: "Max() on three-item collection", |
325 | | - coll: builder.Three(), |
326 | | - want1: 333, |
327 | | - }, |
328 | | - { |
329 | | - name: "Max() on six-item collection", |
330 | | - coll: builder.SixWithDuplicates(), |
331 | | - want1: 333, |
332 | | - }, |
333 | | - } |
334 | | -} |
335 | | - |
336 | | -func testMax[C cmpInternal[int]](t *testing.T, builder testCollectionBuilder[C]) { |
337 | | - cases := getMaxCases(builder) |
338 | | - for _, tt := range cases { |
339 | | - t.Run(tt.name, func(t *testing.T) { |
340 | | - got, err := tt.coll.Max() |
341 | | - if err != nil { |
342 | | - if !errors.Is(err, tt.err) { |
343 | | - t.Errorf("Max() error = %v, wantErr %v", err, tt.err) |
344 | | - } |
345 | | - } else if got != tt.want1 { |
346 | | - t.Errorf("Max() = %v, want1 %v", got, tt.want1) |
347 | | - } |
348 | | - }) |
349 | | - } |
350 | | -} |
351 | | - |
352 | | -func getMinCases[C any](builder testCollectionBuilder[C]) []testCase[C, int] { |
353 | | - return []testCase[C, int]{ |
354 | | - { |
355 | | - name: "Min() on empty collection", |
356 | | - coll: builder.Empty(), |
357 | | - want1: 0, |
358 | | - err: ErrEmptyCollection, |
359 | | - }, |
360 | | - { |
361 | | - name: "Min() on one-item collection", |
362 | | - coll: builder.One(), |
363 | | - want1: 111, |
364 | | - }, |
365 | | - { |
366 | | - name: "Min() on three-item collection", |
367 | | - coll: builder.Three(), |
368 | | - want1: 111, |
369 | | - }, |
370 | | - { |
371 | | - name: "Min() on three-item collection reversed", |
372 | | - coll: builder.ThreeRev(), |
373 | | - want1: 111, |
374 | | - }, |
375 | | - { |
376 | | - name: "Min() on six-item collection", |
377 | | - coll: builder.SixWithDuplicates(), |
378 | | - want1: 111, |
379 | | - }, |
380 | | - } |
381 | | -} |
382 | | - |
383 | | -func testMin[C cmpInternal[int]](t *testing.T, builder testCollectionBuilder[C]) { |
384 | | - cases := getMinCases(builder) |
385 | | - for _, tt := range cases { |
386 | | - t.Run(tt.name, func(t *testing.T) { |
387 | | - got, err := tt.coll.Min() |
388 | | - if err != nil { |
389 | | - if !errors.Is(err, tt.err) { |
390 | | - t.Errorf("Min() error = %v, wantErr %v", err, tt.err) |
391 | | - } |
392 | | - } else if got != tt.want1 { |
393 | | - t.Errorf("Min() = %v, want1 %v", got, tt.want1) |
394 | | - } |
395 | | - }) |
396 | | - } |
397 | | -} |
398 | | - |
399 | | -func getSumCases[C any](builder testCollectionBuilder[C]) []testCase[C, int] { |
400 | | - return []testCase[C, int]{ |
401 | | - { |
402 | | - name: "Sum() on empty collection", |
403 | | - coll: builder.Empty(), |
404 | | - want1: 0, |
405 | | - }, |
406 | | - { |
407 | | - name: "Sum() on one-item collection", |
408 | | - coll: builder.One(), |
409 | | - want1: 111, |
410 | | - }, |
411 | | - { |
412 | | - name: "Sum() on three-item collection", |
413 | | - coll: builder.Three(), |
414 | | - want1: 666, |
415 | | - }, |
416 | | - { |
417 | | - name: "Sum() on six-item collection", |
418 | | - coll: builder.SixWithDuplicates(), |
419 | | - want1: 1332, |
420 | | - }, |
421 | | - } |
422 | | -} |
423 | | - |
424 | | -func testSum[C cmpInternal[int]](t *testing.T, builder testCollectionBuilder[C]) { |
425 | | - cases := getSumCases(builder) |
426 | | - for _, tt := range cases { |
427 | | - t.Run(tt.name, func(t *testing.T) { |
428 | | - got := tt.coll.Sum() |
429 | | - if got != tt.want1 { |
430 | | - t.Errorf("Sum() = %v, want1 %v", got, tt.want1) |
431 | | - } |
432 | | - }) |
433 | | - } |
434 | | -} |
0 commit comments