Skip to content

Commit f9cd6a4

Browse files
committed
add test case
1 parent f110d06 commit f9cd6a4

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

examples/boxplot.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4242
.map(|(k, v)| (k.0.clone(), k.1.clone(), Quartiles::new(&v)))
4343
.collect();
4444

45-
let host_list:Vec<_> = dataset
45+
let host_list: Vec<_> = dataset
4646
.iter()
4747
.unique_by(|x| x.0.clone())
4848
.sorted_by(|a, b| b.2.median().partial_cmp(&a.2.median()).unwrap())
@@ -72,7 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7272
.caption("Ping Boxplot", ("sans-serif", 20).into_font())
7373
.build_ranged(
7474
values_range.start - 1.0..values_range.end + 1.0,
75-
host_list[..].into_centric()
75+
host_list[..].into_centric(),
7676
)?;
7777

7878
chart
@@ -110,9 +110,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
110110
6.0, 7.0, 15.9, 36.9, 39.0, 40.0, 41.0, 42.0, 43.0, 47.0, 49.0,
111111
]);
112112
let quartiles_b = Quartiles::new(&[16.0, 17.0, 50.0, 60.0, 40.2, 41.3, 42.7, 43.3, 47.0]);
113-
113+
114114
let ab_axis = ["a", "b"];
115-
115+
116116
let values_range = fitting_range(
117117
quartiles_a
118118
.values()
@@ -124,7 +124,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
124124
.y_label_area_size(40)
125125
.caption("Vertical Boxplot", ("sans-serif", 20).into_font())
126126
.build_ranged(
127-
(&ab_axis[..]).into_centric(),
127+
ab_axis[..].into_centric(),
128128
values_range.start - 10.0..values_range.end + 10.0,
129129
)?;
130130

src/coord/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub use ranged::{AsRangedCoord, MeshLine, Ranged, RangedCoord, ReversibleRanged}
4444

4545
pub use partial_axis::{make_partial_axis, IntoPartialAxis};
4646

47-
pub use discrete::{DiscreteRanged, IntoCentric, CentricValues};
47+
pub use discrete::{CentricValues, DiscreteRanged, IntoCentric};
4848

4949
pub use logarithmic::{LogCoord, LogRange, LogScalable};
5050

src/coord/slice.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,30 @@ impl<'a, T: PartialEq> AsRangedCoord for &'a [T] {
6262
type CoordDescType = RangedSlice<'a, T>;
6363
type Value = &'a T;
6464
}
65+
66+
#[cfg(test)]
67+
mod test {
68+
use super::*;
69+
#[test]
70+
fn test_slice_range() {
71+
let my_slice = [1, 2, 3, 0, -1, -2];
72+
let slice_range: RangedSlice<i32> = my_slice[..].into();
73+
74+
assert_eq!(slice_range.range(), &1..&-2);
75+
assert_eq!(
76+
slice_range.key_points(6),
77+
my_slice.iter().collect::<Vec<_>>()
78+
);
79+
assert_eq!(slice_range.map(&&0, (0, 50)), 30);
80+
}
81+
82+
#[test]
83+
fn test_slice_range_discrete() {
84+
let my_slice = [1, 2, 3, 0, -1, -2];
85+
let slice_range: RangedSlice<i32> = my_slice[..].into();
86+
87+
assert_eq!(slice_range.size(), 6);
88+
assert_eq!(slice_range.index_of(&&3), Some(2));
89+
assert_eq!(slice_range.from_index(2), Some(&3));
90+
}
91+
}

src/element/errorbar.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ impl<K, V> ErrorBar<K, V, ErrorBarOrientH<K, V>> {
9494
}
9595
}
9696

97-
impl<'a, K: Clone, V: Clone, O: ErrorBarOrient<K, V>>
98-
PointCollection<'a, (O::XType, O::YType)> for &'a ErrorBar<K, V, O>
97+
impl<'a, K: Clone, V: Clone, O: ErrorBarOrient<K, V>> PointCollection<'a, (O::XType, O::YType)>
98+
for &'a ErrorBar<K, V, O>
9999
{
100100
type Borrow = (O::XType, O::YType);
101101
type IntoIter = Vec<Self::Borrow>;

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -708,9 +708,9 @@ pub mod prelude {
708708

709709
// Coordinates
710710
pub use crate::coord::{
711-
CoordTranslate, GroupBy, IntoCentric, IntoPartialAxis, LogCoord, LogRange,
711+
CentricValues, CoordTranslate, GroupBy, IntoCentric, IntoPartialAxis, LogCoord, LogRange,
712712
LogScalable, Ranged, RangedCoord, RangedCoordf32, RangedCoordf64, RangedCoordi32,
713-
RangedCoordi64, RangedCoordu32, RangedCoordu64, ToGroupByRange, CentricValues,
713+
RangedCoordi64, RangedCoordu32, RangedCoordu64, ToGroupByRange,
714714
};
715715

716716
#[cfg(feature = "chrono")]

0 commit comments

Comments
 (0)