| 650 | |
| 651 | #[test] |
| 652 | fn approx_topk_basic() { |
| 653 | let mut docs: Vec<Vec<u8>> = Vec::new(); |
| 654 | for _ in 0..10 { |
| 655 | docs.push(encode(&json!({"cat": "a"}))); |
| 656 | } |
| 657 | for _ in 0..5 { |
| 658 | docs.push(encode(&json!({"cat": "b"}))); |
| 659 | } |
| 660 | for _ in 0..1 { |
| 661 | docs.push(encode(&json!({"cat": "c"}))); |
| 662 | } |
| 663 | let refs: Vec<&[u8]> = docs.iter().map(|d| d.as_slice()).collect(); |
| 664 | let result = compute_aggregate_binary("approx_topk", "3:cat", None, &refs); |
| 665 | if let Value::Array(arr) = result { |
| 666 | assert!(!arr.is_empty(), "should have top-k results"); |
| 667 | } else { |
| 668 | panic!("expected Array, got {result:?}"); |
| 669 | } |
| 670 | } |
| 671 | } |