Skip to content

Commit

Permalink
Correct Build Action (#240)
Browse files Browse the repository at this point in the history
This corrects the placement of `CORSET_TEST_LIMIT` in the build action.
  • Loading branch information
DavePearce authored Jul 22, 2024
1 parent 387ca8c commit 3e60e39
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
rustflags: ""
- name: Build
run: cargo build -vv
env:
CORSET_TEST_LIMIT: 1000
- name: Run tests
run: cargo test -v
env:
CORSET_TEST_LIMIT: 4
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn generate_tests_from_lisp_files() {
let out_dir = std::env::var("OUT_DIR").unwrap();
let limit = match env::var("CORSET_TEST_LIMIT") {
Ok(s) => s.parse().unwrap(),
Err(_) => 0,
Err(_) => 100,
};
let target = std::path::Path::new(&out_dir).join("lisp_tests.rs");
let mut f = fs::File::create(target).unwrap();
Expand All @@ -70,7 +70,6 @@ fn generate_tests_from_lisp_files() {
writeln!(f, "fn test_{}() {{ check(\"{}\"); }}", m.name, m.name).unwrap();
// Check whether oracle provided or not
if m.oracle.is_some() {
let limit = limit.max(m.limit);
// Generate trace inputs (accepts / rejects)
let (accepts, rejects) = m.generate_traces_upto(limit);
// Write them out.
Expand Down
46 changes: 34 additions & 12 deletions tests/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ struct Model {
name: &'static str,
/// The column names needed for this test.
cols: &'static [&'static str],
/// Number of rows to generate for.
limit: usize,
/// The oracle determines, for a given set of column data, whether
/// or not it should be accepted or rejected.
oracle: Option<fn(data: &Trace) -> bool>,
Expand All @@ -25,14 +23,16 @@ impl Model {
/// length `n`, and split them into the `accepts` and `rejects`.
/// The former are those traces which are expected to pass, whilst
/// the latter are those which are expected to fail.
pub fn generate_traces_upto(&self, n: usize) -> (Vec<Trace>, Vec<Trace>) {
pub fn generate_traces_upto(&self, m: usize) -> (Vec<Trace>, Vec<Trace>) {
let max_rows = Self::determine_max_rows(self.cols.len(), m);
//
let Some(oracle) = self.oracle else {
panic!();
};
let mut accepts = Vec::new();
let mut rejects = Vec::new();
//
for i in 0..n {
for i in 0..max_rows {
for tr in self.generate_all_traces(i) {
// Test the trace using the given oracle to check whether
// (or not) it should be accepted.
Expand Down Expand Up @@ -77,6 +77,36 @@ impl Model {
// no more
return false;
}

// Determine maximum number of trace rows we can generate within
// the given budget (i.e. maximum number of traces).
fn determine_max_rows(n: usize, m: usize) -> usize {
let mut cost = 0;
// You can compute this with pow
for i in 0..10 {
let ith = Self::cost_max_rows(i, n);
//
if (cost + ith) >= m {
return i;
}
//
cost += ith;
}
// Should be
unreachable!()
}

fn cost_max_rows(i: usize, n: usize) -> usize {
let diff = 1 + (Self::MAX_ELEMENT - Self::MIN_ELEMENT) as usize;
//
let mut acc = 1;
// You can compute this with pow
for _ in 0..(i * n) {
acc *= diff;
}
//
acc
}
}

/// Represents an individial trace which, for a given number of rows,
Expand Down Expand Up @@ -163,49 +193,41 @@ static MODELS: &[Model] = &[
Model {
name: "arrays_1",
cols: &["A", "B_1", "B_2", "B_3"],
limit: 2,
oracle: Some(arrays_1_oracle),
},
Model {
name: "iszero",
cols: &["A", "B"],
limit: 3,
oracle: Some(iszero_oracle),
},
Model {
name: "shift_1",
cols: &["A", "B"],
limit: 3,
oracle: Some(shift_1_oracle),
},
Model {
name: "shift_2",
cols: &["A", "B"],
limit: 3,
oracle: Some(shift_2_oracle),
},
Model {
name: "shift_3",
cols: &["A", "B"],
limit: 3,
oracle: Some(shift_3_oracle),
},
Model {
name: "shift_5",
cols: &["A", "B", "C"],
limit: 2,
oracle: Some(shift_5_oracle),
},
Model {
name: "vanish_1",
cols: &["X"],
limit: 3,
oracle: Some(|_| false),
},
Model {
name: "vanish_2",
cols: &["X"],
limit: 3,
oracle: Some(|_| false),
},
];
Expand Down

0 comments on commit 3e60e39

Please sign in to comment.