To run unit test for your rust applications
sh
cargo add unit-testing
```rust
mod tests { use crate::zuu::Unit;
fn kool() -> bool
{
return false;
}
fn look() -> bool
{
return true;
}
fn f() -> i32
{
return 1;
}
fn theorem() -> bool
{
return 4 * 4 + 3 * 3 == 5 * 5;
}
fn s() -> i32
{
return 0;
}
fn status(u: Unit) -> Unit
{
return u.failure(&f).success(&s).expect(kool(), false).expect(look(),true).expect(f(),1).expect(s(),0);
}
fn diff(u: Unit) -> Unit
{
return u.unequals(&f, 2).different("a", "b").expect("a", "a");
}
fn files(u: Unit) -> Unit
{
return u.exist(".") ;
}
fn numbers(u: Unit) -> Unit
{
return u.equals(&s, 0).equals(&f, 1).unequals(&f, 2).between(&s, -1, 10).superior(&f, 0).inferior(&f, 10).expect(5,5);
}
fn test_string(u: Unit) -> Unit
{
let phrase = "The humanity develop the linux kernel.";
return u.empty("").not_empty(" ").identical(phrase, "The humanity develop the linux kernel.").contains(phrase, "linux").begin(&phrase, "The").finnish(phrase, "kernel.");
}
fn boolean(u: Unit) -> Unit
{
return u.ok(&look).ko(&kool);
}
#[test]
fn it_works() {
assert!(Unit::new("Test the unit framework")
.describe("Test all boolean", &boolean)
.describe("Test numbers", &numbers)
.describe("Test success and failure", &status)
.describe("Test differences", &diff)
.describe("Test string", &test_string)
.describe("Test files", &files)
.theory("Test pythagore", &theorem, true)
.end().is_ok());
}
} ```
shell
cargo run