master > master: code-rust - basic unit tests hinzugefügt
This commit is contained in:
1
code/rust/tests/test_stacks/mod.rs
Normal file
1
code/rust/tests/test_stacks/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
mod test_stack;
|
||||
63
code/rust/tests/test_stacks/test_stack.rs
Normal file
63
code/rust/tests/test_stacks/test_stack.rs
Normal file
@@ -0,0 +1,63 @@
|
||||
// ----------------------------------------------------------------
|
||||
// IMPORTS
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
use std;
|
||||
extern crate closure;
|
||||
|
||||
use ads2::stacks::stack;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Test regex
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Test stack
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn test_stack_initialisation() {
|
||||
let stack = stack::Stack::<i32>::new();
|
||||
assert_eq!(stack.len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stack_push() {
|
||||
let mut stack = stack::Stack::<String>::new();
|
||||
assert_eq!(stack.len(), 0);
|
||||
stack.push("hallo".to_string());
|
||||
assert_eq!(stack.len(), 1);
|
||||
stack.push("welt".to_string());
|
||||
assert_eq!(stack.len(), 2);
|
||||
stack.push("!".to_string());
|
||||
assert_eq!(stack.len(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stack_no_error() {
|
||||
let mut stack = stack::Stack::<String>::new();
|
||||
stack.push("hallo".to_string());
|
||||
stack.push("welt".to_string());
|
||||
stack.push("!".to_string());
|
||||
let result = std::panic::catch_unwind(closure::closure!(move mut stack, || {
|
||||
stack.pop();
|
||||
stack.pop();
|
||||
stack.pop();
|
||||
}));
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_stack_error_po() {
|
||||
let mut stack = stack::Stack::<String>::new();
|
||||
stack.push("hallo".to_string());
|
||||
stack.push("welt".to_string());
|
||||
stack.push("!".to_string());
|
||||
let result = std::panic::catch_unwind(closure::closure!(move mut stack, || {
|
||||
stack.pop();
|
||||
stack.pop();
|
||||
stack.pop();
|
||||
stack.pop();
|
||||
}));
|
||||
assert!(result.is_err());
|
||||
}
|
||||
Reference in New Issue
Block a user