Skip to content

Commit

Permalink
Test lexicons in integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elshize committed Mar 4, 2022
1 parent 2952989 commit 5ec21bd
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions tests/toy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ciff::{ciff_to_pisa, pisa_to_ciff};
use ciff::{ciff_to_pisa, pisa_to_ciff, PayloadSlice};
use std::fs::read;
use std::path::PathBuf;
use tempfile::TempDir;
Expand All @@ -9,13 +9,19 @@ fn test_toy_index() -> anyhow::Result<()> {
let input_path = PathBuf::from("tests/test_data/toy-complete-20200309.ciff");
let temp = TempDir::new().unwrap();
let output_path = temp.path().join("coll");
if let Err(err) = ciff_to_pisa(&input_path, &output_path, false) {
if let Err(err) = ciff_to_pisa(&input_path, &output_path, true) {
panic!("{}", err);
}
assert_eq!(
std::fs::read_to_string(temp.path().join("coll.documents"))?,
"WSJ_1\nTREC_DOC_1\nDOC222\n"
);
let bytes = std::fs::read(temp.path().join("coll.doclex"))?;
let actual_titles: Vec<_> = PayloadSlice::new(&bytes).iter().collect();
assert_eq!(
actual_titles,
vec![b"WSJ_1".as_ref(), b"TREC_DOC_1", b"DOC222"],
);
assert_eq!(
std::fs::read(temp.path().join("coll.sizes"))?,
vec![3, 0, 0, 0, 6, 0, 0, 0, 4, 0, 0, 0, 6, 0, 0, 0]
Expand All @@ -26,6 +32,22 @@ fn test_toy_index() -> anyhow::Result<()> {
.collect::<Vec<_>>(),
vec!["01", "03", "30", "content", "enough", "head", "simpl", "text", "veri"]
);
let bytes = std::fs::read(temp.path().join("coll.termlex"))?;
let actual_terms: Vec<_> = PayloadSlice::new(&bytes).iter().collect();
assert_eq!(
actual_terms,
vec![
b"01".as_ref(),
b"03",
b"30",
b"content",
b"enough",
b"head",
b"simpl",
b"text",
b"veri"
]
);
assert_eq!(
std::fs::read(temp.path().join("coll.docs"))?,
vec![
Expand Down

0 comments on commit 5ec21bd

Please sign in to comment.