Compare commits
No commits in common. "85964de3517a15c3f18b75ebe84ca27a3373e9f3" and "2f600e01e39c3a85d8f88984b6bd449bbeb849e9" have entirely different histories.
85964de351
...
2f600e01e3
@ -31,7 +31,7 @@ pub fn min<T>(x: T, y: T) -> T
|
||||
// METHODS Vectors
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
pub fn restrict<T>(x: &Vec<T>, i: usize, j: usize) -> Vec<T>
|
||||
pub fn restrict<T>(x: &mut Vec<T>, i: usize, j: usize) -> Vec<T>
|
||||
where T: Clone
|
||||
{
|
||||
return x[i..j].iter()
|
||||
@ -39,23 +39,17 @@ pub fn restrict<T>(x: &Vec<T>, i: usize, j: usize) -> Vec<T>
|
||||
.collect::<Vec<T>>();
|
||||
}
|
||||
|
||||
pub fn remove_last<T>(x: &Vec<T>) -> Vec<T>
|
||||
pub fn remove_last<T>(x: &mut Vec<T>) -> Vec<T>
|
||||
where T: Clone
|
||||
{
|
||||
let n = x.len();
|
||||
if n == 0 {
|
||||
return Vec::<T>::new();
|
||||
}
|
||||
return restrict::<T>(x, 0, n-1);
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn remove_first<T>(x: &Vec<T>) -> Vec<T>
|
||||
pub fn remove_first<T>(x: &mut Vec<T>) -> Vec<T>
|
||||
where T: Clone
|
||||
{
|
||||
let n = x.len();
|
||||
if n == 0 {
|
||||
return Vec::<T>::new();
|
||||
}
|
||||
return restrict::<T>(x, 0, n);
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
extern crate ads2;
|
||||
|
||||
pub mod test_core;
|
||||
pub mod test_stacks;
|
||||
pub mod test_graphs;
|
@ -1 +0,0 @@
|
||||
pub mod test_utils;
|
@ -1,62 +0,0 @@
|
||||
// ----------------------------------------------------------------
|
||||
// IMPORTS
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
use ads2::core::utils;
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Test regex
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn test_regex() {
|
||||
let re = utils::construct_regex("^a+(.*?)bc");
|
||||
assert_eq!(re.is_match("aaa---bc"), true);
|
||||
assert_eq!(re.is_match("aaa---b"), false);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Test min
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
fn test_min() {
|
||||
assert_eq!(utils::min("beth", "alef"), "alef");
|
||||
assert_eq!(utils::min("alef", "beth"), "alef");
|
||||
assert_eq!(utils::min("alef", "ale"), "ale");
|
||||
assert_eq!(utils::min(320, 24), 24);
|
||||
assert_eq!(utils::min(0.03, 0.2), 0.03);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Test vector methods
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
#[test]
|
||||
pub fn test_restrict() {
|
||||
let x: Vec<String> = vec![String::from("a"), String::from("b"), String::from("b"), String::from("c"), String::from("d"), String::from("e")];
|
||||
assert_eq!(utils::restrict(&x, 0, 0), Vec::<String>::new());
|
||||
assert_eq!(utils::restrict(&x, 2, 2), Vec::<String>::new());
|
||||
assert_eq!(utils::restrict(&x, 0, 1), vec!["a"]);
|
||||
assert_eq!(utils::restrict(&x, 2, 4), vec!["b", "c"]);
|
||||
let x: Vec<i32> = vec![78, 100, -3, 1];
|
||||
assert_eq!(utils::restrict(&x, 0, 0), Vec::<i32>::new());
|
||||
assert_eq!(utils::restrict(&x, 4, 4), Vec::<i32>::new());
|
||||
assert_eq!(utils::restrict(&x, 1, 3), vec![100, -3]);
|
||||
let mut x_restr = utils::restrict(&x, 1, 3);
|
||||
x_restr[0] = 58;
|
||||
assert_ne!(x[1], 58, "Result should be a copy.");
|
||||
assert_eq!(x[1], 100, "Result should be a copy.");
|
||||
}
|
||||
|
||||
pub fn test_remove_first_last() {
|
||||
let x: Vec<String> = vec!["merkur", "venus", "mars", "terra", "jupiter", "saturn", "uranus", "neptun"]
|
||||
.iter()
|
||||
.map(|s| {s.to_string()})
|
||||
.collect::<Vec<String>>();
|
||||
assert_eq!(utils::remove_first(&x), vec!["venus", "mars", "terra", "jupiter", "saturn", "uranus", "neptun"]);
|
||||
assert_eq!(utils::remove_last(&x), vec!["merkur", "venus", "mars", "terra", "jupiter", "saturn", "uranus"]);
|
||||
let x: Vec<f64> = vec![];
|
||||
assert_eq!(utils::remove_first(&x), Vec::<f64>::new());
|
||||
assert_eq!(utils::remove_last(&x), Vec::<f64>::new());
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
pub mod test_graph;
|
||||
pub mod test_tarjan;
|
@ -1 +0,0 @@
|
||||
mod test_stack;
|
@ -1,63 +0,0 @@
|
||||
// ----------------------------------------------------------------
|
||||
// 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());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user