pub struct Unit { /* private fields */ }Implementations§
source§impl Unit
impl Unit
sourcepub fn new(description: &str) -> Unit
pub fn new(description: &str) -> Unit
Unit Constructor
descriptionA short description to describe the test
use unit::zuu::Unit;
Unit::new("Test description here");sourcepub fn chaos(&mut self, description: &str, f: &dyn Fn() -> bool) -> &mut Unit
pub fn chaos(&mut self, description: &str, f: &dyn Fn() -> bool) -> &mut Unit
Check if a theory is equal to false
descriptionThe theory descriptionfThe theory description
use unit::zuu::Unit;
fn real()-> bool
{
return false;
}
Unit::new("Check the life").chaos("This world is real",&real).end().expect("panic message");sourcepub fn check(&mut self, tdd: bool, s: &str, f: &str) -> &mut Unit
pub fn check(&mut self, tdd: bool, s: &str, f: &str) -> &mut Unit
Run a test
tddThe test to execute
use unit::zuu::Unit;
Unit::new("pythagore").check(3*3 + 4*4 == 5*5,"true","false").end().expect("panic message");sourcepub fn ok(&mut self, actual: &dyn Fn() -> bool) -> &mut Unit
pub fn ok(&mut self, actual: &dyn Fn() -> bool) -> &mut Unit
Check if actual match true
actualThe pointer to the function to check if she return true
use std::env;
use unit::zuu::Unit;
fn is_linux() -> bool
{
return env::consts::OS == "linux";
}
Unit::new("Check if it's a linux pc").ok(&is_linux).end().expect("panic message");sourcepub fn ko(&mut self, actual: &dyn Fn() -> bool) -> &mut Unit
pub fn ko(&mut self, actual: &dyn Fn() -> bool) -> &mut Unit
Check if actual match false
actualThe pointer to the function to check if she return false
use std::env;
use unit::zuu::Unit;
fn is_windows() -> bool
{
return env::consts::OS == "windows";
}
Unit::new("Check if it's a windows pc").ko(&is_windows).end().expect("panic message");sourcepub fn equals<T: PartialEq>(
&mut self,
actual: &dyn Fn() -> T,
expected: T
) -> &mut Unit
pub fn equals<T: PartialEq>( &mut self, actual: &dyn Fn() -> T, expected: T ) -> &mut Unit
Check if the function return the expected number
actualThe pointer to the function to testexpectedThe expected return result
use unit::zuu::Unit;
fn hypot()-> i32
{
return 5*5;
}
Unit::new("Verify the multiplication of the number 5 by 5").equals(&hypot,25)
.end().expect("panic message");sourcepub fn unequals<T: PartialEq>(
&mut self,
actual: &dyn Fn() -> T,
expected: T
) -> &mut Unit
pub fn unequals<T: PartialEq>( &mut self, actual: &dyn Fn() -> T, expected: T ) -> &mut Unit
Check if the function not return the expected number
actualThe pointer to the function to testexpectedThe expected value
use unit::zuu::Unit;
fn get_age()-> i32
{
return 30;
}
Unit::new("The age it's not equals to 200 years").unequals(&get_age,200).end().expect("panic message");sourcepub fn identical<T: PartialEq>(&mut self, actual: T, expected: T) -> &mut Unit
pub fn identical<T: PartialEq>(&mut self, actual: T, expected: T) -> &mut Unit
Check if two strings are equals
actualThe string actualexpectedThe expected value
use unit::zuu::Unit;
Unit::new("Check if the admin username is correct").identical("taishingi","taishingi").end().expect("panic message");sourcepub fn empty(&mut self, actual: &str) -> &mut Unit
pub fn empty(&mut self, actual: &str) -> &mut Unit
Check if the actual value is empty
actualThe string to check if is empty
use unit::zuu::Unit;
let users:[&str;3] = ["","nautilus","power"];
Unit::new("Check if user password is empty").empty(users[0]).end().expect("panic message");sourcepub fn not_empty(&mut self, actual: &str) -> &mut Unit
pub fn not_empty(&mut self, actual: &str) -> &mut Unit
Check if the actual value is not empty
actualThe string to check if is not empty
use unit::zuu::Unit;
let nums:[&str;3] = ["911","14",""];
Unit::new("Check if the phone number is defined").not_empty(nums[1]).end().expect("panic message");sourcepub fn different<T: PartialEq>(&mut self, actual: T, expected: T) -> &mut Unit
pub fn different<T: PartialEq>(&mut self, actual: T, expected: T) -> &mut Unit
Check if two value are unequals
actualThe actual valueexpectedThe expected value
use unit::zuu::Unit;
let cars:[&str;3] = ["volvo","citroen","peugeot"];
let car:[&str;3] = [ "porche","ferrari","jaguar"];
Unit::new("Check if two array are differents").different(cars,car).end().expect("panic message");sourcepub fn begin(&mut self, actual: &str, expected: &str) -> &mut Unit
pub fn begin(&mut self, actual: &str, expected: &str) -> &mut Unit
Check if a string start with the expected value
actualThe data to compareexpectedThe expected data at the beginning of actual
use unit::zuu::Unit;
Unit::new("Check the beginning of a phrase").begin("A superb woman kiss me last night.", "A").end().expect("panic message");sourcepub fn finnish(&mut self, actual: &str, expected: &str) -> &mut Unit
pub fn finnish(&mut self, actual: &str, expected: &str) -> &mut Unit
Check if the string finnish wish the expected value
actualThe data to compareexpectedThe expected data at the end of actual
use unit::zuu::Unit;
Unit::new("Check the end of a phrase").finnish("A musical who loves programming.", "programming.").end().expect("panic message");
sourcepub fn success(&mut self, f: &dyn Fn() -> i32) -> &mut Unit
pub fn success(&mut self, f: &dyn Fn() -> i32) -> &mut Unit
Check if the callback f return 0
fThe pointer to the function to check
use unit::zuu::Unit;
fn s()-> i32
{
return if 2%2 == 0 {0 } else { 1 };
}
Unit::new("Check if 2 is divisible by 2").success(&s).end().expect("panic message");sourcepub fn failure(&mut self, f: &dyn Fn() -> i32) -> &mut Unit
pub fn failure(&mut self, f: &dyn Fn() -> i32) -> &mut Unit
Check if the callback f return 1
fThe pointer to the callback to check
use unit::zuu::Unit;
fn f()-> i32
{
return if 4%3 == 0 { 0 } else { 1 };
}
Unit::new("Check if 2 is divisible by 3").failure(&f).end().expect("panic message");sourcepub fn theory<T: PartialEq>(
&mut self,
description: &str,
f: &dyn Fn() -> T,
expected: T
) -> &mut Unit
pub fn theory<T: PartialEq>( &mut self, description: &str, f: &dyn Fn() -> T, expected: T ) -> &mut Unit
Check a theory
descriptionThe theory descriptionfThe pointer to the function to checkexpectedThe expected theory value
use unit::zuu::Unit;
fn matrix()->bool
{
return false;
}
Unit::new("We are in the matrices ?").theory("All are real ?",&matrix,false).end().expect("panic message");sourcepub fn defined(&mut self, actual: &str) -> &mut Unit
pub fn defined(&mut self, actual: &str) -> &mut Unit
Check is the string is defined (not empty)
actualThe value to check
use unit::zuu::Unit;
let s = "Cleopatra love cesar";
Unit::new("The string is empty ?").defined(s).end().expect("panic message");sourcepub fn exist(&mut self, actual: &str) -> &mut Unit
pub fn exist(&mut self, actual: &str) -> &mut Unit
Check if the actual path exist
actualThe path to check the existence
use unit::zuu::Unit;
Unit::new("Check if the directory exist").exist("/home").end().expect("panic message");sourcepub fn not_equal(&mut self, actual: &str, expected: &str) -> &mut Unit
pub fn not_equal(&mut self, actual: &str, expected: &str) -> &mut Unit
Check if the actual string is not equal to expected
actualThe actual value to checkexpectedThe expected value
use unit::zuu::Unit;
let password = "1234"; /// not good ! but better than 0000.
let bad_password = "0000";
Unit::new("Check if password don't match 0000").not_equal(&bad_password,password).end().expect("panic message");sourcepub fn expect<T: PartialEq>(&mut self, actual: T, expected: T) -> &mut Unit
pub fn expect<T: PartialEq>(&mut self, actual: T, expected: T) -> &mut Unit
Check if actual is equal to expected
actualThe actual valueexpectedThe expected number
use unit::zuu::Unit;
Unit::new("birthday month...").expect(02,02).end().expect("panic message");sourcepub fn has(&mut self, actual: &str, expected: &str) -> &mut Unit
pub fn has(&mut self, actual: &str, expected: &str) -> &mut Unit
Check if expected is found in the actual string
actualThe actual valueexpectedThe expected value
use unit::zuu::Unit;
Unit::new("Check if forever exist in the poem").has("Habibi i love you forever","forever").end().expect("panic message");sourcepub fn not(&mut self, actual: &str, expected: &str) -> &mut Unit
pub fn not(&mut self, actual: &str, expected: &str) -> &mut Unit
Check if expected value is not founded in the actual string
actualThe string to parseexpectedThe expected value
use unit::zuu::Unit;
Unit::new("Check if habibi not exist in the poem").not("Habibi i love you forever","habibi").end().expect("panic message");sourcepub fn contains(&mut self, actual: &str, expected: &str) -> &mut Unit
pub fn contains(&mut self, actual: &str, expected: &str) -> &mut Unit
Check if a string contains a string
actualThe actual valueexpectedThe expected value
use unit::zuu::Unit;
let x = String::from("500000 pieces d'or");
Unit::new("Check if a coffer is there").contains(&x,"or").end().expect("panic message");
sourcepub fn superior<T: PartialOrd>(
&mut self,
actual: &dyn Fn() -> T,
expected: T
) -> &mut Unit
pub fn superior<T: PartialOrd>( &mut self, actual: &dyn Fn() -> T, expected: T ) -> &mut Unit
Check if the actual value is superior to the expected value
actualThe actual value to checkexpectedThe superior’s value expected for the actual value
use unit::zuu::Unit;
fn get_fans()->i32
{
return 5000;
}
Unit::new("We have how many of fans").superior(&get_fans,500).end().expect("panic message");sourcepub fn inferior<T: PartialOrd>(
&mut self,
actual: &dyn Fn() -> T,
expected: T
) -> &mut Unit
pub fn inferior<T: PartialOrd>( &mut self, actual: &dyn Fn() -> T, expected: T ) -> &mut Unit
Check if the actual value is inferior to the expected value
actualThe pointer to the functionexpectedThe inferior’s value for the actual value
use unit::zuu::Unit;
fn log_size()-> i32
{
return 410;
}
Unit::new("Server log more full ?").inferior(&log_size,500).end().expect("panic message");sourcepub fn between<T: PartialOrd>(
&mut self,
actual: &dyn Fn() -> T,
min: T,
max: T
) -> &mut Unit
pub fn between<T: PartialOrd>( &mut self, actual: &dyn Fn() -> T, min: T, max: T ) -> &mut Unit
Test if actual is between the min and the max value
actualThe function pointer to the function to checkminThe minimum valuemaxThe maximum value
use unit::zuu::Unit;
fn h()-> i32
{
return 5*5;
}
Unit::new("test if a number is between 0 and 100").between(&h,24,26).end().expect("panic message");