Skip to content

Commit

Permalink
chore(test): add more test case (#616)
Browse files Browse the repository at this point in the history
* add more test case

Signed-off-by: d2lark <lichengamoy@gmail.com>

* optimize test cases

Signed-off-by: d2lark <lichengamoy@gmail.com>
  • Loading branch information
D2Lark committed Apr 10, 2022
1 parent abe584e commit 4627557
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions src/executor/sort_merge_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,10 @@ fn full_join(left_chunk: &Vec<Row>, right_chunk: &Vec<Row>) -> Vec<Row> {

#[cfg(test)]
mod tests {
use test_case::test_case;

use super::*;
use crate::array::ArrayImpl;
use crate::types::{DataTypeExt, DataTypeKind};
#[test_case(vec![1],vec![1],vec![1])]
#[test_case(vec![1],vec![1,1],vec![1,1])]
#[test_case(vec![1,1],vec![1,1],vec![1,1,1,1])]
#[test_case(vec![1,2,2,3,3],vec![2,3,3,4],vec![2,2,3,3,3,3])]
// #[test_case(vec![1,2,3],vec![4,5,6],vec![])]
#[tokio::test]

async fn sort_merge_test(left_col: Vec<i32>, right_col: Vec<i32>, expected_col: Vec<i32>) {
let left_child: BoxedExecutor = async_stream::try_stream! {
yield vec![
Expand Down Expand Up @@ -197,10 +190,35 @@ mod tests {

let mut executor = executor.execute();

let chunk = executor.next().await.unwrap().unwrap();
assert_eq!(
chunk.arrays(),
&vec![ArrayImpl::new_int32(expected_col.clone().into_iter().collect()); 4]
);
if let Some(chunk) = executor.next().await {
let chunk = chunk.unwrap();
assert_eq!(
chunk.arrays(),
&vec![ArrayImpl::new_int32(expected_col.clone().into_iter().collect()); 4]
);
} else {
assert!(expected_col.is_empty());
}
}
#[tokio::test]
async fn test_single_element() {
sort_merge_test(vec![1], vec![1], vec![1]).await;
sort_merge_test(vec![1, 2, 3], vec![2, 3, 4], vec![2, 3]).await;
}

#[tokio::test]
async fn test_duplicated_elements() {
sort_merge_test(vec![1, 1], vec![1, 1], vec![1, 1, 1, 1]).await;
sort_merge_test(
vec![1, 2, 2, 3, 3],
vec![2, 3, 3, 4],
vec![2, 2, 3, 3, 3, 3],
)
.await;
}

#[tokio::test]
async fn test_no_intersection() {
sort_merge_test(vec![1, 2, 3], vec![4, 5, 6], vec![]).await;
}
}

0 comments on commit 4627557

Please sign in to comment.