diff --git a/.github/workflows/clippy-fmt.yml b/.github/workflows/clippy-fmt.yml new file mode 100644 index 0000000..2ad61a2 --- /dev/null +++ b/.github/workflows/clippy-fmt.yml @@ -0,0 +1,32 @@ +on: + pull_request: + types: [opened, synchronize, reopened] + +name: Clippy and rustfmt Check +jobs: + clippy_check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + components: rustfmt + override: true + - name: Check with rustfmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + components: clippy + override: true + - name: Check with Clippy + uses: actions-rs/clippy-check@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + args: --all-features --all --tests \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 61ef994..3b69804 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,4 +21,7 @@ libc = "0.2.71" thiserror = "1.0" [build-dependencies] -cc = "1.0" \ No newline at end of file +cc = "1.0" + +[dev-dependencies] +float-cmp = "0.8" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 5b679df..c05571b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -163,6 +163,11 @@ mod tests { use super::*; use chrono::Duration; + use float_cmp::approx_eq; + + fn vecs_eq(l: &[f64; 3], r: &[f64; 3]) -> bool { + approx_eq!(f64, l[0], r[0]) && approx_eq!(f64, l[1], r[1]) && approx_eq!(f64, l[2], r[2]) + } #[test] fn test_simple_propagation() -> Result<()> { @@ -175,8 +180,8 @@ mod tests { let s1 = tle.propagate_to(epoch)?; let s2 = tle.propagate_to(epoch + Duration::hours(1))?; - assert_ne!(s1.position, s2.position); - assert_ne!(s1.velocity, s2.velocity); + assert!(!vecs_eq(&s1.position, &s2.position)); + assert!(!vecs_eq(&s1.velocity, &s2.velocity)); Ok(()) } @@ -192,8 +197,8 @@ mod tests { let s1 = tle.propagate_to(epoch)?; let s2 = tle.propagate_to(epoch - Duration::days(30))?; - assert_ne!(s1.position, s2.position); - assert_ne!(s1.velocity, s2.velocity); + assert!(!vecs_eq(&s1.position, &s2.position)); + assert!(!vecs_eq(&s1.velocity, &s2.velocity)); Ok(()) }