#![cfg(test)]
use assert_rs::*;
#[test]
fn is_sorted() -> impl Assertion {
multi_assert!(
assert_that!([1, 2, 2, 9].as_slice()).is_sorted(),
assert_that!([0].as_slice()).is_sorted(),
assert_that!([].as_slice()).is_sorted(),
)
}
#[test]
fn isnt_sorted() -> impl Assertion {
multi_assert!(#[dyn]
assert_that!([1, 3, 2, 4].as_slice())
.is_sorted()
.should_fail(),
assert_that!([0.0, 1.0, f32::NAN].as_slice())
.is_sorted()
.should_fail()
)
}
#[test]
fn is_not_sorted() -> impl Assertion {
multi_assert!(#[dyn]
assert_that!([1, 3, 2, 4].as_slice()).is_not_sorted(),
assert_that!([0.0, 1.0, f32::NAN].as_slice()).is_not_sorted()
)
}
#[test]
fn isnt_not_sorted() -> impl Assertion {
multi_assert!(
assert_that!([1, 2, 2, 9].as_slice())
.is_not_sorted()
.should_fail(),
assert_that!([0].as_slice()).is_not_sorted().should_fail(),
assert_that!([].as_slice()).is_not_sorted().should_fail(),
)
}
#[test]
fn is_sorted_by() -> impl Assertion {
assert_that!([1, 2, 2, 9].as_slice()).is_sorted_by(|a, b| a <= b)
}
#[test]
fn isnt_sorted_by() -> impl Assertion {
assert_that!([1, 2, 2, 9].as_slice())
.is_sorted_by(|a, b| a < b)
.should_fail()
}
#[test]
fn is_not_sorted_by() -> impl Assertion {
assert_that!([1, 2, 1, 9].as_slice()).is_not_sorted_by(|a, b| a <= b)
}
#[test]
fn isnt_not_sorted_by() -> impl Assertion {
assert_that!([1, 2, 2, 9].as_slice())
.is_not_sorted_by(|a, b| a <= b)
.should_fail()
}
#[test]
fn is_sorted_by_key() -> impl Assertion {
assert_that!(["c", "bb", "aaa"].as_slice()).is_sorted_by_key(|s| s.len())
}
#[test]
fn isnt_sorted_by_key() -> impl Assertion {
assert_that!([-2_i32, -1, 0, 3].as_slice())
.is_sorted_by_key(|s| s.abs())
.should_fail()
}
#[test]
fn is_not_sorted_by_key() -> impl Assertion {
assert_that!([-2_i32, -1, 0, 3].as_slice()).is_not_sorted_by_key(|s| s.abs())
}
#[test]
fn isnt_not_sorted_by_key() -> impl Assertion {
assert_that!(["c", "bb", "aaa"].as_slice())
.is_not_sorted_by_key(|s| s.len())
.should_fail()
}
#[test]
fn is_empty() -> impl Assertion {
let s: &[i32] = &[];
assert_that!(s).is_empty()
}
#[test]
fn isnt_empty() -> impl Assertion {
let s: &[i32] = &[1, 2, 3];
assert_that!(s).is_empty().should_fail()
}
#[test]
fn is_not_empty() -> impl Assertion {
let s: &[i32] = &[1, 2, 3];
assert_that!(s).is_not_empty()
}
#[test]
fn isnt_not_empty() -> impl Assertion {
let s: &[i32] = &[];
assert_that!(s).is_not_empty().should_fail()
}
#[test]
fn is_len() -> impl Assertion {
let s: &[i32] = &[1, 2, 3];
assert_that!(s).is_len(3)
}
#[test]
fn isnt_len() -> impl Assertion {
let s: &[i32] = &[4, 5];
assert_that!(s).is_len(3).should_fail()
}
#[test]
fn is_not_len() -> impl Assertion {
let s: &[i32] = &[6, 7, 8, 9];
assert_that!(s).is_not_len(10)
}
#[test]
fn isnt_not_len() -> impl Assertion {
let s: &[i32] = &[11, 12];
assert_that!(s).is_not_len(2).should_fail()
}
#[test]
fn contains() -> impl Assertion {
let s: &[i32] = &[6, 7, 8, 9];
assert_that!(s).contains(7)
}
#[test]
fn containsnt() -> impl Assertion {
let s: &[i32] = &[6, 7, 8, 9];
assert_that!(s).contains(10).should_fail()
}
#[test]
fn does_not_contain() -> impl Assertion {
let s: &[i32] = &[6, 7, 8, 9];
assert_that!(s).does_not_contain(4)
}
#[test]
fn doesnt_not_contain() -> impl Assertion {
let s: &[i32] = &[6, 7, 8, 9];
assert_that!(s).does_not_contain(9).should_fail()
}
#[test]
fn is_in() -> impl Assertion {
let s: &[i32] = &[6, 7, 8, 9];
assert_that!(8).is_in(s)
}
#[test]
fn isnt_in() -> impl Assertion {
let s: &[i32] = &[6, 7, 8, 9];
assert_that!(10).is_in(s).should_fail()
}
#[test]
fn is_not_in() -> impl Assertion {
let s: &[i32] = &[6, 7, 8, 9];
assert_that!(42).is_not_in(s)
}
#[test]
fn isnt_not_in() -> impl Assertion {
let s: &[i32] = &[6, 7, 8, 9];
assert_that!(6).is_not_in(s).should_fail()
}