-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add basic setup for direct testing of rust code using cargo test
#6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use rstest::rstest; | ||
use triangulation::point::{Point, Segment, Vector}; | ||
|
||
#[rstest] | ||
fn test_segment_order() { | ||
let s1 = Segment::new(Point::new(0.0, 0.0), Point::new(1.0, 1.0)); | ||
let s2 = Segment::new(Point::new(1.0, 1.0), Point::new(0.0, 0.0)); | ||
assert_eq!(s1, s2); | ||
} | ||
|
||
#[rstest] | ||
#[case::base(1.0, 0.0, 1.0, 1.0, 2.0, 1.0)] | ||
#[case::zero_vector(0.0, 0.0, 1.0, 1.0, 1.0, 1.0)] // zero vector | ||
#[case::negative_vector(1.0, 1.0, -1.0, -1.0, 0.0, 0.0)] // negative vector | ||
#[case::larger_components(10.0, 20.0, 30.0, 40.0, 40.0, 60.0)] // larger components | ||
fn test_vector_add( | ||
#[case] x1: f32, | ||
#[case] y1: f32, | ||
#[case] x2: f32, | ||
#[case] y2: f32, | ||
#[case] expected_x: f32, | ||
#[case] expected_y: f32, | ||
) { | ||
assert_eq!( | ||
Point::new(x1, y1) + Vector::new(x2, y2), | ||
Point::new(expected_x, expected_y) | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -283,6 +283,27 @@ impl Triangle { | |
} | ||
} | ||
|
||
/// Calculates the Euclidean distance between two points. | ||
/// | ||
/// # Arguments | ||
/// * `p1` - The first point. | ||
/// * `p2` - The second point. | ||
/// | ||
/// # Returns | ||
/// Returns the distance between `p1` and `p2` as a `Coord`. | ||
/// | ||
/// # Examples | ||
/// ``` | ||
/// use triangulation::point::{Point, vector_length}; | ||
/// | ||
/// let point1 = Point { x: 3.0, y: 0.0 }; | ||
/// let point2 = Point { x: 0.0, y: 4.0 }; | ||
/// | ||
/// let distance = vector_length(point1, point2); | ||
/// assert_eq!(distance, 5.0); | ||
/// ``` | ||
pub fn vector_length(p1: Point, p2: Point) -> Coord { | ||
((p1.x - p2.x).powi(2) + (p1.y - p2.y).powi(2)).sqrt() | ||
let dx = p1.x - p2.x; | ||
let dy = p1.y - p2.y; | ||
(dx * dx + dy * dy).sqrt() | ||
Comment on lines
+286
to
+308
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Additional test coverage needed for vector_length function The function currently only has a single doctest example. Given its usage in path triangulation calculations, comprehensive testing is essential. Add a dedicated test module with cases for:
🔗 Analysis chainEnhance test coverage. While the documentation includes a basic test, consider adding tests for:
Let's check the existing test coverage: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for existing tests of the new function
rg -l "vector_length|distance.*test" crates/
Length of output: 127 Script: #!/bin/bash
# Check content of both files focusing on tests
echo "=== point.rs ==="
rg -B 2 -A 10 "vector_length|#\[test\]" crates/triangulation/src/point.rs
echo -e "\n=== path_triangulation.rs ==="
rg -B 2 -A 10 "vector_length|#\[test\]" crates/triangulation/src/path_triangulation.rs
Length of output: 1643 |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add explicit Rust toolchain setup.
While the cargo test configuration looks good, it's missing explicit Rust toolchain setup. This could lead to inconsistent builds across different environments.
Add the rust-toolchain setup step:
📝 Committable suggestion
🧰 Tools
🪛 actionlint (1.7.4)
59-59: the runner of "actions/cache@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)