Skip to content

Commit

Permalink
Add tests for #241
Browse files Browse the repository at this point in the history
This adds the test cases from #241.
  • Loading branch information
DavePearce committed Jul 23, 2024
1 parent 3e60e39 commit 8b76d37
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
7 changes: 7 additions & 0 deletions tests/issue241_a.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(defcolumns X)

(defconstraint constraint-1 () (is-not-zero! (if (is-zero 1) 1 1)))
(defconstraint constraint-2 () (eq! (is-not-zero! (if (is-zero X) 1 X)) 0))
(defconstraint constraint-3 () (eq! (~and! (is-not-zero! (if (is-zero 0) 1 0)) 0) 0))
(defconstraint constraint-4 () (is-not-zero! (if (is-zero 0) 1 0)))
(defconstraint constraint-5 () (is-not-zero! (if (is-zero X) 1 X)))
6 changes: 6 additions & 0 deletions tests/issue241_b.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(defcolumns X ST)

;; ST ==> x != 1
(defconstraint constraint-6 () (if-not-zero ST (neq! 1 (if (is-zero 0) X X))))
;; ST ==> x != 0
(defconstraint constraint-7 () (if-not-zero ST (neq! 0 (if (is-zero X) X X))))
39 changes: 33 additions & 6 deletions tests/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,16 @@ static MODELS: &[Model] = &[
cols: &["X"],
oracle: Some(|_| false),
},
Model {
name: "issue241_a",
cols: &["X"],
oracle: Some(|_| true),
},
Model {
name: "issue241_b",
cols: &["ST", "X"],
oracle: Some(issue241_b_oracle),
},
];

// ===================================================================
Expand All @@ -251,9 +261,9 @@ fn arrays_1_oracle(tr: &Trace) -> bool {
true
}

// // ===================================================================
// // IsZero
// // ===================================================================
// ===================================================================
// IsZero
// ===================================================================

#[allow(non_snake_case)]
fn iszero_oracle(tr: &Trace) -> bool {
Expand All @@ -267,9 +277,9 @@ fn iszero_oracle(tr: &Trace) -> bool {
true
}

// // ===================================================================
// // Shift
// // ===================================================================
// ===================================================================
// Shift
// ===================================================================

#[allow(non_snake_case)]
fn shift_1_oracle(tr: &Trace) -> bool {
Expand Down Expand Up @@ -323,3 +333,20 @@ fn shift_5_oracle(tr: &Trace) -> bool {
}
true
}

// ===================================================================
// Issue 241
// ===================================================================

#[allow(non_snake_case)]
fn issue241_b_oracle(tr: &Trace) -> bool {
let (X, ST) = (tr.col("X"), tr.col("ST"));
for k in 0..tr.height() {
let c1 = ST[k] == 0 || X[k] != 1;
let c2 = ST[k] == 0 || X[k] != 0;
if !c1 || !c2 {
return false;
}
}
true
}

0 comments on commit 8b76d37

Please sign in to comment.