Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoff97 committed Oct 9, 2024
1 parent c770e4b commit 2efb0f5
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 7 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Github action that runs rust clippy, unit tests, tries to compile the code and if successful, builds a docker image and pushes it to dockerhub. After that, it deploys the image to a remote server using SSH.

name: develop

on:
Expand Down
89 changes: 87 additions & 2 deletions backend-rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde = { version = "1.0.210", features = ["derive", "serde_derive"] }

[dev-dependencies]
approx = "0.5.1"
proptest = "1.5.0"
criterion = { version = "0.5", features = ["html_reports"] }

[[bench]]
Expand Down
4 changes: 2 additions & 2 deletions backend-rust/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ impl SearchState {
}
}

struct EffectiveGlide {
pub struct EffectiveGlide {
#[allow(dead_code)]
speed: f32,
glide_ratio: f32,
}

fn get_effective_glide_ratio(
pub fn get_effective_glide_ratio(
effective_wind_angle: f32,
wind_speed: f32,
trim_speed: f32,
Expand Down
40 changes: 39 additions & 1 deletion backend-rust/src/search_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
use super::{search_from_point, SearchQuery};
use core::f32;

use super::{get_effective_glide_ratio, search_from_point, SearchQuery};

use approx::assert_relative_eq;
use proptest::{prop_assert_eq, prop_compose, proptest};

prop_compose! {
fn speed_wind_speed(max_speed: f32)
(speed in 10.0..max_speed, wind_speed in -max_speed..max_speed) -> (f32, f32) {
(speed, wind_speed.min(speed - 0.1))
}
}

proptest! {
#[test]
fn get_effective_glide_ratio_no_wind(glide_ratio in 0.05..0.5f32, speed in 10.0..50.0f32) {
let result = get_effective_glide_ratio(0.0, 0.0, speed, glide_ratio);

prop_assert_eq!(result.speed, speed);
prop_assert_eq!(result.glide_ratio, glide_ratio);
}

#[test]
fn get_effective_glide_ratio_wind(glide_ratio in 0.05..0.5f32, (speed, wind_speed) in speed_wind_speed(50.0)) {
let result = get_effective_glide_ratio(f32::consts::PI, wind_speed, speed, glide_ratio);

prop_assert_eq!(result.speed, speed - wind_speed);
prop_assert_eq!(result.glide_ratio, glide_ratio/((speed - wind_speed)/speed));
}

#[test]
fn get_effective_glide_ratio_side_wind(glide_ratio in 0.05..0.5f32, speed in 10.0..50.0f32) {
let result = get_effective_glide_ratio(f32::consts::PI/2.0, speed/2.0f32.sqrt(), speed, glide_ratio);

assert_relative_eq!(result.speed, speed/2.0f32.sqrt(), max_relative = 0.01);
assert_relative_eq!(result.glide_ratio, glide_ratio*2.0f32.sqrt(), max_relative = 0.01);
}
}

#[test]
fn test_search() {
Expand Down

0 comments on commit 2efb0f5

Please sign in to comment.