1
1
mirror of https://github.com/ProvableHQ/leo.git synced 2024-12-29 05:02:52 +03:00
leo/compiler/tests/boolean/mod.rs

197 lines
5.0 KiB
Rust
Raw Normal View History

2021-02-02 07:26:56 +03:00
// Copyright (C) 2019-2021 Aleo Systems Inc.
2020-08-18 13:50:26 +03:00
// This file is part of the Leo library.
// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{
assert_satisfied,
2020-12-17 00:02:31 +03:00
expect_asg_error,
2020-07-30 21:11:54 +03:00
expect_compiler_error,
2020-08-01 07:15:33 +03:00
get_output,
parse_program,
2020-08-01 05:39:30 +03:00
parse_program_with_input,
EdwardsTestCompiler,
};
2020-06-03 02:56:11 +03:00
pub fn output_true(program: EdwardsTestCompiler) {
2020-08-17 05:14:26 +03:00
let expected = include_bytes!("output/registers_true.out");
2020-08-01 07:15:33 +03:00
let actual = get_output(program);
assert_eq!(expected, actual.bytes().as_slice());
2020-06-03 02:56:11 +03:00
}
pub fn output_false(program: EdwardsTestCompiler) {
2020-08-17 05:14:26 +03:00
let expected = include_bytes!("output/registers_false.out");
2020-08-01 07:15:33 +03:00
let actual = get_output(program);
assert_eq!(expected, actual.bytes().as_slice());
}
#[test]
fn test_input_pass() {
let program_string = include_str!("assert_eq_input.leo");
let input_string = include_str!("input/true_true.in");
2020-06-09 03:28:09 +03:00
let program = parse_program_with_input(program_string, input_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}
#[test]
fn test_input_fail() {
let program_string = include_str!("assert_eq_input.leo");
let input_string = include_str!("input/true_false.in");
2020-06-09 03:28:09 +03:00
let program = parse_program_with_input(program_string, input_string).unwrap();
2020-06-09 03:28:09 +03:00
2020-08-17 03:20:47 +03:00
expect_compiler_error(program);
}
#[test]
fn test_registers() {
let program_string = include_str!("output_register.leo");
let true_input_string = include_str!("input/registers_true.in");
let false_input_string = include_str!("input/registers_false.in");
2020-06-09 03:28:09 +03:00
// test true input register => true output register
let program = parse_program_with_input(program_string, true_input_string).unwrap();
2020-06-09 03:28:09 +03:00
output_true(program);
// test false input register => false output register
let program = parse_program_with_input(program_string, false_input_string).unwrap();
output_false(program);
}
// Boolean not !
#[test]
fn test_not_true() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("not_true.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}
#[test]
fn test_not_false() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("not_false.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}
#[test]
fn test_not_mutable() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("not_mutable.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
2021-02-03 05:42:00 +03:00
#[test]
fn test_conditional_mut() {
let program_string = include_str!("conditional_mut.leo");
let program = parse_program(program_string).unwrap();
assert_satisfied(program);
}
#[test]
fn test_not_u32() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("not_u32.leo");
2020-12-17 00:02:31 +03:00
let error = parse_program(program_string).err().unwrap();
2020-06-09 03:28:09 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
}
// Boolean or ||
#[test]
fn test_true_or_true() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("true_or_true.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}
#[test]
fn test_true_or_false() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("true_or_false.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}
#[test]
fn test_false_or_false() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("false_or_false.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}
2020-11-12 21:28:24 +03:00
#[test]
fn test_true_or_u32() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("true_or_u32.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
// Boolean and &&
#[test]
fn test_true_and_true() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("true_and_true.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}
#[test]
fn test_true_and_false() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("true_and_false.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}
#[test]
fn test_false_and_false() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("false_and_false.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}
2020-11-12 21:28:24 +03:00
#[test]
fn test_true_and_u32() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("true_and_u32.leo");
let error = parse_program(program_string).err().unwrap();
2020-11-12 21:28:24 +03:00
2020-12-17 00:02:31 +03:00
expect_asg_error(error);
2020-11-12 21:28:24 +03:00
}
// All
#[test]
fn test_all() {
2020-12-04 23:48:43 +03:00
let program_string = include_str!("all.leo");
let program = parse_program(program_string).unwrap();
2020-06-09 03:28:09 +03:00
assert_satisfied(program);
}