Skip to content

Commit

Permalink
refactor: add helper function to construct fst value
Browse files Browse the repository at this point in the history
Signed-off-by: Zhenchi <[email protected]>
  • Loading branch information
zhongzc committed Dec 4, 2023
1 parent eef919f commit 08fd331
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/index/src/inverted_index/search/fst_values_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ mod tests {
use super::*;
use crate::inverted_index::format::reader::MockInvertedIndexReader;

fn value(offset: u32, size: u32) -> u64 {
((offset as u64) << 32) | (size as u64)
}

#[tokio::test]
async fn test_map_values() {
let mut mock_reader = MockInvertedIndexReader::new();
Expand All @@ -88,20 +92,20 @@ mod tests {
let result = values_mapper.map_values(&[]).await.unwrap();
assert_eq!(result.count_ones(), 0);

let result = values_mapper.map_values(&[(1 << 32) | 1]).await.unwrap();
let result = values_mapper.map_values(&[value(1, 1)]).await.unwrap();
assert_eq!(result, bitvec![u8, Lsb0; 1, 0, 1, 0, 1, 0, 1]);

let result = values_mapper.map_values(&[(2 << 32) | 1]).await.unwrap();
let result = values_mapper.map_values(&[value(2, 1)]).await.unwrap();
assert_eq!(result, bitvec![u8, Lsb0; 0, 1, 0, 1, 0, 1, 0, 1]);

let result = values_mapper
.map_values(&[(1 << 32) | 1, (2 << 32) | 1])
.map_values(&[value(1, 1), value(2, 1)])
.await
.unwrap();
assert_eq!(result, bitvec![u8, Lsb0; 1, 1, 1, 1, 1, 1, 1, 1]);

let result = values_mapper
.map_values(&[(2 << 32) | 1, (1 << 32) | 1])
.map_values(&[value(2, 1), value(1, 1)])
.await
.unwrap();
assert_eq!(result, bitvec![u8, Lsb0; 1, 1, 1, 1, 1, 1, 1, 1]);
Expand Down

0 comments on commit 08fd331

Please sign in to comment.