Struct unit::Unit

source ·
pub struct Unit { /* private fields */ }
Expand description

Unit

Implementations§

source§

impl Unit

source

pub fn new(description: &str) -> Unit

Unit Constructor

use unit::Unit;
Unit::new("Test description here");
source

pub fn check(self, tdd: bool) -> Unit

Run a test

use unit::Unit;
Unit::new("pythagore").check( 3*3 + 4*4 == 5*5).end();
source

pub fn ok(self, actual: bool) -> Unit

Check if actual match true

use std::env;
use unit::Unit;
Unit::new("Check if it's a linux pc").ok(env::consts::OS == "linux").end();
source

pub fn ko(self, actual: bool) -> Unit

Check if actual match false

use std::env;
use unit::Unit;
Unit::new("Check if it's a windows pc").ko(env::consts::OS == "windows").end();
source

pub fn equals(self, actual: &dyn Fn() -> i32, expected: i32) -> Unit

Check if two numbers are equals

use unit::Unit;
fn hypot()-> i32
{
    return 5*5;
}
Unit::new("Verify the multiplication of the number 5 by 5").equals(&hypot,25).end();
source

pub fn unequals(self, actual: &dyn Fn() -> i32, expected: i32) -> Unit

Check if two numbers are unequals


use unit::Unit;
/// Access model simplified
fn get_age()-> i32
{
    return 30;
}
Unit::new("The age it's not equals to 200 years").unequals(&get_age,200);
source

pub fn identical(self, actual: &String, expected: &str) -> Unit

Check if two strings are equals

use unit::Unit;
let admin = String::from("taishingi");
Unit::new("Check if the admin username is correct").identical(&admin,"taishingi").end();
source

pub fn empty(self, actual: &str) -> Unit

Check if the actual value is empty

use unit::Unit;
let users:[&str;3] = ["","nautilus","power"];
Unit::new("Check if user password is empty").empty(users[0]).end();
source

pub fn not_empty(self, actual: &str) -> Unit

Check if the actual value 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();
source

pub fn different(self, actual: &str, expected: &str) -> Unit

Check if two strings are unequals

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();
source

pub fn begin(self, actual: &String, expected: &str) -> Unit

Check if a string start with the expected value

use unit::Unit;
Unit::new("Check the beginning of a phrase").begin(&String::from("A superb woman"), "A").end();
source

pub fn finnish(self, actual: &String, expected: &str) -> Unit

Check if the string finnish wish the expected value

use unit::Unit;
Unit::new("Check the end of a phrase").finnish(&String::from("A superb woman who loves listen musics"), "musics").end();
source

pub fn success(self, f: &dyn Fn() -> i32) -> Unit

Check if the callback f return 0

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();
source

pub fn failure(self, f: &dyn Fn() -> i32) -> Unit

Check if the callback f return 1

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();
source

pub fn theory( self, description: &str, f: &dyn Fn() -> bool, expected: bool ) -> Unit

Check a theory

use unit::Unit;
fn matrix()->bool
{
    return false;
}
Unit::new("We are in the matrices ?").theory("All are real ?",&matrix,false);
source

pub fn describe(self, description: &str, f: &dyn Fn(Unit) -> Unit) -> Unit

Group a test case

use unit::Unit;
fn rectangle(u: Unit)-> Unit
{
    return u.ok(25 == 3*3+4*4);
}
Unit::new("Test the pythagore theorem").describe("The triangle must be rectangle",&rectangle).end();
source

pub fn defined(self, actual: &String) -> Unit

Check is the string is defined (not empty)

use unit::Unit;
let x = Unit::new("a");
let s = String::from("Cleopatra love cesar");
Unit::new("The string is empty ?").defined(&s).end();
source

pub fn exist(self, actual: &str) -> Unit

Check if the actual path exist

use unit::Unit;
Unit::new("Check if the directory exist").exist("/home").end();
source

pub fn not_equal(self, actual: &String, expected: &str) -> Unit

Check if the actual string is not equal to expected

use unit::Unit;
let password = "1234";
let bad_password = String::from("0000");
Unit::new("Check if password don't match 0000").not_equal(&bad_password,password).end();
source

pub fn expect(self, actual: &String, expected: &str) -> Unit

Check if actual string is equal to expected

use unit::Unit;
let expected = "lxpxd";
let pass= String::from("lxpxd");
Unit::new("I've founded the password ?").expect(&pass,expected).end();
source

pub fn expect_number(self, actual: usize, expected: usize) -> Unit

Check if actual is equal to expected

use unit::Unit;
Unit::new("birthday month...").expect_number(02,02).end();
source

pub fn find(self, actual: &String, expected: &str) -> Unit

Check if expected is find in actual string

use unit::Unit;
let poem = String::from("Habibi i love you forever");
Unit::new("Check if forever exist in the poem").find(&poem,"forever").end();
source

pub fn not_find(self, actual: &String, expected: &str) -> Unit

Check if expected value is not find in the actual string

use unit::Unit;
let poem = String::from("Habibi i love you forever");
Unit::new("Check if habibi not exist in the poem").not_find(&poem,"habibi").end();
source

pub fn ascii(self, actual: String) -> Unit

Check if expected value is not find in the actual string

source

pub fn contains(self, actual: &String, expected: &str) -> Unit

Check if a string contains a string

use unit::Unit;
let x = String::from("500000 pieces d'or");
Unit::new("Check if a coffer is there").contains(&x,"or").end();
source

pub fn superior(self, actual: &dyn Fn() -> i32, expected: i32) -> Unit

Check if the actual value is superior to the expected value

use unit::Unit;
fn get_fans()->i32
{
    return 5000;
}
Unit::new("We have how many of fans").superior(&get_fans,500).end();
source

pub fn inferior(self, actual: &dyn Fn() -> i32, expected: i32) -> Unit

Check if the actual value is inferior to the expected value

use unit::Unit;
fn server_ban()-> i32
{
    return 410;
}
Unit::new("Server log more full ?").inferior(&server_ban,500).end();
source

pub fn between(self, actual: &dyn Fn() -> i32, min: i32, max: i32) -> Unit

Test if actual is between the min and the max 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();
source

pub fn end(self) -> i32

End of the tests

use unit::Unit;
Unit::new("The superb description").ok(true).end();

Auto Trait Implementations§

§

impl !RefUnwindSafe for Unit

§

impl Send for Unit

§

impl !Sync for Unit

§

impl Unpin for Unit

§

impl UnwindSafe for Unit

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.