()
| 727 | |
| 728 | #[test] |
| 729 | fn test_weighted_dimensions() { |
| 730 | let age_values: HashSet<FieldValue> = (1..=10).map(FieldValue::Int).collect(); |
| 731 | let age = MetadataField::new("age".to_owned(), age_values).unwrap(); |
| 732 | |
| 733 | let group_values: HashSet<FieldValue> = vec!["a", "b", "c"] |
| 734 | .into_iter() |
| 735 | .map(|x| FieldValue::String(String::from(x))) |
| 736 | .collect(); |
| 737 | let group = MetadataField::new("group".to_owned(), group_values).unwrap(); |
| 738 | |
| 739 | let level_values: HashSet<FieldValue> = vec!["first", "second", "third"] |
| 740 | .into_iter() |
| 741 | .map(|x| FieldValue::String(String::from(x))) |
| 742 | .collect(); |
| 743 | let level = MetadataField::new("level".to_owned(), level_values).unwrap(); |
| 744 | |
| 745 | let conditions = vec![ |
| 746 | SupportedCondition::And(hashset(vec!["age", "group"])), |
| 747 | SupportedCondition::And(hashset(vec!["age", "level"])), |
| 748 | ]; |
| 749 | |
| 750 | let schema = MetadataSchema::new(vec![age, group, level], conditions).unwrap(); |
| 751 | |
| 752 | // Case 1: When only "age" field is specified in input vector |
| 753 | |
| 754 | let mut fields = HashMap::with_capacity(1); |
| 755 | fields.insert("age".to_owned(), FieldValue::Int(5)); |
| 756 | let wd = schema.weighted_dimensions(&fields, 1024).unwrap(); |
| 757 | let exp_dim1 = vec![ |
| 758 | 0, 1024, 0, 1024, // 5 (original value: 5) |
| 759 | 0, 0, // (not specified) |
| 760 | 0, 0, // (not specified) |
| 761 | ]; |
| 762 | assert_eq!(vec![exp_dim1], wd); |
| 763 | |
| 764 | // Case 2: When only "age" and "group" fields are specified in |
| 765 | // input vector |
| 766 | |
| 767 | let mut fields = HashMap::with_capacity(2); |
| 768 | fields.insert("age".to_owned(), FieldValue::Int(5)); |
| 769 | fields.insert("group".to_owned(), FieldValue::String("a".to_owned())); |
| 770 | let wd = schema.weighted_dimensions(&fields, 1024).unwrap(); |
| 771 | let exp = vec![ |
| 772 | vec![ |
| 773 | 0, 1024, 0, 1024, // 5 (original value: 5) |
| 774 | 0, 0, // no high weights |
| 775 | 0, 0, // no high weights |
| 776 | ], |
| 777 | vec![ |
| 778 | 0, 0, 0, 0, // no high weights |
| 779 | 0, 1024, // 1 (original value: a) |
| 780 | 0, 0, // no high weights |
| 781 | ], |
| 782 | vec![ |
| 783 | 0, 1024, 0, 1024, // 5 (original value: 5) |
| 784 | 0, 1024, // 1 (original value: a) |
| 785 | 0, 0, // (not specified) |
| 786 | ], |
nothing calls this directly
no test coverage detected