Skip to content

Commit 94fce4b

Browse files
author
GBathie
committed
Fix constants
1 parent 0ee665b commit 94fce4b

2 files changed

Lines changed: 55 additions & 11 deletions

File tree

src/algos/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::{
2525
AtomicProposition, Constant, LtlFormula,
2626
cache::LtlCache,
2727
charac::LtlCharac,
28+
cm::CharMatrix,
2829
trace::{Operators, Trace},
2930
},
3031
traits::EqTarget,
@@ -56,22 +57,16 @@ pub(crate) fn atoms(traces: &[Trace], atomic_propositions: Vec<String>) -> Vec<L
5657
let mut atoms = Vec::new();
5758

5859
let true_f = Formula::new_base(
59-
traces
60-
.iter()
61-
.filter_map(|t| t.atomic_propositions.first().map(|&p| p | !p))
62-
.collect::<LtlCharac>(),
60+
LtlCharac::new(CharMatrix::true_like(traces)),
6361
1,
6462
Rc::from(FormulaTree::Const(Constant::True)),
6563
);
6664
atoms.push(true_f);
6765

6866
let false_f = Formula::new_base(
69-
traces
70-
.iter()
71-
.filter_map(|t| t.atomic_propositions.first().map(|&p| p | !p))
72-
.collect::<LtlCharac>(),
67+
LtlCharac::new(CharMatrix::false_like(traces)),
7368
1,
74-
Rc::from(FormulaTree::Const(Constant::True)),
69+
Rc::from(FormulaTree::Const(Constant::False)),
7570
);
7671
atoms.push(false_f);
7772

src/tests/end_to_end.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use itertools::Itertools;
33
use crate::{
44
algos::{atoms, create_initial_cache, enumeration::aux::enum_aux},
55
formula::{rebuild_formula, tree::FormulaTree},
6-
ltl::trace::parse_traces,
6+
ltl::{Constant, trace::parse_traces},
77
};
88

9-
use super::{AND, F, G, Not, OR, SX, build_atom};
9+
use super::{AND, F, G, Not, OR, SX, build_atom, build_const};
1010

1111
fn test_ltl_search(instance: &str, expected: FormulaTree) {
1212
let instance = parse_traces(&instance);
@@ -17,6 +17,7 @@ fn test_ltl_search(instance: &str, expected: FormulaTree) {
1717
);
1818

1919
let atoms = atoms(&instance.traces, instance.atomic_propositions);
20+
2021
// Add initial formulas
2122
let (atom, mut ltl_cache) = create_initial_cache(atoms, &instance.target);
2223
if let Some(f) = atom {
@@ -120,6 +121,14 @@ fn instance_str(
120121
}
121122

122123
macro_rules! make_instance {
124+
(pos : [],
125+
neg: [$( { $( $name:ident : [$($v2:literal),*]),* }), *]) => {
126+
&instance_str(
127+
&[ ],
128+
&[ $( &[ $( &[ $( $v2),* ]),* ]),*],
129+
& helper!{ $([ $( $name ),* ]),* }
130+
)
131+
};
123132
(pos : [$( { $( $name:ident : [$($v:literal),*]),* }), *],
124133
neg: [$( { $( $name2:ident : [$($v2:literal),*]),* }), *]) => {
125134
&instance_str(
@@ -308,3 +317,43 @@ fn a_and_b_and_c() {
308317
);
309318
test_ltl_search(example, exp);
310319
}
320+
321+
#[test]
322+
fn empty_neg_is_true() {
323+
let example = make_instance!(
324+
pos: [
325+
{
326+
a: [1, 0, 1, 1],
327+
b: [1, 0, 0, 1],
328+
c: [1, 0, 1, 0]
329+
},
330+
{
331+
a: [1, 1, 0],
332+
b: [1, 0, 1],
333+
c: [1, 1, 1]
334+
}
335+
],
336+
neg: []);
337+
let exp = build_const(Constant::True);
338+
test_ltl_search(example, exp);
339+
}
340+
341+
#[test]
342+
fn empty_pos_is_false() {
343+
let example = make_instance!(
344+
pos: [ ],
345+
neg: [
346+
{
347+
a: [1, 0, 1, 1],
348+
b: [1, 0, 0, 1],
349+
c: [1, 0, 1, 0]
350+
},
351+
{
352+
a: [1, 1, 0],
353+
b: [1, 0, 1],
354+
c: [1, 1, 1]
355+
}
356+
]);
357+
let exp = build_const(Constant::False);
358+
test_ltl_search(example, exp);
359+
}

0 commit comments

Comments
 (0)