Skip to content

Commit

Permalink
Created integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Jan 1, 2022
1 parent e6f3483 commit 9a16d92
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
40 changes: 40 additions & 0 deletions kalk/src/integration_testing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#[cfg(test)]
mod tests {
use std::{fs::File, io::Read, path::PathBuf};

use crate::kalk_num::KalkNum;

fn eval_file(name: &str) -> KalkNum {
let mut path = PathBuf::new();
path.push(env!("CARGO_MANIFEST_DIR"));
path.push("..");
path.push("tests");
path.push(name);
path.set_extension("kalker");

let mut file_content = String::new();
File::open(path)
.unwrap()
.read_to_string(&mut file_content)
.unwrap();
let mut context = crate::parser::Context::new();

crate::parser::eval(&mut context, &file_content, 58)
.unwrap()
.unwrap()
}

#[test]
fn test_basics() {
let result = eval_file("basics");
assert_eq!(result.to_string_real(10), "3400");
assert!(!result.has_imaginary());
}

#[test]
fn test_radix() {
let result = eval_file("radix");
assert_eq!(result.to_string_real(10), "62");
assert_eq!(result.to_string_imaginary(10, false), "11.3125");
}
}
1 change: 1 addition & 0 deletions kalk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod ast;
mod calculus;
mod integration_testing;
mod interpreter;
mod inverter;
pub mod kalk_num;
Expand Down
2 changes: 1 addition & 1 deletion kalk/src/text_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn subscript_to_digits(chars: impl Iterator<Item = char>) -> String {
});
}

return regular;
return regular.trim().to_string();
}

pub fn digits_to_subscript(chars: impl Iterator<Item = char>) -> String {
Expand Down
4 changes: 4 additions & 0 deletions tests/basics.kalker
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x = 2
y = 3
f(x) = 2x(x - 3)(y + 2)
f(f(x) + y)
1 change: 1 addition & 0 deletions tests/radix.kalker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0b1101.101 + 1101.101_2 + 0o13.5 + 13.5_8 + 11.5 + 0xb.5i

0 comments on commit 9a16d92

Please sign in to comment.