-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
We recently added build_text to generate a text for tests.
fm-index/src/suffix_array/sais.rs
Lines 530 to 552 in a88db3b
| /// Build a text for tests using a generator function `gen`. | |
| fn build_text<T: Zero, F: FnMut() -> T>(mut gen: F, len: usize) -> Vec<T> { | |
| let mut text = (0..(len - 1)).map(|_| gen()).collect::<Vec<_>>(); | |
| // Truncate the trailing zeros, since SA-IS does not support trailing zero suffix longer than 1. | |
| if let Some(pos) = text.iter().rposition(|x| !x.is_zero()) { | |
| text.truncate(pos + 1); | |
| } else { | |
| text.clear(); | |
| } | |
| // Add non-zero elements until the text length reaches len - 1. | |
| while text.len() < len - 1 { | |
| let c = gen(); | |
| if !c.is_zero() { | |
| text.push(c); | |
| } | |
| } | |
| // Add the last zero as a sentinel for SA-IS. | |
| text.push(T::zero()); | |
| text | |
| } |
This is specific to sais module, and in other places we adopt different strategies (use small texts or random texts) to generate test texts.
Let's unify these testing strategies.