use super::*;
use crate::NormCoord;
fn page() -> DocumentSegment<NormCoord> {
DocumentSegment::new(
Quad::try_unit((0.10, 0.12), (0.90, 0.10), (0.92, 0.88), (0.08, 0.90))
.expect("the fixture's corners are in frame"),
Score::new(0.97).expect("the fixture's confidence is in range"),
)
}
#[test]
fn a_segment_carries_no_index_leaf_at_all() {
type Page = DocumentSegment<NormCoord>;
assert_eq!(crate::width(<Page as ColumnKind>::SEGMENTS), 9);
assert_eq!(
crate::value_width(<Page as ColumnKind>::SEGMENTS),
9,
"a quad derives nothing, so a segment holding one derives nothing either"
);
assert!(
<Page as ColumnKind>::ORDER.is_empty(),
"…which is why it keeps the non-reordering word and states no sequence"
);
let names: Vec<_> = <Page as ColumnKind>::SEGMENTS
.iter()
.map(|segment| segment.field().expect("named").declared().as_str())
.collect();
assert_eq!(names, ["quad", "confidence"]);
}
#[test]
fn the_corners_keep_their_winding_order_beneath_the_segment() {
let found = page();
assert_eq!(
found.quad().corners(),
[
crate::Point2::try_unit(0.10, 0.12).expect("in frame"),
crate::Point2::try_unit(0.90, 0.10).expect("in frame"),
crate::Point2::try_unit(0.92, 0.88).expect("in frame"),
crate::Point2::try_unit(0.08, 0.90).expect("in frame"),
],
"the third corner is diagonally opposite the first, not below it"
);
}
#[test]
fn a_segment_round_trips_through_a_cursor_and_refuses_a_forged_one() {
use crate::CursorValue as _;
let found = page();
let mut bytes = Vec::new();
found.write_cursor(&mut bytes);
assert_eq!(
<DocumentSegment<NormCoord> as crate::CursorValue>::read_cursor(&bytes),
Some(found)
);
assert_eq!(
<DocumentSegment<NormCoord> as crate::CursorValue>::read_cursor(&bytes[..bytes.len() - 1]),
None
);
}
#[test]
fn a_filter_is_empty_until_a_component_under_some_corner_is_set() {
type Face = DocumentSegmentFilter<crate::ScalarFilter<NormCoord>>;
assert!(crate::GraphqlFilter::is_empty(&Face::new()));
assert!(crate::GraphqlFilter::is_empty(
&Face::new().with_quad(QuadFilter::new())
));
assert!(!crate::GraphqlFilter::is_empty(
&Face::new().with_quad(
QuadFilter::new().with_top_left(
crate::Point2Filter::new()
.with_x(crate::ScalarFilter::new().with_gte(NormCoord::new(0.5).expect("in range")))
)
)
));
}