rosu-pp 4.0.1

Difficulty and performance calculation for osu!
Documentation
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
use std::cmp;

use crate::{
    any::{
        HitResultGenerator,
        hitresult_generator::{Fast, IgnoreAccuracy},
    },
    catch::{Catch, CatchHitResults, performance::inspect::InspectCatchPerformance},
};

impl HitResultGenerator<Catch> for Fast {
    #[expect(clippy::too_many_lines, reason = "it is what it is /shrug")]
    fn generate_hitresults(inspect: InspectCatchPerformance<'_>) -> CatchHitResults {
        let Some(acc) = inspect.acc else {
            return <IgnoreAccuracy as HitResultGenerator<Catch>>::generate_hitresults(inspect);
        };

        // In osu!catch:
        // - total_objects = n_fruits + n_droplets + n_tiny_droplets
        // - accuracy = (fruits + droplets + tiny_droplets) / total_objects
        // - Constraint: fruits + droplets + misses = n_fruits + n_droplets
        // - Constraint: tiny_droplets + tiny_droplet_misses = n_tiny_droplets

        let n_fruits = inspect.attrs.n_fruits;
        let n_droplets = inspect.attrs.n_droplets;
        let n_tiny_droplets = inspect.attrs.n_tiny_droplets;
        let total_objects = inspect.total_objects();

        if total_objects == 0 {
            return CatchHitResults {
                fruits: 0,
                droplets: 0,
                tiny_droplets: 0,
                tiny_droplet_misses: 0,
                misses: 0,
            };
        }

        // Get misses (fruits and droplets only, clamped)
        let misses = inspect.misses();

        // Calculate how many successful catches we need for target accuracy
        // acc = catches / total_objects
        // catches = acc * total_objects
        let catches_needed = (acc * f64::from(total_objects)).round_ties_even() as u32;

        // Maximum possible catches considering misses
        let max_fruit_droplet_catches = (n_fruits + n_droplets).saturating_sub(misses);

        // Clamp and validate provided values
        let provided_fruits = inspect.fruits.map_or(0, |n| cmp::min(n, n_fruits));
        let provided_droplets = inspect.droplets.map_or(0, |n| cmp::min(n, n_droplets));
        let provided_tiny_droplets = inspect
            .tiny_droplets
            .map_or(0, |n| cmp::min(n, n_tiny_droplets));
        let provided_tiny_droplet_misses = inspect.tiny_droplet_misses.unwrap_or(0);

        // Make sure provided fruits + droplets don't exceed what's possible with the given misses
        let clamped_fruits = cmp::min(provided_fruits, max_fruit_droplet_catches);
        let clamped_droplets = cmp::min(
            provided_droplets,
            max_fruit_droplet_catches.saturating_sub(clamped_fruits),
        );

        match (
            inspect.fruits,
            inspect.droplets,
            inspect.tiny_droplets,
            inspect.tiny_droplet_misses,
        ) {
            // All provided - clamp and ensure pool constraints
            // Priority: misses > fruits > droplets (for fruit/droplet pool)
            // Priority: tiny_droplets > tiny_droplet_misses (for tiny droplet pool)
            (Some(_), Some(_), Some(_), Some(_)) => {
                // Handle fruit/droplet pool constraint
                let pool_total = n_fruits + n_droplets;
                let current_sum = clamped_fruits + clamped_droplets + misses;

                let (final_fruits, final_droplets) = match current_sum.cmp(&pool_total) {
                    cmp::Ordering::Less => {
                        // Need to add more - prioritize droplets (adjust lower priority first)
                        let needed = pool_total - current_sum;
                        let new_droplets = cmp::min(clamped_droplets + needed, n_droplets);
                        let still_needed =
                            pool_total.saturating_sub(clamped_fruits + new_droplets + misses);
                        let new_fruits = cmp::min(clamped_fruits + still_needed, n_fruits);

                        (new_fruits, new_droplets)
                    }
                    cmp::Ordering::Equal => (clamped_fruits, clamped_droplets),
                    cmp::Ordering::Greater => {
                        // Have too many - reduce droplets first (adjust lower priority first)
                        let excess = current_sum - pool_total;
                        let new_droplets = clamped_droplets.saturating_sub(excess);
                        let still_excess =
                            (clamped_fruits + new_droplets + misses).saturating_sub(pool_total);
                        let new_fruits = clamped_fruits.saturating_sub(still_excess);

                        (new_fruits, new_droplets)
                    }
                };

                // Handle tiny droplet pool constraint
                let tiny_pool_total = n_tiny_droplets;
                let tiny_current_sum = provided_tiny_droplets + provided_tiny_droplet_misses;

                let (final_tiny_droplets, final_tiny_droplet_misses) = match tiny_current_sum
                    .cmp(&tiny_pool_total)
                {
                    cmp::Ordering::Less => {
                        // Need to add more - prioritize tiny_droplets (higher priority)
                        let needed = tiny_pool_total - tiny_current_sum;
                        let new_tiny_droplets =
                            cmp::min(provided_tiny_droplets + needed, n_tiny_droplets);
                        let still_needed = tiny_pool_total.saturating_sub(new_tiny_droplets);

                        (new_tiny_droplets, still_needed)
                    }
                    cmp::Ordering::Equal => (provided_tiny_droplets, provided_tiny_droplet_misses),
                    cmp::Ordering::Greater => {
                        // Have too many - reduce tiny_droplet_misses first (lower priority)
                        let excess = tiny_current_sum - tiny_pool_total;
                        let new_tiny_droplet_misses =
                            provided_tiny_droplet_misses.saturating_sub(excess);
                        let still_excess = (provided_tiny_droplets + new_tiny_droplet_misses)
                            .saturating_sub(tiny_pool_total);
                        let new_tiny_droplets = provided_tiny_droplets.saturating_sub(still_excess);

                        (new_tiny_droplets, new_tiny_droplet_misses)
                    }
                };

                CatchHitResults {
                    fruits: final_fruits,
                    droplets: final_droplets,
                    tiny_droplets: final_tiny_droplets,
                    tiny_droplet_misses: final_tiny_droplet_misses,
                    misses,
                }
            }

            // Only one missing
            (Some(_), Some(_), Some(_), None) => {
                // tiny_droplet_misses is the only unknown
                let tiny_droplet_misses = n_tiny_droplets.saturating_sub(provided_tiny_droplets);

                CatchHitResults {
                    fruits: clamped_fruits,
                    droplets: clamped_droplets,
                    tiny_droplets: provided_tiny_droplets,
                    tiny_droplet_misses,
                    misses,
                }
            }
            (Some(_), Some(_), None, Some(_)) => {
                // tiny_droplets is the only unknown
                // We need to figure out how many tiny droplets to catch
                let current_catches = clamped_fruits + clamped_droplets;
                let remaining_catches = catches_needed.saturating_sub(current_catches);
                let tiny_droplets = cmp::min(remaining_catches, n_tiny_droplets);

                CatchHitResults {
                    fruits: clamped_fruits,
                    droplets: clamped_droplets,
                    tiny_droplets,
                    tiny_droplet_misses: provided_tiny_droplet_misses,
                    misses,
                }
            }
            (Some(_), None, Some(_), Some(_)) => {
                // droplets is the only unknown
                // Use pool constraint: droplets = n_fruits + n_droplets - fruits - misses
                let droplets_by_pool =
                    (n_fruits + n_droplets).saturating_sub(clamped_fruits + misses);
                let droplets = cmp::min(droplets_by_pool, n_droplets);

                CatchHitResults {
                    fruits: clamped_fruits,
                    droplets,
                    tiny_droplets: provided_tiny_droplets,
                    tiny_droplet_misses: provided_tiny_droplet_misses,
                    misses,
                }
            }
            (None, Some(_), Some(_), Some(_)) => {
                // fruits is the only unknown
                // Use pool constraint: fruits = n_fruits + n_droplets - droplets - misses
                let fruits_by_pool =
                    (n_fruits + n_droplets).saturating_sub(clamped_droplets + misses);
                let fruits = cmp::min(fruits_by_pool, n_fruits);

                CatchHitResults {
                    fruits,
                    droplets: clamped_droplets,
                    tiny_droplets: provided_tiny_droplets,
                    tiny_droplet_misses: provided_tiny_droplet_misses,
                    misses,
                }
            }

            // Two or more missing - use fast approximation
            _ => {
                // Calculate how many catches we still need after accounting for provided values
                let provided_catches = clamped_fruits + clamped_droplets + provided_tiny_droplets;
                let mut remain_catches = catches_needed.saturating_sub(provided_catches);

                // We need to distribute remaining catches among missing types
                // Priority: fruits > droplets > tiny_droplets (for performance)

                let fruits = if inspect.fruits.is_none() {
                    // Maximum fruits we can catch considering:
                    // 1. How many fruits exist (n_fruits)
                    // 2. How many fruit/droplet slots are available after misses and provided droplets
                    let max_by_pool = max_fruit_droplet_catches.saturating_sub(clamped_droplets);
                    let max_fruits = cmp::min(n_fruits, max_by_pool);
                    let caught = cmp::min(remain_catches, max_fruits);
                    remain_catches = remain_catches.saturating_sub(caught);

                    caught
                } else {
                    clamped_fruits
                };

                let droplets = if inspect.droplets.is_some() {
                    clamped_droplets
                } else if inspect.fruits.is_none() {
                    // If fruits is also missing, calculate based on remaining catches

                    // Both fruits and droplets are missing
                    let max_by_pool = max_fruit_droplet_catches.saturating_sub(fruits);
                    let max_droplets = cmp::min(n_droplets, max_by_pool);
                    let caught = cmp::min(remain_catches, max_droplets);
                    remain_catches = remain_catches.saturating_sub(caught);

                    caught
                } else {
                    // Only droplets is missing, fruits was provided
                    // Use pool constraint: droplets = n_fruits + n_droplets - fruits - misses
                    let droplets_by_pool = (n_fruits + n_droplets).saturating_sub(fruits + misses);
                    let droplets = cmp::min(droplets_by_pool, n_droplets);

                    // Decrement remaining_catches by the droplets we're catching
                    remain_catches = remain_catches.saturating_sub(droplets);

                    droplets
                };

                // If fruits was provided but droplets couldn't fill the pool,
                // adjust fruits upward to satisfy the pool constraint
                let fruits = if inspect.fruits.is_some() && inspect.droplets.is_none() {
                    let pool_sum = fruits + droplets + misses;
                    let expected = n_fruits + n_droplets;

                    if pool_sum < expected {
                        // Add the difference to fruits
                        let adjusted = cmp::min(n_fruits, fruits + (expected - pool_sum));
                        // Also update remaining_catches since we added more catches
                        let added_catches = adjusted - fruits;
                        remain_catches = remain_catches.saturating_sub(added_catches);

                        adjusted
                    } else {
                        fruits
                    }
                } else {
                    fruits
                };

                let tiny_droplets = if inspect.tiny_droplets.is_none() {
                    cmp::min(remain_catches, n_tiny_droplets)
                } else {
                    provided_tiny_droplets
                };

                let tiny_droplet_misses = if inspect.tiny_droplet_misses.is_none() {
                    // Calculate how many tiny droplets were missed
                    n_tiny_droplets.saturating_sub(tiny_droplets)
                } else {
                    provided_tiny_droplet_misses
                };

                CatchHitResults {
                    fruits,
                    droplets,
                    tiny_droplets,
                    tiny_droplet_misses,
                    misses,
                }
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use crate::{Difficulty, catch::CatchDifficultyAttributes};

    use super::*;

    #[test]
    fn perfect_accuracy() {
        const N_FRUITS: u32 = 100;
        const N_DROPLETS: u32 = 50;
        const N_TINY_DROPLETS: u32 = 200;

        let inspect = InspectCatchPerformance {
            attrs: &CatchDifficultyAttributes {
                n_fruits: N_FRUITS,
                n_droplets: N_DROPLETS,
                n_tiny_droplets: N_TINY_DROPLETS,
                ..Default::default()
            },
            difficulty: &Difficulty::new(),
            acc: Some(1.0),
            combo: None,
            fruits: None,
            droplets: None,
            tiny_droplets: None,
            tiny_droplet_misses: None,
            misses: Some(0),
        };

        let result = <Fast as HitResultGenerator<Catch>>::generate_hitresults(inspect);

        assert_eq!(result.fruits, N_FRUITS);
        assert_eq!(result.droplets, N_DROPLETS);
        assert_eq!(result.tiny_droplets, N_TINY_DROPLETS);
        assert_eq!(result.tiny_droplet_misses, 0);
        assert_eq!(result.misses, 0);
        assert_eq!(result.accuracy(), 1.0);
        assert_eq!(result.total_hits(), N_FRUITS + N_DROPLETS + N_TINY_DROPLETS);
    }

    #[test]
    fn high_accuracy_with_misses() {
        const N_FRUITS: u32 = 80;
        const N_DROPLETS: u32 = 40;
        const N_TINY_DROPLETS: u32 = 100;
        const MISSES: u32 = 5; // fruit/droplet misses
        const ACC: f64 = 0.95;

        let inspect = InspectCatchPerformance {
            attrs: &CatchDifficultyAttributes {
                n_fruits: N_FRUITS,
                n_droplets: N_DROPLETS,
                n_tiny_droplets: N_TINY_DROPLETS,
                ..Default::default()
            },
            difficulty: &Difficulty::new(),
            acc: Some(ACC),
            combo: None,
            fruits: None,
            droplets: None,
            tiny_droplets: None,
            tiny_droplet_misses: None,
            misses: Some(MISSES),
        };

        let result = <Fast as HitResultGenerator<Catch>>::generate_hitresults(inspect);

        // Total objects is fixed
        assert_eq!(result.total_hits(), N_FRUITS + N_DROPLETS + N_TINY_DROPLETS);
        assert_eq!(result.misses, MISSES);

        // Verify accuracy
        let actual_acc = result.accuracy();
        assert!(
            (actual_acc - ACC).abs() < 0.01,
            "Expected ~{ACC}, got {actual_acc}"
        );
    }

    #[test]
    fn medium_accuracy() {
        const N_FRUITS: u32 = 60;
        const N_DROPLETS: u32 = 30;
        const N_TINY_DROPLETS: u32 = 150;
        const MISSES: u32 = 10;
        const ACC: f64 = 0.85;

        let inspect = InspectCatchPerformance {
            attrs: &CatchDifficultyAttributes {
                n_fruits: N_FRUITS,
                n_droplets: N_DROPLETS,
                n_tiny_droplets: N_TINY_DROPLETS,
                ..Default::default()
            },
            difficulty: &Difficulty::new(),
            acc: Some(ACC),
            combo: None,
            fruits: None,
            droplets: None,
            tiny_droplets: None,
            tiny_droplet_misses: None,
            misses: Some(MISSES),
        };

        let result = <Fast as HitResultGenerator<Catch>>::generate_hitresults(inspect);

        assert_eq!(result.total_hits(), N_FRUITS + N_DROPLETS + N_TINY_DROPLETS);
        assert_eq!(result.misses, MISSES);

        let actual_acc = result.accuracy();
        assert!(
            (actual_acc - ACC).abs() < 0.01,
            "Expected ~{ACC}, got {actual_acc}"
        );
    }

    #[test]
    fn with_fruits_provided() {
        const N_FRUITS: u32 = 50;
        const N_DROPLETS: u32 = 25;
        const N_TINY_DROPLETS: u32 = 100;
        const ACC: f64 = 0.90;

        let inspect = InspectCatchPerformance {
            attrs: &CatchDifficultyAttributes {
                n_fruits: N_FRUITS,
                n_droplets: N_DROPLETS,
                n_tiny_droplets: N_TINY_DROPLETS,
                ..Default::default()
            },
            difficulty: &Difficulty::new(),
            acc: Some(ACC),
            combo: None,
            fruits: Some(45),
            droplets: None,
            tiny_droplets: None,
            tiny_droplet_misses: None,
            misses: Some(3),
        };

        let result = <Fast as HitResultGenerator<Catch>>::generate_hitresults(inspect);

        // 25 droplets are the max but with 45 fruits and 3 misses we're still
        // missing 2 hits. Since droplets are at the max and misses have the
        // highest priority, the amount of fruits needs to be adjusted to 47
        // despite being specified to be lower.
        assert_eq!(result.fruits, 47);
        assert_eq!(result.misses, 3);
        assert_eq!(result.droplets, 25);
        assert_eq!(result.total_hits(), N_FRUITS + N_DROPLETS + N_TINY_DROPLETS);

        let actual_acc = result.accuracy();
        assert!(
            (actual_acc - ACC).abs() < 0.02,
            "Expected ~{ACC}, got {actual_acc}"
        );
    }

    #[test]
    fn all_values_provided() {
        const N_FRUITS: u32 = 40;
        const N_DROPLETS: u32 = 20;
        const N_TINY_DROPLETS: u32 = 80;

        let inspect = InspectCatchPerformance {
            attrs: &CatchDifficultyAttributes {
                n_fruits: N_FRUITS,
                n_droplets: N_DROPLETS,
                n_tiny_droplets: N_TINY_DROPLETS,
                ..Default::default()
            },
            difficulty: &Difficulty::new(),
            acc: Some(0.85), // Ignored when all provided
            combo: None,
            fruits: Some(35),
            droplets: Some(18),
            tiny_droplets: Some(70),
            tiny_droplet_misses: Some(7),
            misses: Some(4),
        };

        let result = <Fast as HitResultGenerator<Catch>>::generate_hitresults(inspect);

        // Pool constraints will be enforced:
        // Fruit/droplet pool: 40 + 20 = 60, provided sum: 35 + 18 + 4 = 57 (missing 3)
        // Priority: misses > fruits > droplets
        // - droplets are capped to 20 so we assign 2 + 18 but have 1 left
        // - fruits are capped to 40 so we can assign 1 + 35
        assert_eq!(result.fruits, 36); // Adjusted from 35
        assert_eq!(result.droplets, 20); // Adjusted from 18
        assert_eq!(result.misses, 4); // Remains as given

        // Tiny droplet pool: 80, provided sum: 70 + 7 = 77 (missing 3)
        // Priority: tiny_droplets_misses > tiny_droplet, so adjust tiny_droplets: 70 + 3 = 73
        assert_eq!(result.tiny_droplets, 73); // Adjusted from 70
        assert_eq!(result.tiny_droplet_misses, 7); // Remains as given

        assert_eq!(result.total_hits(), N_FRUITS + N_DROPLETS + N_TINY_DROPLETS);
    }

    #[test]
    fn low_accuracy_many_tiny_droplet_misses() {
        const N_FRUITS: u32 = 30;
        const N_DROPLETS: u32 = 15;
        const N_TINY_DROPLETS: u32 = 60;
        const MISSES: u32 = 10;
        const ACC: f64 = 0.60;

        let inspect = InspectCatchPerformance {
            attrs: &CatchDifficultyAttributes {
                n_fruits: N_FRUITS,
                n_droplets: N_DROPLETS,
                n_tiny_droplets: N_TINY_DROPLETS,
                ..Default::default()
            },
            difficulty: &Difficulty::new(),
            acc: Some(ACC),
            combo: None,
            fruits: None,
            droplets: None,
            tiny_droplets: None,
            tiny_droplet_misses: None,
            misses: Some(MISSES),
        };

        let result = <Fast as HitResultGenerator<Catch>>::generate_hitresults(inspect);

        assert_eq!(result.total_hits(), N_FRUITS + N_DROPLETS + N_TINY_DROPLETS);
        assert_eq!(result.misses, MISSES);

        // With 60% acc on 105 objects, we need 63 catches
        // We have 10 fruit/droplet misses, so max fruit+droplet = 35
        // But we only need 63 total catches
        let catches = result.fruits + result.droplets + result.tiny_droplets;
        assert_eq!(catches, 63);

        let actual_acc = result.accuracy();
        assert!(
            (actual_acc - ACC).abs() < 0.01,
            "Expected ~{ACC}, got {actual_acc}"
        );
    }

    #[test]
    fn zero_accuracy_all_misses() {
        const N_FRUITS: u32 = 20;
        const N_DROPLETS: u32 = 10;
        const N_TINY_DROPLETS: u32 = 40;

        let inspect = InspectCatchPerformance {
            attrs: &CatchDifficultyAttributes {
                n_fruits: N_FRUITS,
                n_droplets: N_DROPLETS,
                n_tiny_droplets: N_TINY_DROPLETS,
                ..Default::default()
            },
            difficulty: &Difficulty::new(),
            acc: Some(0.0),
            combo: None,
            fruits: None,
            droplets: None,
            tiny_droplets: None,
            tiny_droplet_misses: None,
            misses: Some(N_FRUITS + N_DROPLETS), // All fruits and droplets missed
        };

        let result = <Fast as HitResultGenerator<Catch>>::generate_hitresults(inspect);

        assert_eq!(result.fruits, 0);
        assert_eq!(result.droplets, 0);
        assert_eq!(result.tiny_droplets, 0);
        assert_eq!(result.misses, 30);
        assert_eq!(result.tiny_droplet_misses, N_TINY_DROPLETS);
        assert_eq!(result.accuracy(), 0.0);
    }

    #[test]
    fn only_tiny_droplet_misses_missing() {
        const N_FRUITS: u32 = 25;
        const N_DROPLETS: u32 = 15;
        const N_TINY_DROPLETS: u32 = 50;

        let inspect = InspectCatchPerformance {
            attrs: &CatchDifficultyAttributes {
                n_fruits: N_FRUITS,
                n_droplets: N_DROPLETS,
                n_tiny_droplets: N_TINY_DROPLETS,
                ..Default::default()
            },
            difficulty: &Difficulty::new(),
            acc: Some(0.88),
            combo: None,
            fruits: Some(20),
            droplets: Some(12),
            tiny_droplets: Some(47),
            tiny_droplet_misses: None,
            misses: Some(5),
        };

        let result = <Fast as HitResultGenerator<Catch>>::generate_hitresults(inspect);

        assert_eq!(result.fruits, 20);
        assert_eq!(result.droplets, 12);
        assert_eq!(result.tiny_droplets, 47);
        assert_eq!(result.misses, 5);

        // tiny_droplet_misses = n_tiny_droplets - tiny_droplets
        assert_eq!(result.tiny_droplet_misses, N_TINY_DROPLETS - 47);

        // Note: total_hits() will be 87 not 90 because the provided values
        // (fruits=20, droplets=12, misses=5) only account for 37 of the 40 fruits+droplets
    }

    #[test]
    fn misses_clamped_to_fruits_plus_droplets() {
        const N_FRUITS: u32 = 20;
        const N_DROPLETS: u32 = 10;
        const N_TINY_DROPLETS: u32 = 30;

        let inspect = InspectCatchPerformance {
            attrs: &CatchDifficultyAttributes {
                n_fruits: N_FRUITS,
                n_droplets: N_DROPLETS,
                n_tiny_droplets: N_TINY_DROPLETS,
                ..Default::default()
            },
            difficulty: &Difficulty::new(),
            acc: Some(0.80),
            combo: None,
            fruits: None,
            droplets: None,
            tiny_droplets: None,
            tiny_droplet_misses: None,
            misses: Some(100), // Way more than possible
        };

        let result = <Fast as HitResultGenerator<Catch>>::generate_hitresults(inspect);

        // Misses should be clamped to n_fruits + n_droplets
        assert_eq!(result.misses, N_FRUITS + N_DROPLETS);
        assert_eq!(result.fruits, 0);
        assert_eq!(result.droplets, 0);
    }
}