summaryrefslogtreecommitdiffstats
path: root/src/query/scorer.rs
diff options
context:
space:
mode:
authorPaul Masurel <paul.masurel@gmail.com>2018-02-21 00:13:04 +0900
committerPaul Masurel <paul.masurel@gmail.com>2018-02-21 00:13:04 +0900
commit6fb114224a99c485dc46be001434a607f08bfd04 (patch)
tree68bda4d561322edc702eeba9f6c1afa9830dbfe8 /src/query/scorer.rs
parent2c3e33895af57cae38911eff0746a24a0772aecc (diff)
Added unit test
Diffstat (limited to 'src/query/scorer.rs')
-rw-r--r--src/query/scorer.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/query/scorer.rs b/src/query/scorer.rs
index 2143b44..e1bba45 100644
--- a/src/query/scorer.rs
+++ b/src/query/scorer.rs
@@ -51,7 +51,8 @@ impl DocSet for EmptyScorer {
}
fn doc(&self) -> DocId {
- DocId::max_value()
+ panic!("You may not call .doc() on a scorer \
+ where the last call to advance() did not return true.");
}
fn size_hint(&self) -> u32 {
@@ -122,3 +123,21 @@ impl<TDocSet: DocSet + 'static> Scorer for ConstScorer<TDocSet> {
1f32
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::EmptyScorer;
+ use DocSet;
+
+ #[test]
+ fn test_empty_scorer() {
+ let mut empty_scorer = EmptyScorer;
+ assert!(!empty_scorer.advance());
+ }
+
+ #[test]
+ #[should_panic]
+ fn test_empty_scorer_panic_on_doc_call() {
+ EmptyScorer.doc();
+ }
+}