Skip to content

Commit

Permalink
test: improve gradual testing for catch
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn committed Nov 13, 2023
1 parent ae8cc67 commit 3abdb96
Showing 1 changed file with 50 additions and 74 deletions.
124 changes: 50 additions & 74 deletions tests/gradual_catch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
))]

use rosu_pp::{
catch::{CatchGradualDifficulty, CatchGradualPerformance, CatchScoreState},
Beatmap, CatchPP, CatchStars,
catch::{
CatchGradualDifficulty, CatchGradualPerformance, CatchOwnedGradualPerformance,
CatchScoreState,
},
Beatmap, BeatmapExt, CatchPP,
};

mod common;
Expand All @@ -18,64 +21,6 @@ fn empty_map() {
assert!(attributes.next().is_none());
}

#[test]
fn iter_end_eq_regular() {
let map = test_map!(Catch);
let regular = CatchStars::new(map).calculate();

let iter_end = CatchGradualDifficulty::new(map, 0)
.last()
.expect("empty iter");

assert_eq!(regular, iter_end);
}

#[test]
fn correct_empty() {
let map = test_map!(Catch);
let mut gradual = CatchGradualPerformance::new(map, 0);
let state = CatchScoreState::default();

let first_attrs = gradual.nth(state.clone(), usize::MAX);

assert!(first_attrs.is_some());
assert!(gradual.next(state).is_none());
}

#[test]
fn next_and_next_n() {
let map = test_map!(Catch);
let state = CatchScoreState::default();

let mut gradual1 = CatchGradualPerformance::new(map, 0);
let mut gradual2 = CatchGradualPerformance::new(map, 0);

for _ in 0..20 {
let _ = gradual1.next(state.clone());
let _ = gradual2.next(state.clone());
}

let n = 80;

for _ in 1..n {
let _ = gradual1.next(state.clone());
}

let state = CatchScoreState {
max_combo: 101,
n_fruits: 99,
n_droplets: 2,
n_tiny_droplets: 68,
n_tiny_droplet_misses: 0,
n_misses: 0,
};

let next = gradual1.next(state.clone());
let next_n = gradual2.nth(state, n - 1);

assert_eq!(next_n, next);
}

#[test]
fn gradual_end_eq_regular() {
let map = test_map!(Catch);
Expand All @@ -98,23 +43,54 @@ fn gradual_end_eq_regular() {
}

#[test]
fn gradual_eq_regular_passed() {
fn gradual_complete_next() {
let map = test_map!(Catch);
let n = 100;
let mods = 88; // HDHRDT
let n_objects = dbg!(map.catch_hitobjects(mods).len());

let regular = CatchPP::new(map).passed_objects(n).calculate();
let mut gradual = CatchGradualPerformance::new(map, 0);
let mut gradual = CatchGradualPerformance::new(map, mods);
let mut gradual_2nd = CatchGradualPerformance::new(map, mods);
let mut gradual_3rd = CatchGradualPerformance::new(map, mods);
let mut gradual_owned = CatchOwnedGradualPerformance::new(map.to_owned(), mods);

let state = CatchScoreState {
max_combo: 101,
n_fruits: 99,
n_droplets: 2,
n_tiny_droplets: 68,
n_tiny_droplet_misses: 0,
n_misses: 0,
};
let mut state = CatchScoreState::default();

for i in 1.. {
state.n_misses += 1;

let Some(next_gradual) = gradual.next(state.clone()) else {
assert_eq!(i, n_objects + 1);
assert!(gradual_2nd.last(state.clone()).is_some() || n_objects % 2 == 0);
assert!(gradual_3rd.last(state.clone()).is_some() || n_objects % 3 == 0);
assert!(gradual_owned.next(state.clone()).is_none());
break;
};

if i % 2 == 0 {
let next_gradual_2nd = gradual_2nd.nth(state.clone(), 1).unwrap();
assert_eq!(next_gradual, next_gradual_2nd, "i={i}");
}

let gradual = gradual.nth(state, n - 1).unwrap();
if i % 3 == 0 {
let next_gradual_3rd = gradual_3rd.nth(state.clone(), 2).unwrap();
assert_eq!(next_gradual, next_gradual_3rd, "i={i}");
}

assert_eq!(regular, gradual);
let next_gradual_owned = gradual_owned.next(state.clone()).unwrap();

let mut regular_calc = CatchPP::new(map)
.mods(mods)
.passed_objects(i)
.state(state.clone());

let _regular_state = regular_calc.generate_state();
// FIXME: juicestreams are currently added to the attributes in their entirety
// so the state won't change while objects of the same juicestream are processed
// assert_eq!(state, _regular_state);

let regular = regular_calc.calculate();

assert_eq!(next_gradual, next_gradual_owned, "i={i}");
assert_eq!(next_gradual, regular, "i={i}");
}
}

0 comments on commit 3abdb96

Please sign in to comment.