-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfeature.rs
More file actions
81 lines (70 loc) · 2.38 KB
/
Copy pathfeature.rs
File metadata and controls
81 lines (70 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crate::config::CONFIG;
use fixedbitset::FixedBitSet;
use std::ops::BitOrAssign;
use std::path::Path;
use std::sync::LazyLock;
use zip_diff::hash::{read_parsing_result, ParsingResult};
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct Feature {
pub ok: FixedBitSet,
pub inconsistency: FixedBitSet,
}
pub static PAIR_LIST: LazyLock<Vec<(String, String)>> = LazyLock::new(Feature::pair_list);
impl Feature {
pub fn new() -> Self {
let n = CONFIG.parsers.len();
let ok = FixedBitSet::with_capacity(n);
let inconsistency = FixedBitSet::with_capacity(n * (n - 1) / 2);
Self { ok, inconsistency }
}
pub fn par_read(name: impl AsRef<Path>) -> Self {
let mut feature = Self::new();
feature.apply_testcase(name, true);
feature
}
pub fn apply_testcase(&mut self, name: impl AsRef<Path>, par: bool) {
let results = CONFIG
.parsers
.iter()
.map(|parser| read_parsing_result(CONFIG.output_dir.join(parser).join(&name), par))
.collect::<Vec<_>>();
let mut p = 0;
for (i, x) in results.iter().enumerate() {
if matches!(x, ParsingResult::Ok(_)) {
self.ok.insert(i);
}
for y in &results[..i] {
if x.inconsistent_with(y) {
self.inconsistency.insert(p);
}
p += 1;
}
}
}
pub fn is_covered_by(&self, by: &Self) -> bool {
self.inconsistency.is_subset(&by.inconsistency) && self.ok.is_subset(&by.ok)
}
pub fn consistent_pairs(&self) -> Vec<&'static (String, String)> {
self.inconsistency.zeroes().map(|i| &PAIR_LIST[i]).collect()
}
pub fn summary(&self) -> String {
let ok_count = self.ok.count_ones(..);
let incons_count = self.inconsistency.count_ones(..);
format!("ok: {ok_count:2}, incons: {incons_count:4}")
}
fn pair_list() -> Vec<(String, String)> {
let mut result = Vec::new();
for (i, x) in CONFIG.parsers.iter().enumerate() {
for y in CONFIG.parsers.iter().take(i) {
result.push((x.clone(), y.clone()));
}
}
result
}
}
impl BitOrAssign<&Feature> for Feature {
fn bitor_assign(&mut self, rhs: &Feature) {
self.ok |= &rhs.ok;
self.inconsistency |= &rhs.inconsistency;
}
}