Skip to content

Commit

Permalink
Merge pull request #87 from lambdaclass/add-examples-as-tests
Browse files Browse the repository at this point in the history
Add examples as test cases.
  • Loading branch information
juanbono authored Feb 1, 2024
2 parents c59a2ff + 461de16 commit f20a8e9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/concrete_codegen_mlir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ itertools = "0.12.0"
llvm-sys = "170.0.1"
melior = { version = "0.15.2", features = ["ods-dialects"] }
mlir-sys = "0.2.1"
tracing.workspace = true
tracing = { workspace = true }

[build-dependencies]
cc = "1.0.83"
77 changes: 77 additions & 0 deletions crates/concrete_driver/tests/examples.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use crate::common::{compile_program, run_program};

mod common;

#[test]
fn borrow() {
let program = compile_program(
include_str!("../../../examples/borrow.con"),
"borrow",
false,
)
.unwrap();

let result = run_program(&program.binary_file).unwrap();
assert_eq!(result.status.code().unwrap(), 2);
}

#[test]
fn factorial_if() {
let program = compile_program(
include_str!("../../../examples/factorial_if.con"),
"factorial_if",
false,
)
.unwrap();

let result = run_program(&program.binary_file).unwrap();
assert_eq!(result.status.code().unwrap(), 24);
}

#[test]
fn fib_if() {
let program = compile_program(
include_str!("../../../examples/fib_if.con"),
"fib_if",
false,
)
.unwrap();

let result = run_program(&program.binary_file).unwrap();
assert_eq!(result.status.code().unwrap(), 55);
}

#[test]
fn import() {
let program = compile_program(
include_str!("../../../examples/import.con"),
"import",
false,
)
.unwrap();

let result = run_program(&program.binary_file).unwrap();
assert_eq!(result.status.code().unwrap(), 12);
}

#[test]
fn simple() {
let program = compile_program(
include_str!("../../../examples/simple.con"),
"simple",
false,
)
.unwrap();

let result = run_program(&program.binary_file).unwrap();
assert_eq!(result.status.code().unwrap(), 8);
}

#[test]
fn r#while() {
let program =
compile_program(include_str!("../../../examples/while.con"), "while", false).unwrap();

let result = run_program(&program.binary_file).unwrap();
assert_eq!(result.status.code().unwrap(), 16);
}

0 comments on commit f20a8e9

Please sign in to comment.