1use crate::mutation::MutationKind;
2use crate::target::Target;
3
4#[derive(Clone, Debug)]
8pub struct ScribbleConfig {
9 cases: u32,
10 targets: Vec<Target>,
11 kinds: Vec<MutationKind>,
12 include_cols: Vec<usize>,
13 exclude_cols: Vec<usize>,
14 include_rows: Vec<usize>,
15 exclude_rows: Vec<usize>,
16}
17
18impl Default for ScribbleConfig {
19 fn default() -> Self {
20 Self {
21 cases: 256,
22 targets: Vec::new(),
23 kinds: Vec::new(),
24 include_cols: Vec::new(),
25 exclude_cols: Vec::new(),
26 include_rows: Vec::new(),
27 exclude_rows: Vec::new(),
28 }
29 }
30}
31
32impl ScribbleConfig {
33 pub fn cases(mut self, cases: u32) -> Self {
34 self.cases = cases;
35 self
36 }
37
38 pub fn target(mut self, target: Target) -> Self {
39 self.targets = vec![target];
40 self
41 }
42
43 pub fn targets<I: IntoIterator<Item = Target>>(mut self, targets: I) -> Self {
44 self.targets = targets.into_iter().collect();
45 self
46 }
47
48 pub fn mutations<I: IntoIterator<Item = MutationKind>>(mut self, kinds: I) -> Self {
49 self.kinds = kinds.into_iter().collect();
50 self
51 }
52
53 pub fn include_cols<I: IntoIterator<Item = usize>>(mut self, cols: I) -> Self {
54 self.include_cols = cols.into_iter().collect();
55 self
56 }
57
58 pub fn exclude_cols<I: IntoIterator<Item = usize>>(mut self, cols: I) -> Self {
59 self.exclude_cols = cols.into_iter().collect();
60 self
61 }
62
63 pub fn include_rows<I: IntoIterator<Item = usize>>(mut self, rows: I) -> Self {
64 self.include_rows = rows.into_iter().collect();
65 self
66 }
67
68 pub fn exclude_rows<I: IntoIterator<Item = usize>>(mut self, rows: I) -> Self {
69 self.exclude_rows = rows.into_iter().collect();
70 self
71 }
72
73 pub fn case_count(&self) -> u32 {
74 self.cases
75 }
76
77 pub fn is_target_allowed(&self, target: Target) -> bool {
78 self.targets.is_empty() || self.targets.contains(&target)
79 }
80
81 pub fn is_kind_allowed(&self, kind: MutationKind) -> bool {
82 self.kinds.is_empty() || self.kinds.contains(&kind)
83 }
84
85 pub fn is_col_allowed(&self, col: usize) -> bool {
86 if !self.include_cols.is_empty() && !self.include_cols.contains(&col) {
87 return false;
88 }
89
90 !self.exclude_cols.contains(&col)
91 }
92
93 pub fn is_row_allowed(&self, row: usize) -> bool {
94 if !self.include_rows.is_empty() && !self.include_rows.contains(&row) {
95 return false;
96 }
97
98 !self.exclude_rows.contains(&row)
99 }
100}