aboutsummaryrefslogtreecommitdiff
path: root/tests/image.rs
blob: 2006a3bb9710a36105cd348f5992dee14d7e9606 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use obi::Image;

#[test]
fn image_indexing() {
    let (width, height) = (30, 50);
    let img = Image::new(width, height);
    for x in 0..width {
        for y in 0..height {
            assert_eq!((y * width + x) as usize, img.index(x, y).unwrap());
        }
    }
}

#[test]
#[should_panic]
fn x_value_out_of_bounds() {
    let img = Image::new(30, 50);
    img.index(30, 0).unwrap();
}

#[test]
#[should_panic]
fn y_value_out_of_bounds() {
    let img = Image::new(30, 50);
    img.index(0, 50).unwrap();
}

#[test]
fn pixel_setter_and_getters() {
    let mut img = Image::new(100, 200);
    img.set(2, 3, true).unwrap();
    assert!(img.get(2, 3).unwrap());
    assert_eq!(1, img.data.iter().filter(|&&x| x).count());
}

#[test]
fn flip_bits() {
    let (width, height) = (100, 200);
    let mut img = Image::new(width, height);
    img.set(2, 3, true).expect("Indexing error");
    for i in 0..width {
        for j in 0..height {
            img.flip(i, j).unwrap();
        }
    }
    let mut expected = Image::new_with(width, height, true);
    expected.set(2, 3, false).expect("Indexing error");
    assert_eq!(expected.data, img.data);
}