Skip to content

Commit

Permalink
Use new color testing code for grid test
Browse files Browse the repository at this point in the history
  • Loading branch information
lcallarec committed Jan 23, 2024
1 parent a59ed3f commit 076d1ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
1 change: 1 addition & 0 deletions tests/fakes.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ LiveChart.Config create_config(TestContext context = create_context()) {
var config = new LiveChart.Config();
config.width = context.surface.get_width();
config.height = context.surface.get_height();

config.padding = { 0, 0, 0, 0 };

return config;
Expand Down
23 changes: 7 additions & 16 deletions tests/grid.vala
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@

private void register_grid() {

Test.add_func("/LiveChart/Grid#should_generate_padding_when_y_axis_has_not_unit", () => {
Test.add_func("/Grid/should_generate_padding_when_y_axis_has_not_unit", () => {
//given
var WIDTH = 100;
var HEIGHT = 100;

var red = Gdk.RGBA() { red = 1f, green = 0f, blue = 0f, alpha = 1f };

var context = create_context(WIDTH, HEIGHT);
context.set_background_color(red);

var config = new LiveChart.Config();
config.y_axis.update_bounds(10);
config.height = HEIGHT;
config.width = WIDTH;
config.configure(context.ctx, null);

var grid = new LiveChart.Grid();
var background = new LiveChart.Background();
background.color = { 1f, 0f, 0f, 1f };
background.draw(context.ctx, config);

//when
grid.draw(context.ctx, config);

//then
var pixbuff = Gdk.pixbuf_get_from_surface(context.surface, 0, 0, WIDTH, HEIGHT);
screenshot(context);

//then
//Colors between left side and first pixels of "0" char on y-axis
var padding_colors = colors_at(pixbuff, WIDTH, HEIGHT)(0, 80, 10, 80);
assert(padding_colors.size == 11);
foreach (var color in padding_colors) {
assert(color.red == 1.0);
assert(color.green == 0);
assert(color.blue == 0);
assert(color.alpha == 1);
}
assert(has_only_one_color_in_rectangle(context, 0, 80, 10, 80)(red));
});
}

0 comments on commit 076d1ab

Please sign in to comment.