osu & fruits: added unit test for SliderState

This commit is contained in:
MaxOhn
2021-01-22 16:35:50 +01:00
parent 52979f790f
commit 91819063c6
5 changed files with 105 additions and 0 deletions
+51
View File
@@ -41,3 +41,54 @@ impl<'p> SliderState<'p> {
}
}
}
#[cfg(test)]
mod test {
use crate::{Beatmap, DifficultyPoint, TimingPoint};
use super::SliderState;
#[test]
fn fruits_slider_state() {
let map = Beatmap {
timing_points: vec![
TimingPoint {
time: 1.0,
beat_len: 10.0,
},
TimingPoint {
time: 3.0,
beat_len: 20.0,
},
TimingPoint {
time: 4.0,
beat_len: 30.0,
},
],
difficulty_points: vec![
DifficultyPoint {
time: 2.0,
speed_multiplier: 15.0,
},
DifficultyPoint {
time: 5.0,
speed_multiplier: 45.0,
},
],
..Default::default()
};
let mut state = SliderState::new(&map);
state.update(2.0);
assert_eq!(state.beat_len, 10.0);
state.update(3.0);
assert_eq!(state.beat_len, 20.0);
assert_eq!(state.speed_mult, 1.0);
state.update(5.0);
assert_eq!(state.beat_len, 30.0);
assert_eq!(state.speed_mult, 45.0);
}
}
+1
View File
@@ -126,6 +126,7 @@ pub(crate) struct DifficultyHitObject<'o> {
}
impl<'o> DifficultyHitObject<'o> {
#[inline]
fn new(base: &'o HitObject, prev: &'o HitObject, cs: f32, clock_rate: f32) -> Self {
let x_divisor = 512.0 / cs;
let column = (base.pos.x / x_divisor).floor() as usize;
+1
View File
@@ -181,6 +181,7 @@ impl ManiaAttributeProvider for StarResult {
}
impl ManiaAttributeProvider for PpResult {
#[inline]
fn attributes(self) -> Option<f32> {
self.attributes.attributes()
}
@@ -41,3 +41,54 @@ impl<'p> SliderState<'p> {
}
}
}
#[cfg(test)]
mod test {
use crate::{Beatmap, DifficultyPoint, TimingPoint};
use super::SliderState;
#[test]
fn osu_slider_state() {
let map = Beatmap {
timing_points: vec![
TimingPoint {
time: 1.0,
beat_len: 10.0,
},
TimingPoint {
time: 3.0,
beat_len: 20.0,
},
TimingPoint {
time: 4.0,
beat_len: 30.0,
},
],
difficulty_points: vec![
DifficultyPoint {
time: 2.0,
speed_multiplier: 15.0,
},
DifficultyPoint {
time: 5.0,
speed_multiplier: 45.0,
},
],
..Default::default()
};
let mut state = SliderState::new(&map);
state.update(2.0);
assert_eq!(state.beat_len, 10.0);
state.update(3.0);
assert_eq!(state.beat_len, 20.0);
assert_eq!(state.speed_mult, 1.0);
state.update(5.0);
assert_eq!(state.beat_len, 30.0);
assert_eq!(state.speed_mult, 45.0);
}
}
+1
View File
@@ -210,6 +210,7 @@ impl TaikoAttributeProvider for StarResult {
}
impl TaikoAttributeProvider for PpResult {
#[inline]
fn attributes(self) -> Option<f32> {
self.attributes.attributes()
}