From 2c5daf7a3faae1486f0351619797a743b78e6420 Mon Sep 17 00:00:00 2001 From: Slavik Date: Fri, 24 Jan 2025 12:50:07 +0100 Subject: [PATCH] chore: add code coverage (#10) --- .github/dependabot.yml | 6 ++++++ .github/workflows/test.yml | 14 +++++++++++-- Cargo.lock | 4 ++-- Cargo.toml | 2 +- README.md | 29 +++++++++++++++++++++++---- src/kdbush.rs | 40 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 86 insertions(+), 9 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..53f8242 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "cargo" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a8df335..fa2c447 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,11 +6,13 @@ on: paths: - '**.rs' - 'src/**.rs' + - '.github/workflows/**.yml' pull_request: branches: [ "main" ] paths: - '**.rs' - 'src/**.rs' + - '.github/workflows/**.yml' env: CI: true @@ -26,11 +28,19 @@ jobs: with: toolchain: 1.84.0 components: clippy, rustfmt + - name: Install tarpaulin + run: cargo install --locked cargo-tarpaulin - name: Run build run: cargo build --locked - name: Run clippy run: cargo clippy --all-targets --all-features --no-deps -- -D warnings - - name: Run rustfmt + - name: Run lint run: cargo fmt -- --check - name: Run tests - run: cargo test + run: cargo tarpaulin --out xml + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + file: ./cobertura.xml diff --git a/Cargo.lock b/Cargo.lock index e29b45e..1cad041 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,9 +121,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.135" +version = "1.0.137" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" +checksum = "930cfb6e6abf99298aaad7d29abbef7a9999a9a8806a40088f55f0dcec03146b" dependencies = [ "itoa", "memchr", diff --git a/Cargo.toml b/Cargo.toml index 9cd316e..584cce3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,4 +13,4 @@ repository = "https://github.com/chargetrip/supercluster-rs" [dependencies] geojson = "0.24.1" -serde_json = "1.0.135" +serde_json = "1.0.137" diff --git a/README.md b/README.md index 3187acc..a45be4c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This crate was initially inspired by Mapbox's supercluster [blog post](https://b [![crate](https://img.shields.io/crates/v/supercluster.svg)](https://crates.io/crates/supercluster) ![downloads](https://img.shields.io/crates/d/supercluster) ![GitHub](https://img.shields.io/github/license/chargetrip/supercluster-rs) +[![codecov](https://codecov.io/gh/chargetrip/supercluster-rs/graph/badge.svg?token=0S31CZY2ZJ)](https://codecov.io/gh/chargetrip/supercluster-rs) ![Features](https://cloud.githubusercontent.com/assets/25395/11857351/43407b46-a40c-11e5-8662-e99ab1cd2cb7.gif) @@ -96,30 +97,50 @@ fn main() { ## Contributing -Build: +Contributions from the community are always welcome! Here are some ways you can contribute: + +### Reporting Bugs + +If you encounter any bugs, please [submit an issue](https://github.com/chargetrip/supercluster-rs/issues) with detailed information about the problem and steps to reproduce it. + +### Feature Requests + +If you have ideas for new features, feel free to [submit an issue](https://github.com/chargetrip/supercluster-rs/issues) with a detailed description of the feature and its potential use cases. + +### Build + +To build the project, run: ```bash cargo build ``` -Test: +### Test + +To run the tests, use: ```bash cargo test ``` -Run [clippy](https://github.com/rust-lang/rust-clippy): +### Lint + +Run [clippy](https://github.com/rust-lang/rust-clippy) to lint the code: ```bash cargo clippy --all-targets --all-features --no-deps -- -D warnings ``` -Run [rustfmt](https://github.com/rust-lang/rustfmt): +### Format + +Run [rustfmt](https://github.com/rust-lang/rustfmt) to format the code: ```bash cargo fmt ``` +### Documentation + Generate documentation in HTML format: ```bash diff --git a/src/kdbush.rs b/src/kdbush.rs index 4abf1b9..c06c9b2 100644 --- a/src/kdbush.rs +++ b/src/kdbush.rs @@ -596,4 +596,44 @@ mod tests { assert_eq!(result, 5); } + + #[test] + fn test_select_basic() { + let mut kdbush = KDBush::new(10, 1); + kdbush.coords = vec![2.0, 3.0, 1.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]; + kdbush.ids = vec![0, 1, 2, 3, 4]; + kdbush.select(2, 0, 4, 0); + + assert_eq!(kdbush.coords[4], 5.0); + } + + #[test] + fn test_select_large_range() { + let mut kdbush = KDBush::new(10, 1); + kdbush.coords = (0..4000).map(|x| x as f64).collect(); + kdbush.ids = (0..4000).collect(); + kdbush.select(1000, 0, 1999, 0); + + assert_eq!(kdbush.coords[2000], 2000.0); + } + + #[test] + fn test_select_axis_y() { + let mut kdbush = KDBush::new(10, 1); + kdbush.coords = vec![2.0, 3.0, 1.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]; + kdbush.ids = vec![0, 1, 2, 3, 4]; + kdbush.select(2, 0, 4, 1); + + assert_eq!(kdbush.coords[4], 5.0); + } + + #[test] + fn test_select_single_element() { + let mut kdbush = KDBush::new(10, 1); + kdbush.coords = vec![2.0]; + kdbush.ids = vec![0]; + kdbush.select(0, 0, 0, 0); + + assert_eq!(kdbush.coords[0], 2.0); + } }