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