Skip to content

Commit bfdc6bb

Browse files
committed
add the subset-relations dataset as tests
1 parent a6b6098 commit bfdc6bb

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/test.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg(test)]
22

33
use crate::dump::Output;
4-
use crate::facts::{AllFacts, Loan, Point};
4+
use crate::facts::{AllFacts, Loan, Origin, Point};
55
use crate::intern;
66
use crate::program::parse_from_program;
77
use crate::tab_delim;
@@ -613,3 +613,55 @@ fn transitive_illegal_subset_error() {
613613
assert_eq!(checker.subset_errors_count(), 1);
614614
assert!(checker.subset_error_exists("'a", "'c", "\"Mid(B0[1])\""));
615615
}
616+
617+
#[test]
618+
fn successes_in_subset_relations_dataset() {
619+
let successes = ["valid_subset", "implied_bounds_subset"];
620+
621+
// these tests have no illegal access errors or subset errors
622+
for test_fn in &successes {
623+
let facts_dir = Path::new(env!("CARGO_MANIFEST_DIR"))
624+
.join("inputs")
625+
.join("subset-relations")
626+
.join("nll-facts")
627+
.join(test_fn);
628+
let tables = &mut intern::InternerTables::new();
629+
let facts = tab_delim::load_tab_delimited_facts(tables, &facts_dir).expect("facts");
630+
631+
let result = Output::compute(&facts, Algorithm::Naive, true);
632+
assert!(result.errors.is_empty());
633+
assert!(result.subset_errors.is_empty());
634+
}
635+
}
636+
637+
#[test]
638+
fn errors_in_subset_relations_dataset() {
639+
let facts_dir = Path::new(env!("CARGO_MANIFEST_DIR"))
640+
.join("inputs")
641+
.join("subset-relations")
642+
.join("nll-facts")
643+
.join("missing_subset");
644+
let tables = &mut intern::InternerTables::new();
645+
let facts = tab_delim::load_tab_delimited_facts(tables, &facts_dir).expect("facts");
646+
647+
// this function has no illegal access errors, but one subset error, over 3 points
648+
let result = Output::compute(&facts, Algorithm::Naive, true);
649+
assert!(result.errors.is_empty());
650+
assert_eq!(result.subset_errors.len(), 3);
651+
652+
let points = ["\"Mid(bb0[0])\"", "\"Start(bb0[1])\"", "\"Mid(bb0[1])\""];
653+
for point in &points {
654+
let point = tables.points.intern(point);
655+
let subset_error = result.subset_errors.get(&point).unwrap();
656+
657+
// in this dataset, `'a` is interned as `'1`
658+
let origin_a = Origin::from(1);
659+
660+
// `'b` is interned as `'2`
661+
let origin_b = Origin::from(2);
662+
663+
// and there should be a `'b: 'a` known subset to make the function valid, so
664+
// that is the subset error we should find
665+
assert!(subset_error.contains(&(origin_b, origin_a)));
666+
}
667+
}

0 commit comments

Comments
 (0)