Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn committed Mar 31, 2024
1 parent 193f8fa commit 94706bc
Show file tree
Hide file tree
Showing 5 changed files with 297 additions and 20 deletions.
63 changes: 63 additions & 0 deletions src/any/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,66 @@ impl<'a, T: IntoPerformance<'a>> From<T> for Performance<'a> {
into.into_performance()
}
}

#[cfg(test)]
mod tests {
use crate::{
any::DifficultyAttributes,
catch::{CatchDifficultyAttributes, CatchPerformanceAttributes},
mania::{ManiaDifficultyAttributes, ManiaPerformanceAttributes},
osu::{OsuDifficultyAttributes, OsuPerformanceAttributes},
taiko::{Taiko, TaikoDifficultyAttributes, TaikoPerformanceAttributes},
Beatmap,
};

use super::*;

#[test]
fn create() {
let map = Beatmap::from_path("./resources/1028484.osu").unwrap();
let converted = map.unchecked_as_converted::<Taiko>();

let _ = Performance::new(&converted);
let _ = Performance::new(converted.as_owned());
let _ = Performance::new(&map);
let _ = Performance::new(map.clone());

let _ = Performance::new(OsuDifficultyAttributes::default());
let _ = Performance::new(TaikoDifficultyAttributes::default());
let _ = Performance::new(CatchDifficultyAttributes::default());
let _ = Performance::new(ManiaDifficultyAttributes::default());

let _ = Performance::new(OsuPerformanceAttributes::default());
let _ = Performance::new(TaikoPerformanceAttributes::default());
let _ = Performance::new(CatchPerformanceAttributes::default());
let _ = Performance::new(ManiaPerformanceAttributes::default());

let _ = Performance::new(DifficultyAttributes::Osu(OsuDifficultyAttributes::default()));
let _ = Performance::new(PerformanceAttributes::Taiko(
TaikoPerformanceAttributes::default(),
));

let _ = Performance::from(&converted);
let _ = Performance::from(converted);
let _ = Performance::from(&map);
let _ = Performance::from(map);

let _ = Performance::from(OsuDifficultyAttributes::default());
let _ = Performance::from(TaikoDifficultyAttributes::default());
let _ = Performance::from(CatchDifficultyAttributes::default());
let _ = Performance::from(ManiaDifficultyAttributes::default());

let _ = Performance::from(OsuPerformanceAttributes::default());
let _ = Performance::from(TaikoPerformanceAttributes::default());
let _ = Performance::from(CatchPerformanceAttributes::default());
let _ = Performance::from(ManiaPerformanceAttributes::default());

let _ = Performance::from(DifficultyAttributes::Osu(OsuDifficultyAttributes::default()));
let _ = Performance::from(PerformanceAttributes::Taiko(
TaikoPerformanceAttributes::default(),
));

let _ = DifficultyAttributes::Osu(OsuDifficultyAttributes::default()).performance();
let _ = PerformanceAttributes::Taiko(TaikoPerformanceAttributes::default()).performance();
}
}
64 changes: 59 additions & 5 deletions src/catch/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,13 @@ mod test {
use std::sync::OnceLock;

use proptest::prelude::*;
use rosu_map::section::general::GameMode;

use crate::Beatmap;
use crate::{
any::{DifficultyAttributes, PerformanceAttributes},
osu::{Osu, OsuDifficultyAttributes, OsuPerformanceAttributes},
Beatmap,
};

use super::*;

Expand All @@ -610,13 +615,14 @@ mod test {
const N_DROPLETS: u32 = 2;
const N_TINY_DROPLETS: u32 = 291;

fn beatmap() -> Beatmap {
Beatmap::from_path("./resources/2118524.osu").unwrap()
}

fn attrs() -> CatchDifficultyAttributes {
ATTRS
.get_or_init(|| {
let converted = Beatmap::from_path("./resources/2118524.osu")
.unwrap()
.unchecked_into_converted::<Catch>();

let converted = beatmap().unchecked_into_converted::<Catch>();
let attrs = Difficulty::new().with_mode().calculate(&converted);

assert_eq!(N_FRUITS, attrs.n_fruits);
Expand Down Expand Up @@ -808,4 +814,52 @@ mod test {

assert_eq!(state, expected);
}

#[test]
fn create() {
let mut map = beatmap();
let converted = map.unchecked_as_converted();

let _ = CatchPerformance::new(CatchDifficultyAttributes::default());
let _ = CatchPerformance::new(CatchPerformanceAttributes::default());
let _ = CatchPerformance::new(&converted);
let _ = CatchPerformance::new(converted.as_owned());

let _ = CatchPerformance::try_new(CatchDifficultyAttributes::default()).unwrap();
let _ = CatchPerformance::try_new(CatchPerformanceAttributes::default()).unwrap();
let _ = CatchPerformance::try_new(DifficultyAttributes::Catch(
CatchDifficultyAttributes::default(),
))
.unwrap();
let _ = CatchPerformance::try_new(PerformanceAttributes::Catch(
CatchPerformanceAttributes::default(),
))
.unwrap();
let _ = CatchPerformance::try_new(&converted).unwrap();
let _ = CatchPerformance::try_new(converted.as_owned()).unwrap();

let _ = CatchPerformance::from(CatchDifficultyAttributes::default());
let _ = CatchPerformance::from(CatchPerformanceAttributes::default());
let _ = CatchPerformance::from(&converted);
let _ = CatchPerformance::from(converted);

let _ = CatchDifficultyAttributes::default().performance();
let _ = CatchPerformanceAttributes::default().performance();

map.mode = GameMode::Osu;
let converted = map.unchecked_as_converted::<Osu>();

assert!(CatchPerformance::try_new(OsuDifficultyAttributes::default()).is_none());
assert!(CatchPerformance::try_new(OsuPerformanceAttributes::default()).is_none());
assert!(CatchPerformance::try_new(DifficultyAttributes::Osu(
OsuDifficultyAttributes::default()
))
.is_none());
assert!(CatchPerformance::try_new(PerformanceAttributes::Osu(
OsuPerformanceAttributes::default()
))
.is_none());
assert!(CatchPerformance::try_new(&converted).is_none());
assert!(CatchPerformance::try_new(converted).is_none());
}
}
64 changes: 59 additions & 5 deletions src/mania/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,22 +935,28 @@ mod tests {
use std::{cmp::Ordering, sync::OnceLock};

use proptest::prelude::*;
use rosu_map::section::general::GameMode;

use crate::Beatmap;
use crate::{
any::{DifficultyAttributes, PerformanceAttributes},
osu::{Osu, OsuDifficultyAttributes, OsuPerformanceAttributes},
Beatmap,
};

use super::*;

static ATTRS: OnceLock<ManiaDifficultyAttributes> = OnceLock::new();

const N_OBJECTS: u32 = 594;

fn beatmap() -> Beatmap {
Beatmap::from_path("./resources/1638954.osu").unwrap()
}

fn attrs() -> ManiaDifficultyAttributes {
ATTRS
.get_or_init(|| {
let converted = Beatmap::from_path("./resources/1638954.osu")
.unwrap()
.unchecked_into_converted::<Mania>();

let converted = beatmap().unchecked_into_converted::<Mania>();
let attrs = Difficulty::new().with_mode().calculate(&converted);

assert_eq!(N_OBJECTS, converted.hit_objects.len() as u32);
Expand Down Expand Up @@ -1286,4 +1292,52 @@ mod tests {

assert_eq!(state, expected);
}

#[test]
fn create() {
let mut map = beatmap();
let converted = map.unchecked_as_converted();

let _ = ManiaPerformance::new(ManiaDifficultyAttributes::default());
let _ = ManiaPerformance::new(ManiaPerformanceAttributes::default());
let _ = ManiaPerformance::new(&converted);
let _ = ManiaPerformance::new(converted.as_owned());

let _ = ManiaPerformance::try_new(ManiaDifficultyAttributes::default()).unwrap();
let _ = ManiaPerformance::try_new(ManiaPerformanceAttributes::default()).unwrap();
let _ = ManiaPerformance::try_new(DifficultyAttributes::Mania(
ManiaDifficultyAttributes::default(),
))
.unwrap();
let _ = ManiaPerformance::try_new(PerformanceAttributes::Mania(
ManiaPerformanceAttributes::default(),
))
.unwrap();
let _ = ManiaPerformance::try_new(&converted).unwrap();
let _ = ManiaPerformance::try_new(converted.as_owned()).unwrap();

let _ = ManiaPerformance::from(ManiaDifficultyAttributes::default());
let _ = ManiaPerformance::from(ManiaPerformanceAttributes::default());
let _ = ManiaPerformance::from(&converted);
let _ = ManiaPerformance::from(converted);

let _ = ManiaDifficultyAttributes::default().performance();
let _ = ManiaPerformanceAttributes::default().performance();

map.mode = GameMode::Osu;
let converted = map.unchecked_as_converted::<Osu>();

assert!(ManiaPerformance::try_new(OsuDifficultyAttributes::default()).is_none());
assert!(ManiaPerformance::try_new(OsuPerformanceAttributes::default()).is_none());
assert!(ManiaPerformance::try_new(DifficultyAttributes::Osu(
OsuDifficultyAttributes::default()
))
.is_none());
assert!(ManiaPerformance::try_new(PerformanceAttributes::Osu(
OsuPerformanceAttributes::default()
))
.is_none());
assert!(ManiaPerformance::try_new(&converted).is_none());
assert!(ManiaPerformance::try_new(converted).is_none());
}
}
62 changes: 57 additions & 5 deletions src/osu/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,21 +872,26 @@ mod test {

use proptest::prelude::*;

use crate::Beatmap;
use crate::{
any::{DifficultyAttributes, PerformanceAttributes},
taiko::{Taiko, TaikoDifficultyAttributes, TaikoPerformanceAttributes},
Beatmap,
};

use super::*;

static ATTRS: OnceLock<OsuDifficultyAttributes> = OnceLock::new();

const N_OBJECTS: u32 = 601;

fn beatmap() -> Beatmap {
Beatmap::from_path("./resources/2785319.osu").unwrap()
}

fn attrs() -> OsuDifficultyAttributes {
ATTRS
.get_or_init(|| {
let converted = Beatmap::from_path("./resources/2785319.osu")
.unwrap()
.unchecked_into_converted::<Osu>();

let converted = beatmap().unchecked_into_converted::<Osu>();
let attrs = Difficulty::new().with_mode().calculate(&converted);

assert_eq!(
Expand Down Expand Up @@ -1133,4 +1138,51 @@ mod test {

assert_eq!(state, expected);
}

#[test]
fn create() {
let mut map = beatmap();
let converted = map.unchecked_as_converted();

let _ = OsuPerformance::new(OsuDifficultyAttributes::default());
let _ = OsuPerformance::new(OsuPerformanceAttributes::default());
let _ = OsuPerformance::new(&converted);
let _ = OsuPerformance::new(converted.as_owned());

let _ = OsuPerformance::try_new(OsuDifficultyAttributes::default()).unwrap();
let _ = OsuPerformance::try_new(OsuPerformanceAttributes::default()).unwrap();
let _ =
OsuPerformance::try_new(DifficultyAttributes::Osu(OsuDifficultyAttributes::default()))
.unwrap();
let _ = OsuPerformance::try_new(PerformanceAttributes::Osu(
OsuPerformanceAttributes::default(),
))
.unwrap();
let _ = OsuPerformance::try_new(&converted).unwrap();
let _ = OsuPerformance::try_new(converted.as_owned()).unwrap();

let _ = OsuPerformance::from(OsuDifficultyAttributes::default());
let _ = OsuPerformance::from(OsuPerformanceAttributes::default());
let _ = OsuPerformance::from(&converted);
let _ = OsuPerformance::from(converted);

let _ = OsuDifficultyAttributes::default().performance();
let _ = OsuPerformanceAttributes::default().performance();

map.mode = GameMode::Taiko;
let converted = map.unchecked_as_converted::<Taiko>();

assert!(OsuPerformance::try_new(TaikoDifficultyAttributes::default()).is_none());
assert!(OsuPerformance::try_new(TaikoPerformanceAttributes::default()).is_none());
assert!(OsuPerformance::try_new(DifficultyAttributes::Taiko(
TaikoDifficultyAttributes::default()
))
.is_none());
assert!(OsuPerformance::try_new(PerformanceAttributes::Taiko(
TaikoPerformanceAttributes::default()
))
.is_none());
assert!(OsuPerformance::try_new(&converted).is_none());
assert!(OsuPerformance::try_new(converted).is_none());
}
}
Loading

0 comments on commit 94706bc

Please sign in to comment.