ok/jj
1
0
Fork 0
forked from mirrors/jj

repo: move test_id_index() into a tests module

This is the usual convention (to save on compilation time when not
running tests).
This commit is contained in:
Martin von Zweigbergk 2023-01-18 15:56:06 -08:00 committed by Martin von Zweigbergk
parent d3789cb28d
commit 0f8622dd5c

View file

@ -1237,26 +1237,31 @@ impl IdIndex {
} }
} }
#[test] #[cfg(test)]
fn test_id_index() { mod tests {
let mut id_index = IdIndex::new(); use super::*;
id_index.insert(b"ab", ());
id_index.insert(b"acd", ());
assert_eq!(id_index.shortest_unique_prefix_len(b"acd"), 2);
assert_eq!(id_index.shortest_unique_prefix_len(b"ac"), 3);
let mut id_index = IdIndex::new(); #[test]
id_index.insert(b"ab", ()); fn test_id_index() {
id_index.insert(b"acd", ()); let mut id_index = IdIndex::new();
id_index.insert(b"acf", ()); id_index.insert(b"ab", ());
id_index.insert(b"a", ()); id_index.insert(b"acd", ());
id_index.insert(b"ba", ()); assert_eq!(id_index.shortest_unique_prefix_len(b"acd"), 2);
assert_eq!(id_index.shortest_unique_prefix_len(b"ac"), 3);
assert_eq!(id_index.shortest_unique_prefix_len(b"a"), 2); // Unlikely for hashes case: the entire length of the key is an insufficient let mut id_index = IdIndex::new();
// prefix id_index.insert(b"ab", ());
assert_eq!(id_index.shortest_unique_prefix_len(b"ba"), 1); id_index.insert(b"acd", ());
assert_eq!(id_index.shortest_unique_prefix_len(b"ab"), 2); id_index.insert(b"acf", ());
assert_eq!(id_index.shortest_unique_prefix_len(b"acd"), 3); id_index.insert(b"a", ());
// If it were there, the length would be 1. id_index.insert(b"ba", ());
assert_eq!(id_index.shortest_unique_prefix_len(b"c"), 1);
assert_eq!(id_index.shortest_unique_prefix_len(b"a"), 2); // Unlikely for hashes case: the entire length of the key is an insufficient
// prefix
assert_eq!(id_index.shortest_unique_prefix_len(b"ba"), 1);
assert_eq!(id_index.shortest_unique_prefix_len(b"ab"), 2);
assert_eq!(id_index.shortest_unique_prefix_len(b"acd"), 3);
// If it were there, the length would be 1.
assert_eq!(id_index.shortest_unique_prefix_len(b"c"), 1);
}
} }