Skip to content

Commit

Permalink
chore: add code coverage (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
slavik-pastushenko authored Jan 24, 2025
1 parent 258fdb6 commit 2c5daf7
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "weekly"
14 changes: 12 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions src/kdbush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 2c5daf7

Please sign in to comment.