Skip to content

Commit

Permalink
fix: update imports and namespaces in doc-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sanity committed Sep 21, 2024
1 parent 86c11ee commit 4f67bad
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 64 deletions.
14 changes: 7 additions & 7 deletions src/coordinate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait Coordinate:
/// # Examples
///
/// ```
/// use crate::coordinate::Coordinate;
/// use pav_regression::Coordinate;
///
/// let zero = f64::zero();
/// assert_eq!(zero, 0.0);
Expand All @@ -23,7 +23,7 @@ pub trait Coordinate:
/// # Examples
///
/// ```
/// use crate::coordinate::Coordinate;
/// use pav_regression::Coordinate;
///
/// let one = f64::one();
/// assert_eq!(one, 1.0);
Expand All @@ -35,7 +35,7 @@ pub trait Coordinate:
/// # Examples
///
/// ```
/// use crate::coordinate::Coordinate;
/// use pav_regression::Coordinate;
///
/// let value: f64 = 3.14;
/// assert_eq!(value.to_float(), 3.14);
Expand All @@ -47,7 +47,7 @@ pub trait Coordinate:
/// # Examples
///
/// ```
/// use crate::coordinate::Coordinate;
/// use pav_regression::Coordinate;
///
/// let value = f64::from_float(3.14);
/// assert_eq!(value, 3.14);
Expand All @@ -59,7 +59,7 @@ pub trait Coordinate:
/// # Examples
///
/// ```
/// use crate::coordinate::Coordinate;
/// use pav_regression::Coordinate;
///
/// let a: f64 = 2.5;
/// let b: f64 = -1.5;
Expand All @@ -72,7 +72,7 @@ pub trait Coordinate:
/// # Examples
///
/// ```
/// use crate::coordinate::Coordinate;
/// use pav_regression::Coordinate;
///
/// let a: f64 = -1.0;
/// assert!(a.is_sign_negative());
Expand All @@ -87,7 +87,7 @@ pub trait Coordinate:
/// # Examples
///
/// ```
/// use crate::coordinate::Coordinate;
/// use pav_regression::Coordinate;
///
/// let a: f64 = 2.0;
/// let b: f64 = 4.0;
Expand Down
112 changes: 64 additions & 48 deletions src/isotonic_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// use pav_regression::{Point, IsotonicRegression};
///
/// let points = vec![
/// super::point::Point::new(0.0, 1.0),
/// super::point::Point::new(1.0, 2.0),
/// super::point::Point::new(2.0, 1.5),
/// super::point::Point::new(3.0, 3.0),
/// Point::new(0.0, 1.0),
/// Point::new(1.0, 2.0),
/// Point::new(2.0, 1.5),
/// Point::new(3.0, 3.0),
/// ];
/// let regression = super::isotonic_regression::IsotonicRegression::new_ascending(&points).unwrap();
/// let regression = IsotonicRegression::new_ascending(&points).unwrap();
/// assert_eq!(regression.get_points().len(), 3);
/// ```
pub fn new_ascending(points: &[Point<T>]) -> Result<IsotonicRegression<T>, IsotonicRegressionError> {
Expand All @@ -82,13 +83,15 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// use pav_regression::{Point, IsotonicRegression};
///
/// let points = vec![
/// super::point::Point::new(0.0, 3.0),
/// super::point::Point::new(1.0, 2.0),
/// super::point::Point::new(2.0, 2.5),
/// super::point::Point::new(3.0, 1.0),
/// Point::new(0.0, 3.0),
/// Point::new(1.0, 2.0),
/// Point::new(2.0, 2.5),
/// Point::new(3.0, 1.0),
/// ];
/// let regression = super::isotonic_regression::IsotonicRegression::new_descending(&points).unwrap();
/// let regression = IsotonicRegression::new_descending(&points).unwrap();
/// assert_eq!(regression.get_points().len(), 3);
/// ```
pub fn new_descending(points: &[Point<T>]) -> Result<IsotonicRegression<T>, IsotonicRegressionError> {
Expand All @@ -102,13 +105,15 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// use pav_regression::{Point, IsotonicRegression, Direction};
///
/// let points = vec![
/// super::point::Point::new(0.0, 1.0),
/// super::point::Point::new(1.0, 2.0),
/// super::point::Point::new(2.0, 1.5),
/// super::point::Point::new(3.0, 3.0),
/// Point::new(0.0, 1.0),
/// Point::new(1.0, 2.0),
/// Point::new(2.0, 1.5),
/// Point::new(3.0, 3.0),
/// ];
/// let regression = super::isotonic_regression::IsotonicRegression::new(&points, super::isotonic_regression::Direction::Ascending, false).unwrap();
/// let regression = IsotonicRegression::new(&points, Direction::Ascending, false).unwrap();
/// assert_eq!(regression.get_points().len(), 3);
/// ```
fn new(points: &[Point<T>], direction: Direction, intersect_origin: bool) -> Result<IsotonicRegression<T>, IsotonicRegressionError> {
Expand Down Expand Up @@ -139,13 +144,15 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// use pav_regression::{Point, IsotonicRegression};
///
/// let points = vec![
/// super::point::Point::new(0.0, 1.0),
/// super::point::Point::new(1.0, 2.0),
/// super::point::Point::new(2.0, 1.5),
/// super::point::Point::new(3.0, 3.0),
/// Point::new(0.0, 1.0),
/// Point::new(1.0, 2.0),
/// Point::new(2.0, 1.5),
/// Point::new(3.0, 3.0),
/// ];
/// let regression = super::isotonic_regression::IsotonicRegression::new_ascending(&points).unwrap();
/// let regression = IsotonicRegression::new_ascending(&points).unwrap();
/// let interpolated_y = regression.interpolate(1.5).unwrap();
/// assert_eq!(interpolated_y, 1.75);
/// ```
Expand Down Expand Up @@ -199,13 +206,15 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// use pav_regression::{Point, IsotonicRegression};
///
/// let points = vec![
/// super::point::Point::new(0.0, 1.0),
/// super::point::Point::new(1.0, 2.0),
/// super::point::Point::new(2.0, 1.5),
/// super::point::Point::new(3.0, 3.0),
/// Point::new(0.0, 1.0),
/// Point::new(1.0, 2.0),
/// Point::new(2.0, 1.5),
/// Point::new(3.0, 3.0),
/// ];
/// let regression = super::isotonic_regression::IsotonicRegression::new_ascending(&points).unwrap();
/// let regression = IsotonicRegression::new_ascending(&points).unwrap();
/// assert_eq!(regression.get_points().len(), 3);
/// ```
pub fn get_points(&self) -> &[Point<T>] {
Expand All @@ -217,15 +226,17 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// use pav_regression::{Point, IsotonicRegression};
///
/// let points = vec![
/// super::point::Point::new(0.0, 1.0),
/// super::point::Point::new(1.0, 2.0),
/// super::point::Point::new(2.0, 1.5),
/// super::point::Point::new(3.0, 3.0),
/// Point::new(0.0, 1.0),
/// Point::new(1.0, 2.0),
/// Point::new(2.0, 1.5),
/// Point::new(3.0, 3.0),
/// ];
/// let regression = super::isotonic_regression::IsotonicRegression::new_ascending(&points).unwrap();
/// let regression = IsotonicRegression::new_ascending(&points).unwrap();
/// let centroid = regression.get_centroid_point().unwrap();
/// assert_eq!(*centroid.x(), 1.0);
/// assert_eq!(*centroid.x(), 1.5);
/// assert_eq!(*centroid.y(), 1.875);
/// ```
pub fn get_centroid_point(&self) -> Option<Point<T>> {
Expand All @@ -245,11 +256,13 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// let mut regression = super::isotonic_regression::IsotonicRegression::new_ascending(&[
/// super::point::Point::new(0.0, 1.0),
/// super::point::Point::new(2.0, 2.0),
/// use pav_regression::{Point, IsotonicRegression};
///
/// let mut regression = IsotonicRegression::new_ascending(&[
/// Point::new(0.0, 1.0),
/// Point::new(2.0, 2.0),
/// ]).unwrap();
/// regression.add_points(&[super::Point::new(1.0, 1.5)]);
/// regression.add_points(&[Point::new(1.0, 1.5)]);
/// assert_eq!(regression.get_points().len(), 3);
/// ```
pub fn add_points(&mut self, points: &[Point<T>]) {
Expand All @@ -272,12 +285,14 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// let mut regression = super::isotonic_regression::IsotonicRegression::new_ascending(&[
/// super::point::Point::new(0.0, 1.0),
/// super::point::Point::new(1.0, 2.0),
/// super::point::Point::new(2.0, 3.0),
/// use pav_regression::{Point, IsotonicRegression};
///
/// let mut regression = IsotonicRegression::new_ascending(&[
/// Point::new(0.0, 1.0),
/// Point::new(1.0, 2.0),
/// Point::new(2.0, 3.0),
/// ]).unwrap();
/// regression.remove_points(&[super::Point::new(1.0, 2.0)]);
/// regression.remove_points(&[Point::new(1.0, 2.0)]);
/// assert_eq!(regression.get_points().len(), 2);
/// ```
pub fn remove_points(&mut self, points: &[Point<T>]) {
Expand All @@ -303,16 +318,15 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// use super::point::Point;
/// use super::isotonic_regression::IsotonicRegression;
/// use pav_regression::{Point, IsotonicRegression};
///
/// let points = vec![
/// super::Point::new(0.0, 1.0),
/// super::Point::new(1.0, 2.0),
/// super::Point::new(2.0, 1.5),
/// super::Point::new(3.0, 3.0),
/// Point::new(0.0, 1.0),
/// Point::new(1.0, 2.0),
/// Point::new(2.0, 1.5),
/// Point::new(3.0, 3.0),
/// ];
/// let regression = super::IsotonicRegression::new_ascending(&points).unwrap();
/// let regression = IsotonicRegression::new_ascending(&points).unwrap();
/// assert_eq!(regression.len(), 4);
/// ```
pub fn len(&self) -> usize {
Expand All @@ -324,7 +338,9 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// # Examples
///
/// ```
/// let regression: super::isotonic_regression::IsotonicRegression<f64> = super::isotonic_regression::IsotonicRegression::new_ascending(&[]).unwrap();
/// use pav_regression::IsotonicRegression;
///
/// let regression: IsotonicRegression<f64> = IsotonicRegression::new_ascending(&[]).unwrap();
/// assert!(regression.is_empty());
/// ```
#[must_use]
Expand Down
16 changes: 7 additions & 9 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<T: Coordinate> Point<T> {
/// # Examples
///
/// ```
/// let point = crate::point::Point::new(1.0, 2.0);
/// use pav_regression::Point;
///
/// let point = Point::new(1.0, 2.0);
/// assert_eq!(*point.x(), 1.0);
Expand All @@ -41,7 +41,7 @@ impl<T: Coordinate> Point<T> {
/// # Examples
///
/// ```
/// let point = crate::point::Point::new_with_weight(1.0, 2.0, 0.5);
/// use pav_regression::Point;
///
/// let point = Point::new_with_weight(1.0, 2.0, 0.5);
/// assert_eq!(*point.x(), 1.0);
Expand All @@ -57,7 +57,7 @@ impl<T: Coordinate> Point<T> {
/// # Examples
///
/// ```
/// let point = crate::point::Point::new(1.0, 2.0);
/// use pav_regression::Point;
///
/// let point = Point::new(1.0, 2.0);
/// assert_eq!(*point.x(), 1.0);
Expand All @@ -71,7 +71,7 @@ impl<T: Coordinate> Point<T> {
/// # Examples
///
/// ```
/// let point = crate::point::Point::new(1.0, 2.0);
/// use pav_regression::Point;
///
/// let point = Point::new(1.0, 2.0);
/// assert_eq!(*point.y(), 2.0);
Expand All @@ -85,7 +85,7 @@ impl<T: Coordinate> Point<T> {
/// # Examples
///
/// ```
/// let point = crate::point::Point::new(1.0, 2.0);
/// use pav_regression::Point;
///
/// let point = Point::new(1.0, 2.0);
/// assert_eq!(point.weight(), 1.0);
Expand All @@ -99,8 +99,7 @@ impl<T: Coordinate> Point<T> {
/// # Examples
///
/// ```
/// let mut point1 = crate::point::Point::new_with_weight(1.0, 2.0, 0.5);
/// let point2 = crate::point::Point::new_with_weight(3.0, 4.0, 1.5);
/// use pav_regression::Point;
///
/// let mut point1 = Point::new_with_weight(1.0, 2.0, 0.5);
/// let point2 = Point::new_with_weight(3.0, 4.0, 1.5);
Expand Down Expand Up @@ -129,8 +128,7 @@ impl<T: Coordinate> From<(T, T)> for Point<T> {
/// # Examples
///
/// ```
/// let point1 = crate::point::Point::new(0.0, 0.0);
/// let point2 = crate::point::Point::new(2.0, 2.0);
/// use pav_regression::{Point, interpolate_two_points};
///
/// let point1 = Point::new(0.0, 0.0);
/// let point2 = Point::new(2.0, 2.0);
Expand Down

0 comments on commit 4f67bad

Please sign in to comment.