()
| 3741 | |
| 3742 | #[test] |
| 3743 | fn intersection_default() { |
| 3744 | // Two slices of string literals. |
| 3745 | let set1 = ["banana", "apple", "cherry"]; |
| 3746 | let set2 = ["cherry", "orange", "pineapple", "banana"]; |
| 3747 | // Output buffers: size must be at least min(set1.len(), set2.len()). |
| 3748 | let mut out1 = [0; 3]; |
| 3749 | let mut out2 = [0; 3]; |
| 3750 | |
| 3751 | let n = sz::intersection(&set1, &set2, 0, &mut out1, &mut out2).expect("intersection failed"); |
| 3752 | assert!(n <= set1.len().min(set2.len())); |
| 3753 | |
| 3754 | // For simplicity, we will compare the intersection from the first set. |
| 3755 | // Our API returns indices (for set1 in out1). |
| 3756 | let common_from_api: HashSet<_> = out1[..n].iter().map(|&i| set1[i]).collect(); |
| 3757 | |
| 3758 | // Compute the expected intersection using a `HashSet`. |
| 3759 | let expected: HashSet<_> = set1 |
| 3760 | .iter() |
| 3761 | .cloned() |
| 3762 | .collect::<HashSet<_>>() |
| 3763 | .intersection(&set2.iter().cloned().collect()) |
| 3764 | .cloned() |
| 3765 | .collect(); |
| 3766 | |
| 3767 | assert_eq!(common_from_api, expected); |
| 3768 | } |
| 3769 | |
| 3770 | #[test] |
| 3771 | fn intersection_by_custom() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…