MCPcopy Create free account
hub / github.com/cosdata/cosdata / test_input_field_combinations

Function test_input_field_combinations

src/metadata/schema.rs:611–726  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

609
610 #[test]
611 fn test_input_field_combinations() {
612 let a_values: HashSet<FieldValue> = (1..=10).map(FieldValue::Int).collect();
613 let a = MetadataField::new("a".to_owned(), a_values).unwrap();
614
615 let b_values: HashSet<FieldValue> = (1..=10).map(FieldValue::Int).collect();
616 let b = MetadataField::new("b".to_owned(), b_values).unwrap();
617
618 let c_values: HashSet<FieldValue> = (1..=10).map(FieldValue::Int).collect();
619 let c = MetadataField::new("c".to_owned(), c_values).unwrap();
620
621 let conditions = vec![
622 SupportedCondition::And(hashset(vec!["a", "b"])),
623 SupportedCondition::And(hashset(vec!["a", "c"])),
624 SupportedCondition::Or(hashset(vec!["a", "b"])),
625 ];
626
627 let schema = MetadataSchema::new(vec![a, b, c], conditions).unwrap();
628
629 // Test case 1: As the input contains only a single field,
630 // only the following replicas are relevant to this vector:
631 //
632 // 1. matches "a"
633 //
634 // Hence the result is 1 combination i.e. 1 replica
635 let fs = ifc_input(vec![("a", 1)]);
636 let cs = schema.input_field_combinations(&fs);
637 assert_eq!(1, cs.len());
638 let mut ec1 = HashMap::with_capacity(1);
639 ec1.insert("a", &FieldValue::Int(1));
640 assert_eq!(ec1, cs[0]);
641
642 // Test case 2: As the input contains only "a" and "b", only
643 // the following replicas are relevant to this vector
644 //
645 // 1. matches "a"
646 // 2. matches "b"
647 // 3. matches "a AND b"
648 //
649 // Hence the result is 3 combinations i.e. 3 replicas.
650 let fs = ifc_input(vec![("a", 1), ("b", 2)]);
651 let mut cs = schema.input_field_combinations(&fs);
652
653 // To make the order of returned combinations deterministic,
654 // sort them by sum of the field values.
655 ifc_sort_result(&mut cs);
656
657 assert_eq!(3, cs.len());
658 let mut ec1 = HashMap::with_capacity(1);
659 ec1.insert("a", &FieldValue::Int(1));
660 let mut ec2 = HashMap::with_capacity(1);
661 ec2.insert("b", &FieldValue::Int(2));
662 let mut ec3 = HashMap::with_capacity(2);
663 ec3.insert("a", &FieldValue::Int(1));
664 ec3.insert("b", &FieldValue::Int(2));
665 assert_eq!(vec![ec1, ec2, ec3], cs);
666
667 // Test case 3: The input contains fields "b" and "c"
668 // only. There is no supported `AND` condition that includes

Callers

nothing calls this directly

Calls 4

ifc_inputFunction · 0.85
ifc_sort_resultFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected