mirror of
https://github.com/PaddiM8/kalker.git
synced 2024-12-04 13:43:49 +01:00
Created integration tests
This commit is contained in:
parent
dbf3866137
commit
d01ce4c526
40
kalk/src/integration_testing.rs
Normal file
40
kalk/src/integration_testing.rs
Normal file
@ -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,5 +1,6 @@
|
||||
pub mod ast;
|
||||
mod calculus;
|
||||
mod integration_testing;
|
||||
mod interpreter;
|
||||
mod inverter;
|
||||
pub mod kalk_num;
|
||||
|
@ -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 {
|
||||
|
4
tests/basics.kalker
Normal file
4
tests/basics.kalker
Normal file
@ -0,0 +1,4 @@
|
||||
x = 2
|
||||
y = 3
|
||||
f(x) = 2x(x - 3)(y + 2)
|
||||
f(f(x) + y)
|
1
tests/radix.kalker
Normal file
1
tests/radix.kalker
Normal file
@ -0,0 +1 @@
|
||||
0b1101.101 + 1101.101_2 + 0o13.5 + 13.5_8 + 11.5 + 0xb.5i
|
Loading…
Reference in New Issue
Block a user