Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Build Action #240

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -4,35 +4,35 @@
/// be accepted and which should be rejected. In essence, we are
/// comparing a Rust function (the model) against the constraints
/// evaluated on the trace.
struct Model {

Check warning on line 7 in tests/models.rs

View workflow job for this annotation

GitHub Actions / build

struct `Model` is never constructed
/// The name of this test (which should correspond to a lisp
/// file).
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>,
}

impl Model {
const MIN_ELEMENT: isize = -1;

Check warning on line 19 in tests/models.rs

View workflow job for this annotation

GitHub Actions / build

multiple associated items are never used
const MAX_ELEMENT: isize = 1;

/// Generate all traces matching the model configuration upto
/// 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,11 +77,41 @@
// 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,
/// contains values for each of the columns.
struct Trace {

Check warning on line 114 in tests/models.rs

View workflow job for this annotation

GitHub Actions / build

struct `Trace` is never constructed
/// Simplistic column schema.
cols: &'static [&'static str],
/// The trace data, whose length must be divisible by `width`.
Expand All @@ -92,7 +122,7 @@
}

impl Trace {
pub fn new(cols: &'static [&'static str], data: Vec<isize>) -> Self {

Check warning on line 125 in tests/models.rs

View workflow job for this annotation

GitHub Actions / build

associated items `new`, `height`, `width`, `col`, and `get` are never used
Self {
cols,
data,
Expand Down Expand Up @@ -133,7 +163,7 @@

/// Represents a single column which can contain zero (or more) rows
/// of padding at the beginning.
struct Column<'a> {

Check warning on line 166 in tests/models.rs

View workflow job for this annotation

GitHub Actions / build

struct `Column` is never constructed
// The raw data underlying this column
data: &'a [isize],
// The number of rows of passing which are assumed to be prepended
Expand All @@ -159,53 +189,45 @@

/// The master list of active models. Tests will be automatically
/// generated for each item in this list.
static MODELS: &[Model] = &[

Check warning on line 192 in tests/models.rs

View workflow job for this annotation

GitHub Actions / build

static `MODELS` is never used
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 All @@ -215,7 +237,7 @@
// ===================================================================

#[allow(non_snake_case)]
fn arrays_1_oracle(tr: &Trace) -> bool {

Check warning on line 240 in tests/models.rs

View workflow job for this annotation

GitHub Actions / build

function `arrays_1_oracle` is never used
let (A, B_1, B_2, B_3) = (tr.col("A"), tr.col("B_1"), tr.col("B_2"), tr.col("B_3"));

for k in 0..tr.height() {
Expand All @@ -234,7 +256,7 @@
// // ===================================================================

#[allow(non_snake_case)]
fn iszero_oracle(tr: &Trace) -> bool {

Check warning on line 259 in tests/models.rs

View workflow job for this annotation

GitHub Actions / build

function `iszero_oracle` is never used
let (A, B) = (tr.col("A"), tr.col("B"));

for k in 0..tr.height() {
Expand Down
Loading