slight integration test restructure

This commit is contained in:
MaxOhn
2021-04-28 21:38:23 +02:00
parent bb6ee0332c
commit 2707f1aabc
4 changed files with 140 additions and 224 deletions
+28 -48
View File
@@ -30,13 +30,10 @@ macro_rules! assert_result {
}; };
} }
#[cfg(not(any(feature = "async_std", feature = "async_tokio")))] fn fruits_test(map: Beatmap, result: &MapResult) {
#[test]
fn fruits_sync() {
let star_margin = 0.0001; let star_margin = 0.0001;
let pp_margin = 0.0001; let pp_margin = 0.0001;
for result in RESULTS {
let MapResult { let MapResult {
map_id, map_id,
mods, mods,
@@ -44,21 +41,28 @@ fn fruits_sync() {
pp, pp,
} = result; } = result;
let file = match std::fs::File::open(format!("./maps/{}.osu", map_id)) {
Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why),
};
let map = match Beatmap::parse(file) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why),
};
let result = rosu_pp::FruitsPP::new(&map).mods(*mods).calculate(); let result = rosu_pp::FruitsPP::new(&map).mods(*mods).calculate();
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods); assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods); assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
#[cfg(not(any(feature = "async_std", feature = "async_tokio")))]
#[test]
fn fruits_sync() {
for result in RESULTS {
let file = match std::fs::File::open(format!("./maps/{}.osu", result.map_id)) {
Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
};
let map = match Beatmap::parse(file) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
};
fruits_test(map, result);
}
} }
#[cfg(feature = "async_tokio")] #[cfg(feature = "async_tokio")]
@@ -67,31 +71,19 @@ fn fruits_async_tokio() {
tokio::runtime::Runtime::new() tokio::runtime::Runtime::new()
.expect("could not start runtime") .expect("could not start runtime")
.block_on(async { .block_on(async {
let star_margin = 0.0001;
let pp_margin = 0.0001;
for result in RESULTS { for result in RESULTS {
let MapResult { let file =
map_id, match tokio::fs::File::open(format!("./maps/{}.osu", result.map_id)).await {
mods,
stars,
pp,
} = result;
let file = match tokio::fs::File::open(format!("./maps/{}.osu", map_id)).await {
Ok(file) => file, Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why), Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
}; };
let map = match Beatmap::parse(file).await { let map = match Beatmap::parse(file).await {
Ok(map) => map, Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why), Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
}; };
let result = rosu_pp::FruitsPP::new(&map).mods(*mods).calculate(); fruits_test(map, result);
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
}); });
} }
@@ -100,31 +92,19 @@ fn fruits_async_tokio() {
#[test] #[test]
fn fruits_async_std() { fn fruits_async_std() {
async_std::task::block_on(async { async_std::task::block_on(async {
let star_margin = 0.0001;
let pp_margin = 0.0001;
for result in RESULTS { for result in RESULTS {
let MapResult { let file =
map_id, match async_std::fs::File::open(format!("./maps/{}.osu", result.map_id)).await {
mods,
stars,
pp,
} = result;
let file = match async_std::fs::File::open(format!("./maps/{}.osu", map_id)).await {
Ok(file) => file, Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why), Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
}; };
let map = match Beatmap::parse(file).await { let map = match Beatmap::parse(file).await {
Ok(map) => map, Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why), Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
}; };
let result = rosu_pp::FruitsPP::new(&map).mods(*mods).calculate(); fruits_test(map, result);
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
}) })
} }
+28 -48
View File
@@ -30,13 +30,10 @@ macro_rules! assert_result {
}; };
} }
#[cfg(not(any(feature = "async_std", feature = "async_tokio")))] fn mania_test(map: Beatmap, result: &MapResult) {
#[test]
fn mania_sync() {
let star_margin = 0.00001; let star_margin = 0.00001;
let pp_margin = 0.00001; let pp_margin = 0.00001;
for result in RESULTS {
let MapResult { let MapResult {
map_id, map_id,
mods, mods,
@@ -44,21 +41,28 @@ fn mania_sync() {
pp, pp,
} = result; } = result;
let file = match std::fs::File::open(format!("./maps/{}.osu", map_id)) {
Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why),
};
let map = match Beatmap::parse(file) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why),
};
let result = rosu_pp::ManiaPP::new(&map).mods(*mods).calculate(); let result = rosu_pp::ManiaPP::new(&map).mods(*mods).calculate();
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods); assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods); assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
#[cfg(not(any(feature = "async_std", feature = "async_tokio")))]
#[test]
fn mania_sync() {
for result in RESULTS {
let file = match std::fs::File::open(format!("./maps/{}.osu", result.map_id)) {
Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
};
let map = match Beatmap::parse(file) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
};
mania_test(map, result);
}
} }
#[cfg(feature = "async_tokio")] #[cfg(feature = "async_tokio")]
@@ -67,31 +71,19 @@ fn mania_async_tokio() {
tokio::runtime::Runtime::new() tokio::runtime::Runtime::new()
.expect("could not start runtime") .expect("could not start runtime")
.block_on(async { .block_on(async {
let star_margin = 0.00001;
let pp_margin = 0.00001;
for result in RESULTS { for result in RESULTS {
let MapResult { let file =
map_id, match tokio::fs::File::open(format!("./maps/{}.osu", result.map_id)).await {
mods,
stars,
pp,
} = result;
let file = match tokio::fs::File::open(format!("./maps/{}.osu", map_id)).await {
Ok(file) => file, Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why), Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
}; };
let map = match Beatmap::parse(file).await { let map = match Beatmap::parse(file).await {
Ok(map) => map, Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why), Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
}; };
let result = rosu_pp::ManiaPP::new(&map).mods(*mods).calculate(); mania_test(map, result);
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
}); });
} }
@@ -100,31 +92,19 @@ fn mania_async_tokio() {
#[test] #[test]
fn mania_async_std() { fn mania_async_std() {
async_std::task::block_on(async { async_std::task::block_on(async {
let star_margin = 0.00001;
let pp_margin = 0.00001;
for result in RESULTS { for result in RESULTS {
let MapResult { let file =
map_id, match async_std::fs::File::open(format!("./maps/{}.osu", result.map_id)).await {
mods,
stars,
pp,
} = result;
let file = match async_std::fs::File::open(format!("./maps/{}.osu", map_id)).await {
Ok(file) => file, Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why), Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
}; };
let map = match Beatmap::parse(file).await { let map = match Beatmap::parse(file).await {
Ok(map) => map, Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why), Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
}; };
let result = rosu_pp::ManiaPP::new(&map).mods(*mods).calculate(); mania_test(map, result);
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
}) })
} }
+28 -52
View File
@@ -42,15 +42,12 @@ fn margin() -> f32 {
} }
} }
#[cfg(not(any(feature = "async_std", feature = "async_tokio")))] fn osu_test(map: Beatmap, result: &MapResult) {
#[test]
fn osu_sync() {
let margin = margin(); let margin = margin();
let star_margin = margin; let star_margin = margin;
let pp_margin = margin; let pp_margin = margin;
for result in RESULTS {
let MapResult { let MapResult {
map_id, map_id,
mods, mods,
@@ -58,21 +55,28 @@ fn osu_sync() {
pp, pp,
} = result; } = result;
let file = match std::fs::File::open(format!("./maps/{}.osu", map_id)) {
Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why),
};
let map = match Beatmap::parse(file) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why),
};
let result = rosu_pp::OsuPP::new(&map).mods(*mods).calculate(); let result = rosu_pp::OsuPP::new(&map).mods(*mods).calculate();
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods); assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods); assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
#[cfg(not(any(feature = "async_std", feature = "async_tokio")))]
#[test]
fn osu_sync() {
for result in RESULTS {
let file = match std::fs::File::open(format!("./maps/{}.osu", result.map_id)) {
Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
};
let map = match Beatmap::parse(file) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
};
osu_test(map, result);
}
} }
#[cfg(feature = "async_tokio")] #[cfg(feature = "async_tokio")]
@@ -81,33 +85,19 @@ fn osu_async_tokio() {
tokio::runtime::Runtime::new() tokio::runtime::Runtime::new()
.expect("could not start runtime") .expect("could not start runtime")
.block_on(async { .block_on(async {
let margin = margin();
let star_margin = margin;
let pp_margin = margin;
for result in RESULTS { for result in RESULTS {
let MapResult { let file =
map_id, match tokio::fs::File::open(format!("./maps/{}.osu", result.map_id)).await {
mods,
stars,
pp,
} = result;
let file = match tokio::fs::File::open(format!("./maps/{}.osu", map_id)).await {
Ok(file) => file, Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why), Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
}; };
let map = match Beatmap::parse(file).await { let map = match Beatmap::parse(file).await {
Ok(map) => map, Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why), Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
}; };
let result = rosu_pp::OsuPP::new(&map).mods(*mods).calculate(); osu_test(map, result);
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
}); });
} }
@@ -116,33 +106,19 @@ fn osu_async_tokio() {
#[test] #[test]
fn osu_async_std() { fn osu_async_std() {
async_std::task::block_on(async { async_std::task::block_on(async {
let margin = margin();
let star_margin = margin;
let pp_margin = margin;
for result in RESULTS { for result in RESULTS {
let MapResult { let file =
map_id, match async_std::fs::File::open(format!("./maps/{}.osu", result.map_id)).await {
mods,
stars,
pp,
} = result;
let file = match async_std::fs::File::open(format!("./maps/{}.osu", map_id)).await {
Ok(file) => file, Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why), Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
}; };
let map = match Beatmap::parse(file).await { let map = match Beatmap::parse(file).await {
Ok(map) => map, Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why), Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
}; };
let result = rosu_pp::OsuPP::new(&map).mods(*mods).calculate(); osu_test(map, result);
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
}) })
} }
+28 -48
View File
@@ -30,13 +30,10 @@ macro_rules! assert_result {
}; };
} }
#[cfg(not(any(feature = "async_std", feature = "async_tokio")))] fn taiko_test(map: Beatmap, result: &MapResult) {
#[test]
fn taiko_sync() {
let star_margin = 0.0001; let star_margin = 0.0001;
let pp_margin = 0.0001; let pp_margin = 0.0001;
for result in RESULTS {
let MapResult { let MapResult {
map_id, map_id,
mods, mods,
@@ -44,21 +41,28 @@ fn taiko_sync() {
pp, pp,
} = result; } = result;
let file = match std::fs::File::open(format!("./maps/{}.osu", map_id)) {
Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why),
};
let map = match Beatmap::parse(file) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why),
};
let result = rosu_pp::TaikoPP::new(&map).mods(*mods).calculate(); let result = rosu_pp::TaikoPP::new(&map).mods(*mods).calculate();
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods); assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods); assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
#[cfg(not(any(feature = "async_std", feature = "async_tokio")))]
#[test]
fn taiko_sync() {
for result in RESULTS {
let file = match std::fs::File::open(format!("./maps/{}.osu", result.map_id)) {
Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
};
let map = match Beatmap::parse(file) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
};
taiko_test(map, result);
}
} }
#[cfg(feature = "async_tokio")] #[cfg(feature = "async_tokio")]
@@ -67,31 +71,19 @@ fn taiko_async_tokio() {
tokio::runtime::Runtime::new() tokio::runtime::Runtime::new()
.expect("could not start runtime") .expect("could not start runtime")
.block_on(async { .block_on(async {
let star_margin = 0.0001;
let pp_margin = 0.0001;
for result in RESULTS { for result in RESULTS {
let MapResult { let file =
map_id, match tokio::fs::File::open(format!("./maps/{}.osu", result.map_id)).await {
mods,
stars,
pp,
} = result;
let file = match tokio::fs::File::open(format!("./maps/{}.osu", map_id)).await {
Ok(file) => file, Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why), Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
}; };
let map = match Beatmap::parse(file).await { let map = match Beatmap::parse(file).await {
Ok(map) => map, Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why), Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
}; };
let result = rosu_pp::TaikoPP::new(&map).mods(*mods).calculate(); taiko_test(map, result);
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
}); });
} }
@@ -100,31 +92,19 @@ fn taiko_async_tokio() {
#[test] #[test]
fn taiko_async_std() { fn taiko_async_std() {
async_std::task::block_on(async { async_std::task::block_on(async {
let star_margin = 0.0001;
let pp_margin = 0.0001;
for result in RESULTS { for result in RESULTS {
let MapResult { let file =
map_id, match async_std::fs::File::open(format!("./maps/{}.osu", result.map_id)).await {
mods,
stars,
pp,
} = result;
let file = match async_std::fs::File::open(format!("./maps/{}.osu", map_id)).await {
Ok(file) => file, Ok(file) => file,
Err(why) => panic!("Could not open file {}.osu: {}", map_id, why), Err(why) => panic!("Could not open file {}.osu: {}", result.map_id, why),
}; };
let map = match Beatmap::parse(file).await { let map = match Beatmap::parse(file).await {
Ok(map) => map, Ok(map) => map,
Err(why) => panic!("Error while parsing map {}: {}", map_id, why), Err(why) => panic!("Error while parsing map {}: {}", result.map_id, why),
}; };
let result = rosu_pp::TaikoPP::new(&map).mods(*mods).calculate(); taiko_test(map, result);
assert_result!("Stars" => result.stars(), star_margin, stars, map_id, mods);
assert_result!("PP" => result.pp(), pp_margin, pp, map_id, mods);
} }
}) })
} }