fix(try_from_into): rewrite tests (#392)

This commit is contained in:
IkaR49 2020-05-15 19:39:04 +03:00 committed by GitHub
parent 0b224b7bc6
commit 7f477d173a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -67,11 +67,16 @@ mod tests {
#[test] #[test]
#[should_panic] #[should_panic]
fn test_bad_tuple() { fn test_tuple_out_of_range_positive() {
let _: Color = Color::try_from((-1, 0, 0)).unwrap(); let _ = Color::try_from((256, 1000, 10000)).unwrap();
} }
#[test] #[test]
fn test_good_tuple() { #[should_panic]
fn test_tuple_out_of_range_negative() {
let _ = Color::try_from((-1, -10, -256)).unwrap();
}
#[test]
fn test_tuple_correct() {
let c: Color = (183, 65, 14).try_into().unwrap(); let c: Color = (183, 65, 14).try_into().unwrap();
assert_eq!(c.red, 183); assert_eq!(c.red, 183);
assert_eq!(c.green, 65); assert_eq!(c.green, 65);
@ -80,13 +85,17 @@ mod tests {
#[test] #[test]
#[should_panic] #[should_panic]
fn test_bad_array() { fn test_array_out_of_range_positive() {
let _: Color = [0, -1, 0].try_into().unwrap(); let _: Color = [1000, 10000, 256].try_into().unwrap();
} }
#[test] #[test]
fn test_good_array() { #[should_panic]
fn test_array_out_of_range_negative() {
let _: Color = [-10, -256, -1].try_into().unwrap();
}
#[test]
fn test_array_correct() {
let c: Color = [183, 65, 14].try_into().unwrap(); let c: Color = [183, 65, 14].try_into().unwrap();
assert_eq!(c.red, 183); assert_eq!(c.red, 183);
assert_eq!(c.green, 65); assert_eq!(c.green, 65);
assert_eq!(c.blue, 14); assert_eq!(c.blue, 14);
@ -94,22 +103,27 @@ mod tests {
#[test] #[test]
#[should_panic] #[should_panic]
fn test_bad_slice() { fn test_slice_out_of_range_positive() {
let arr = [0, 0, -1]; let arr = [10000, 256, 1000];
let _ = Color::try_from(&arr[..]).unwrap(); let _ = Color::try_from(&arr[..]).unwrap();
} }
#[test] #[test]
fn test_good_slice() { #[should_panic]
fn test_slice_out_of_range_negative() {
let arr = [-256, -1, -10];
let _ = Color::try_from(&arr[..]).unwrap();
}
#[test]
fn test_slice_correct() {
let v = vec![183, 65, 14]; let v = vec![183, 65, 14];
let c = Color::try_from(&v[..]).unwrap(); let c = Color::try_from(&v[..]).unwrap();
assert_eq!(c.red, 183); assert_eq!(c.red, 183);
assert_eq!(c.green, 65); assert_eq!(c.green, 65);
assert_eq!(c.blue, 14); assert_eq!(c.blue, 14);
} }
#[test] #[test]
#[should_panic] #[should_panic]
fn test_bad_slice_length() { fn test_slice_excess_length() {
let v = vec![0, 0, 0, 0]; let v = vec![0, 0, 0, 0];
let _ = Color::try_from(&v[..]).unwrap(); let _ = Color::try_from(&v[..]).unwrap();
} }