Skip to content

Commit fdfdf12

Browse files
author
GBathie
committed
Adapt parser to int format
1 parent 367790e commit fdfdf12

2 files changed

Lines changed: 24 additions & 27 deletions

File tree

src/ltl/trace.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ pub fn parse_traces(buf: &str) -> Instance {
9595
#[derive(Debug, Clone, Deserialize)]
9696
pub struct ParsedTrace {
9797
#[serde(flatten)]
98-
atomic_propositions: HashMap<String, Vec<String>>,
98+
atomic_propositions: HashMap<String, Vec<usize>>,
9999
}
100100

101-
/// Converts a vector of "0"/"1" strings to a CharSeq
102-
fn vec_to_cs(v: &Vec<String>) -> CharSeq {
101+
/// Converts a vector of 0/1 ints to a CharSeq
102+
fn vec_to_cs(v: &Vec<usize>) -> CharSeq {
103103
v.iter()
104-
.map(|c| match c {
105-
s if s == "0" => false,
106-
s if s == "1" => true,
104+
.map(|x| match *x {
105+
0 => false,
106+
1 => true,
107107
_ => panic!("Unexpected literal in traces definition"),
108108
})
109109
.collect()
@@ -137,7 +137,7 @@ mod test {
137137

138138
#[test]
139139
fn convert_vec_to_cs() {
140-
let v = vec!["1".into(), "0".into(), "1".into()];
140+
let v = vec![1, 0, 1];
141141
let cs = vec_to_cs(&v);
142142
assert_eq!(cs.len(), 3);
143143
assert_eq!(cs.values, 0b101);
@@ -149,26 +149,26 @@ mod test {
149149
{
150150
"positive_traces": [
151151
{
152-
"a0": ["0", "1", "1", "0"],
153-
"a1": ["0", "1", "0", "1"]
152+
"a0": [0, 1, 1, 0],
153+
"a1": [0, 1, 0, 1]
154154
}
155155
],
156156
"negative_traces": [
157157
{
158-
"a0": ["1", "1", "1", "0"],
159-
"a1": ["0", "1", "0", "1"]
158+
"a0": [1, 1, 1, 0],
159+
"a1": [0, 1, 0, 1]
160160
},
161161
{
162-
"a0": ["0", "1", "1", "0"],
163-
"a1": ["0", "1", "1", "1"]
162+
"a0": [0, 1, 1, 0],
163+
"a1": [0, 1, 1, 1]
164164
},
165165
{
166-
"a0": ["0", "1", "1", "1"],
167-
"a1": ["0", "1", "0", "1"]
166+
"a0": [0, 1, 1, 1],
167+
"a1": [0, 1, 0, 1]
168168
},
169169
{
170-
"a0": ["0", "1", "1", "0"],
171-
"a1": ["0", "1", "0", "0"]
170+
"a0": [0, 1, 1, 0],
171+
"a1": [0, 1, 0, 0]
172172
}
173173
],
174174
"smallest_known_formula": "",

src/tests/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,16 @@ fn test_ltl_search(instance: &str, expected: FormulaTree) {
8989
/// ```json
9090
/// [
9191
/// {
92-
/// "a": ["1", "1", "1", "0"],
93-
/// "b": ["0", "0", "0", "0"]
92+
/// "a": [1, 1, 1, 0],
93+
/// "b": [0, 0, 0, 0]
9494
/// },
9595
/// {
96-
/// "a": ["0", "1"],
97-
/// "b": ["0", "0"]
96+
/// "a": [0, 1],
97+
/// "b": [0, 0]
9898
/// },
9999
/// {
100-
/// "a": ["0", "0", "1", "1"],
101-
/// "b": ["1", "0", "0", "0"]
100+
/// "a": [0, 0, 1, 1],
101+
/// "b": [1, 0, 0, 0]
102102
/// },
103103
/// ]
104104
/// ```
@@ -114,10 +114,7 @@ fn to_traces_str(traces: &[&[&[i32]]], atomic_props: &[&str]) -> String {
114114
ts.iter()
115115
.zip(atomic_props)
116116
.map(|(t, a)| {
117-
format!(
118-
r#""{a}": [{}]"#,
119-
t.iter().map(|s| format!(r#""{s}""#)).join(", ")
120-
)
117+
format!(r#""{a}": [{}]"#, t.iter().map(|s| s.to_string()).join(", "))
121118
})
122119
.join(", ")
123120
)

0 commit comments

Comments
 (0)