add & fix: async tests
This commit is contained in:
+4
-2
@@ -1155,13 +1155,15 @@ mod tests {
|
||||
}
|
||||
|
||||
async fn parse_async(map_id: i32) {
|
||||
use async_std::fs::File;
|
||||
|
||||
println!("map_id: {}", map_id);
|
||||
let file = match File::open(format!("./maps/{}.osu", map_id)) {
|
||||
let file = match File::open(format!("./maps/{}.osu", map_id)).await {
|
||||
Ok(file) => file,
|
||||
Err(why) => panic!("Could not read file: {}", why),
|
||||
};
|
||||
|
||||
let map = match Beatmap::parse(file) {
|
||||
let map = match Beatmap::parse_async(file).await {
|
||||
Ok(map) => map,
|
||||
Err(why) => panic!("Error while parsing map: {}", why),
|
||||
};
|
||||
|
||||
@@ -67,6 +67,66 @@ fn fruits() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "async_std")]
|
||||
#[test]
|
||||
fn fruits_async() {
|
||||
use async_std::{fs::File, task};
|
||||
|
||||
task::block_on(async {
|
||||
let star_margin = 0.0001;
|
||||
let pp_margin = 0.0001;
|
||||
|
||||
for result in RESULTS {
|
||||
let MapResult {
|
||||
map_id,
|
||||
mods,
|
||||
stars,
|
||||
pp,
|
||||
} = result;
|
||||
|
||||
let file = match File::open(format!("./maps/{}.osu", map_id)).await {
|
||||
Ok(file) => file,
|
||||
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why),
|
||||
};
|
||||
|
||||
let map = match Beatmap::parse_async(file).await {
|
||||
Ok(map) => map,
|
||||
Err(why) => panic!("Error while parsing map {}: {}", map_id, why),
|
||||
};
|
||||
|
||||
let result = rosu_pp::FruitsPP::new(&map).mods(*mods).calculate();
|
||||
|
||||
assert!(
|
||||
(result.stars() - stars).abs() < star_margin * stars,
|
||||
"\nStars:\n\
|
||||
Calculated: {calculated} | Expected: {expected}\n \
|
||||
=> {margin} margin ({allowed} allowed)\n\
|
||||
[map {map} | mods {mods}]\n",
|
||||
calculated = result.stars(),
|
||||
expected = stars,
|
||||
margin = (result.stars() - stars).abs(),
|
||||
allowed = star_margin * stars,
|
||||
map = map_id,
|
||||
mods = mods
|
||||
);
|
||||
|
||||
assert!(
|
||||
(result.pp() - pp).abs() < pp_margin * pp,
|
||||
"\nPP:\n\
|
||||
Calculated: {calculated} | Expected: {expected}\n \
|
||||
=> {margin} margin ({allowed} allowed)\n\
|
||||
[map {map} | mods {mods}]\n",
|
||||
calculated = result.pp(),
|
||||
expected = pp,
|
||||
margin = (result.pp() - pp).abs(),
|
||||
allowed = pp_margin * pp,
|
||||
map = map_id,
|
||||
mods = mods
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const RESULTS: &[MapResult] = &[
|
||||
MapResult {
|
||||
map_id: 1977380,
|
||||
|
||||
@@ -67,6 +67,66 @@ fn mania() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "async_std")]
|
||||
#[test]
|
||||
fn mania_async() {
|
||||
use async_std::{fs::File, task};
|
||||
|
||||
task::block_on(async {
|
||||
let star_margin = 0.00001;
|
||||
let pp_margin = 0.00001;
|
||||
|
||||
for result in RESULTS {
|
||||
let MapResult {
|
||||
map_id,
|
||||
mods,
|
||||
stars,
|
||||
pp,
|
||||
} = result;
|
||||
|
||||
let file = match File::open(format!("./maps/{}.osu", map_id)).await {
|
||||
Ok(file) => file,
|
||||
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why),
|
||||
};
|
||||
|
||||
let map = match Beatmap::parse_async(file).await {
|
||||
Ok(map) => map,
|
||||
Err(why) => panic!("Error while parsing map {}: {}", map_id, why),
|
||||
};
|
||||
|
||||
let result = rosu_pp::ManiaPP::new(&map).mods(*mods).calculate();
|
||||
|
||||
assert!(
|
||||
(result.stars() - stars).abs() < star_margin * stars,
|
||||
"\nStars:\n\
|
||||
Calculated: {calculated} | Expected: {expected}\n \
|
||||
=> {margin} margin ({allowed} allowed)\n\
|
||||
[map {map} | mods {mods}]\n",
|
||||
calculated = result.stars(),
|
||||
expected = stars,
|
||||
margin = (result.stars() - stars).abs(),
|
||||
allowed = star_margin * stars,
|
||||
map = map_id,
|
||||
mods = mods
|
||||
);
|
||||
|
||||
assert!(
|
||||
(result.pp() - pp).abs() < pp_margin * pp,
|
||||
"\nPP:\n\
|
||||
Calculated: {calculated} | Expected: {expected}\n \
|
||||
=> {margin} margin ({allowed} allowed)\n\
|
||||
[map {map} | mods {mods}]\n",
|
||||
calculated = result.pp(),
|
||||
expected = pp,
|
||||
margin = (result.pp() - pp).abs(),
|
||||
allowed = pp_margin * pp,
|
||||
map = map_id,
|
||||
mods = mods
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const RESULTS: &[MapResult] = &[
|
||||
MapResult {
|
||||
map_id: 1355822,
|
||||
|
||||
@@ -77,6 +77,76 @@ fn osu() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "async_std")]
|
||||
#[test]
|
||||
fn osu_async() {
|
||||
use async_std::{fs::File, task};
|
||||
|
||||
task::block_on(async {
|
||||
let margin = if cfg!(feature = "no_sliders_no_leniency") {
|
||||
0.0075
|
||||
} else if cfg!(feature = "no_leniency") {
|
||||
0.0025
|
||||
} else if cfg!(feature = "all_included") {
|
||||
0.001
|
||||
} else {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
let star_margin = margin;
|
||||
let pp_margin = margin;
|
||||
|
||||
for result in RESULTS {
|
||||
let MapResult {
|
||||
map_id,
|
||||
mods,
|
||||
stars,
|
||||
pp,
|
||||
} = result;
|
||||
|
||||
let file = match File::open(format!("./maps/{}.osu", map_id)).await {
|
||||
Ok(file) => file,
|
||||
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why),
|
||||
};
|
||||
|
||||
let map = match Beatmap::parse_async(file).await {
|
||||
Ok(map) => map,
|
||||
Err(why) => panic!("Error while parsing map {}: {}", map_id, why),
|
||||
};
|
||||
|
||||
let result = rosu_pp::OsuPP::new(&map).mods(*mods).calculate();
|
||||
|
||||
assert!(
|
||||
(result.stars() - stars).abs() < star_margin * stars,
|
||||
"\nStars:\n\
|
||||
Calculated: {calculated} | Expected: {expected}\n \
|
||||
=> {margin} margin ({allowed} allowed)\n\
|
||||
[map {map} | mods {mods}]\n",
|
||||
calculated = result.stars(),
|
||||
expected = stars,
|
||||
margin = (result.stars() - stars).abs(),
|
||||
allowed = star_margin * stars,
|
||||
map = map_id,
|
||||
mods = mods
|
||||
);
|
||||
|
||||
assert!(
|
||||
(result.pp() - pp).abs() < pp_margin * pp,
|
||||
"\nPP:\n\
|
||||
Calculated: {calculated} | Expected: {expected}\n \
|
||||
=> {margin} margin ({allowed} allowed)\n\
|
||||
[map {map} | mods {mods}]\n",
|
||||
calculated = result.pp(),
|
||||
expected = pp,
|
||||
margin = (result.pp() - pp).abs(),
|
||||
allowed = pp_margin * pp,
|
||||
map = map_id,
|
||||
mods = mods
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const RESULTS: &[MapResult] = &[
|
||||
MapResult {
|
||||
map_id: 1851299,
|
||||
|
||||
@@ -67,6 +67,66 @@ fn taiko() {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "async_std")]
|
||||
#[test]
|
||||
fn taiko_async() {
|
||||
use async_std::{fs::File, task};
|
||||
|
||||
task::block_on(async {
|
||||
let star_margin = 0.0001;
|
||||
let pp_margin = 0.0001;
|
||||
|
||||
for result in RESULTS {
|
||||
let MapResult {
|
||||
map_id,
|
||||
mods,
|
||||
stars,
|
||||
pp,
|
||||
} = result;
|
||||
|
||||
let file = match File::open(format!("./maps/{}.osu", map_id)).await {
|
||||
Ok(file) => file,
|
||||
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why),
|
||||
};
|
||||
|
||||
let map = match Beatmap::parse_async(file).await {
|
||||
Ok(map) => map,
|
||||
Err(why) => panic!("Error while parsing map {}: {}", map_id, why),
|
||||
};
|
||||
|
||||
let result = rosu_pp::TaikoPP::new(&map).mods(*mods).calculate();
|
||||
|
||||
assert!(
|
||||
(result.stars() - stars).abs() < star_margin * stars,
|
||||
"\nStars:\n\
|
||||
Calculated: {calculated} | Expected: {expected}\n \
|
||||
=> {margin} margin ({allowed} allowed)\n\
|
||||
[map {map} | mods {mods}]\n",
|
||||
calculated = result.stars(),
|
||||
expected = stars,
|
||||
margin = (result.stars() - stars).abs(),
|
||||
allowed = star_margin * stars,
|
||||
map = map_id,
|
||||
mods = mods
|
||||
);
|
||||
|
||||
assert!(
|
||||
(result.pp() - pp).abs() < pp_margin * pp,
|
||||
"\nPP:\n\
|
||||
Calculated: {calculated} | Expected: {expected}\n \
|
||||
=> {margin} margin ({allowed} allowed)\n\
|
||||
[map {map} | mods {mods}]\n",
|
||||
calculated = result.pp(),
|
||||
expected = pp,
|
||||
margin = (result.pp() - pp).abs(),
|
||||
allowed = pp_margin * pp,
|
||||
map = map_id,
|
||||
mods = mods
|
||||
);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const RESULTS: &[MapResult] = &[
|
||||
MapResult {
|
||||
map_id: 110219,
|
||||
|
||||
Reference in New Issue
Block a user