Skip to content

Commit

Permalink
Add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lusingander committed Sep 4, 2024
1 parent 7fc5e14 commit 71fce8b
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ pub struct Color {
}

impl Color {
fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
pub fn from_rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
Self { r, g, b, a }
}

fn from_rgb(r: u8, g: u8, b: u8) -> Self {
pub fn from_rgb(r: u8, g: u8, b: u8) -> Self {
Self::from_rgba(r, g, b, 255)
}

Expand Down
72 changes: 72 additions & 0 deletions src/graph/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ mod tests {

use image::GenericImage;

use crate::color::Color;

use super::*;
use EdgeType::*;

Expand Down Expand Up @@ -680,6 +682,52 @@ mod tests {
test_calc_graph_row_image(params, cell_count, image_params, drawing_pixels, file_name);
}

#[test]
fn test_calc_graph_row_image_circle_radius() {
let params = straight_test_params();
let cell_count = 2;
let color_set = ColorSet::default();
let mut image_params = ImageParams::new(&color_set);
image_params.circle_inner_radius = 5;
image_params.circle_outer_radius = 12;
let drawing_pixels = DrawingPixels::new(&image_params);
let file_name = "circle_radius";

test_calc_graph_row_image(params, cell_count, image_params, drawing_pixels, file_name);
}

#[test]
fn test_calc_graph_row_image_line_width() {
let params = straight_test_params();
let cell_count = 2;
let color_set = ColorSet::default();
let mut image_params = ImageParams::new(&color_set);
image_params.line_width = 1;
let drawing_pixels = DrawingPixels::new(&image_params);
let file_name = "line_width";

test_calc_graph_row_image(params, cell_count, image_params, drawing_pixels, file_name);
}

#[test]
fn test_calc_graph_row_image_color() {
let params = branches_test_params();
let cell_count = 7;
let color_set = ColorSet {
colors: vec![
Color::from_rgb(200, 200, 100),
Color::from_rgb(100, 200, 200),
Color::from_rgb(100, 100, 100),
Color::from_rgb(200, 100, 200),
],
};
let image_params = ImageParams::new(&color_set);
let drawing_pixels = DrawingPixels::new(&image_params);
let file_name = "color";

test_calc_graph_row_image(params, cell_count, image_params, drawing_pixels, file_name);
}

#[rustfmt::skip]
fn simple_test_params() -> Vec<TestParam> {
vec![
Expand All @@ -689,6 +737,30 @@ mod tests {
]
}

#[rustfmt::skip]
fn straight_test_params() -> Vec<TestParam> {
vec![
(0, vec![(Up, 0, 0), (Down, 0, 0)]),
(0, vec![(Up, 0, 0), (Down, 0, 0), (Right, 0, 1), (RightBottom, 1, 1)]),
(1, vec![(Vertical, 0, 0), (Up, 1, 1), (Down, 1, 1)]),
(0, vec![(Up, 0, 0), (Down, 0, 0), (Right, 0, 1), (RightTop, 1, 1)]),
]
}

#[rustfmt::skip]
fn branches_test_params() -> Vec<TestParam> {
vec![
(0, vec![(Up, 0, 0), (Down, 0, 0),
(Right, 0, 1), (RightBottom, 1, 1),
(Right, 0, 2), (Horizontal, 1, 2), (RightBottom, 2, 2),
(Right, 0, 3), (Horizontal, 1, 3), (Horizontal, 2, 3), (RightBottom, 3, 3),
(Right, 0, 4), (Horizontal, 1, 4), (Horizontal, 2, 4), (Horizontal, 3, 4), (RightBottom, 4, 4),
(Right, 0, 5), (Horizontal, 1, 5), (Horizontal, 2, 5), (Horizontal, 3, 5), (Horizontal, 4, 5), (RightBottom, 5, 5),
(Right, 0, 6), (Horizontal, 1, 6), (Horizontal, 2, 6), (Horizontal, 3, 6), (Horizontal, 4, 6), (Horizontal, 5, 6), (RightBottom, 6, 6)]),
(6, vec![(Vertical, 0, 0), (Vertical, 1, 1), (Vertical, 2, 2), (Vertical, 3, 3), (Vertical, 4, 4), (Vertical, 5, 5), (Down, 6, 6), (Up, 6, 6)]),
]
}

fn test_calc_graph_row_image(
params: Vec<TestParam>,
cell_count: usize,
Expand Down

0 comments on commit 71fce8b

Please sign in to comment.