Skip to content

Commit 596c216

Browse files
committed
Add test case
1 parent 82e7b8e commit 596c216

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

src/coord/ckps.rs

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::ops::Range;
66
use super::{AsRangedCoord, DiscreteRanged, KeyPointHint, Ranged};
77

88
/// The coordinate decorator that binds a key point vector.
9-
/// Normally, all the ranged coordinate implements its own keypoint algorithm
10-
/// to determine how to render the tick mark and mesh grid.
11-
/// This decorator allows customized tick mark specifiied by vector.
12-
/// See [BindKeyPoints::with_key_points](trait.BindKeyPoints.html#tymethod.with_key_points)
9+
/// Normally, all the ranged coordinate implements its own keypoint algorithm
10+
/// to determine how to render the tick mark and mesh grid.
11+
/// This decorator allows customized tick mark specifiied by vector.
12+
/// See [BindKeyPoints::with_key_points](trait.BindKeyPoints.html#tymethod.with_key_points)
1313
/// for details.
1414
/// Note: For any coordinate spec wrapped by this decorator, the maxium number of labels configured by
1515
/// MeshStyle will be ignored and the key point function will always returns the entire vector
@@ -210,3 +210,57 @@ impl<R: DiscreteRanged> DiscreteRanged for WithKeyPointMethod<R> {
210210
self.inner.from_index(index)
211211
}
212212
}
213+
214+
#[cfg(test)]
215+
mod test {
216+
use super::*;
217+
use crate::coord::{BoldPoints, LightPoints};
218+
#[test]
219+
fn test_with_key_points() {
220+
let range = (0..100).with_key_points(vec![1, 2, 3]);
221+
assert_eq!(range.map(&3, (0, 1000)), 30);
222+
assert_eq!(range.range(), 0..100);
223+
assert_eq!(range.key_points(BoldPoints(100)), vec![1, 2, 3]);
224+
assert_eq!(range.key_points(LightPoints::new(100, 100)), vec![]);
225+
let range = range.with_light_points(5..10);
226+
assert_eq!(range.key_points(BoldPoints(10)), vec![1, 2, 3]);
227+
assert_eq!(
228+
range.key_points(LightPoints::new(10, 10)),
229+
(5..10).collect::<Vec<_>>()
230+
);
231+
232+
assert_eq!(range.size(), 101);
233+
assert_eq!(range.index_of(&10), Some(10));
234+
assert_eq!(range.from_index(10), Some(10));
235+
236+
assert_eq!(range.axis_pixel_range((0, 1000)), 0..1000);
237+
238+
let mut range = range;
239+
240+
assert_eq!(range.light_points().len(), 5);
241+
assert_eq!(range.light_points_mut().len(), 5);
242+
assert_eq!(range.bold_points().len(), 3);
243+
assert_eq!(range.bold_points_mut().len(), 3);
244+
}
245+
246+
#[test]
247+
fn test_with_key_point_method() {
248+
let range = (0..100).with_key_point_func(|_| vec![1, 2, 3]);
249+
assert_eq!(range.map(&3, (0, 1000)), 30);
250+
assert_eq!(range.range(), 0..100);
251+
assert_eq!(range.key_points(BoldPoints(100)), vec![1, 2, 3]);
252+
assert_eq!(range.key_points(LightPoints::new(100, 100)), vec![]);
253+
let range = range.with_light_point_func(|_| (5..10).collect());
254+
assert_eq!(range.key_points(BoldPoints(10)), vec![1, 2, 3]);
255+
assert_eq!(
256+
range.key_points(LightPoints::new(10, 10)),
257+
(5..10).collect::<Vec<_>>()
258+
);
259+
260+
assert_eq!(range.size(), 101);
261+
assert_eq!(range.index_of(&10), Some(10));
262+
assert_eq!(range.from_index(10), Some(10));
263+
264+
assert_eq!(range.axis_pixel_range((0, 1000)), 0..1000);
265+
}
266+
}

0 commit comments

Comments
 (0)