aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/image.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/image.rs b/tests/image.rs
new file mode 100644
index 0000000..2006a3b
--- /dev/null
+++ b/tests/image.rs
@@ -0,0 +1,49 @@
1use obi::Image;
2
3#[test]
4fn image_indexing() {
5 let (width, height) = (30, 50);
6 let img = Image::new(width, height);
7 for x in 0..width {
8 for y in 0..height {
9 assert_eq!((y * width + x) as usize, img.index(x, y).unwrap());
10 }
11 }
12}
13
14#[test]
15#[should_panic]
16fn x_value_out_of_bounds() {
17 let img = Image::new(30, 50);
18 img.index(30, 0).unwrap();
19}
20
21#[test]
22#[should_panic]
23fn y_value_out_of_bounds() {
24 let img = Image::new(30, 50);
25 img.index(0, 50).unwrap();
26}
27
28#[test]
29fn pixel_setter_and_getters() {
30 let mut img = Image::new(100, 200);
31 img.set(2, 3, true).unwrap();
32 assert!(img.get(2, 3).unwrap());
33 assert_eq!(1, img.data.iter().filter(|&&x| x).count());
34}
35
36#[test]
37fn flip_bits() {
38 let (width, height) = (100, 200);
39 let mut img = Image::new(width, height);
40 img.set(2, 3, true).expect("Indexing error");
41 for i in 0..width {
42 for j in 0..height {
43 img.flip(i, j).unwrap();
44 }
45 }
46 let mut expected = Image::new_with(width, height, true);
47 expected.set(2, 3, false).expect("Indexing error");
48 assert_eq!(expected.data, img.data);
49}