diff --git a/tests/chart.vala b/tests/chart.vala index 2feca7e..bf5bb8f 100644 --- a/tests/chart.vala +++ b/tests/chart.vala @@ -1,236 +1,235 @@ -private void register_chart() { - - Test.add_func("/Chart/serie/add_value#should_update_bounds_when_adding_a_value", () => { +private void register_chart () { + Test.add_func ("/Chart/serie/add_value#should_update_bounds_when_adding_a_value", () => { //given - var chart = new LiveChart.Chart(); - var serie = new LiveChart.Serie("TEST"); - - chart.add_serie(serie); - + var chart = new LiveChart.Chart (); + var serie = new LiveChart.Serie ("TEST"); + + chart.add_serie (serie); + //when //then - assert_false(chart.config.y_axis.get_bounds().has_upper()); + assert_false (chart.config.y_axis.get_bounds ().has_upper ()); //when - serie.add(100.0); + serie.add (100.0); //then - assert(chart.config.y_axis.get_bounds().upper == 100.0); + assert (chart.config.y_axis.get_bounds ().upper == 100.0); }); //Deprecated - Test.add_func("/Chart/add_value#should_update_bounds_when_adding_a_value", () => { + Test.add_func ("/Chart/add_value#should_update_bounds_when_adding_a_value", () => { //given - var chart = new LiveChart.Chart(); - var serie = new LiveChart.Serie("TEST"); - - chart.add_serie(serie); - + var chart = new LiveChart.Chart (); + var serie = new LiveChart.Serie ("TEST"); + + chart.add_serie (serie); + //when //then - assert_false(chart.config.y_axis.get_bounds().has_upper()); + assert_false (chart.config.y_axis.get_bounds ().has_upper ()); //when - chart.add_value(serie, 100.0); + chart.add_value (serie, 100.0); //then - assert(chart.config.y_axis.get_bounds().upper == 100.0); + assert (chart.config.y_axis.get_bounds ().upper == 100.0); }); - Test.add_func("/Chart/export", () => { + Test.add_func ("/Chart/export", () => { //given - var chart = new LiveChart.Chart(); + var chart = new LiveChart.Chart (); var app = new Gtk.Application ("com.github.live-chart", GLib.ApplicationFlags.FLAGS_NONE); app.activate.connect (() => { - var view = new Gtk.ApplicationWindow(app); - view.set_child(chart); - view.present(); + var view = new Gtk.ApplicationWindow (app); + view.set_child (chart); + view.present (); }); - - Timeout.add(1, () => { - if(chart.is_started()) { + + Timeout.add (1, () => { + if (chart.is_started ()) { try { - chart.to_png("export.png"); + chart.to_png ("export.png"); } catch (Error e) { - assert_not_reached(); + assert_not_reached (); } finally { - app.quit(); + app.quit (); } //then - File file = File.new_for_path("export.png"); - assert(true == file.query_exists()); + File file = File.new_for_path ("export.png"); + assert (true == file.query_exists ()); } return true; }); - app.run(); + app.run (); }); - Test.add_func("/Chart/export_should_fails_when_not_realized", () => { + Test.add_func ("/Chart/export_should_fails_when_not_realized", () => { //given - var chart = new LiveChart.Chart(); + var chart = new LiveChart.Chart (); //when //then try { - chart.to_png("export.png"); - assert_not_reached(); + chart.to_png ("export.png"); + assert_not_reached (); } catch (Error e) { - assert(e is LiveChart.ChartError.EXPORT_ERROR); + assert (e is LiveChart.ChartError.EXPORT_ERROR); } }); - Test.add_func("/Chart/add_unaware_timestamp_collection", () => { + Test.add_func ("/Chart/add_unaware_timestamp_collection", () => { //given - var chart = new LiveChart.Chart(); + var chart = new LiveChart.Chart (); - var serie = new LiveChart.Serie("TEST"); + var serie = new LiveChart.Serie ("TEST"); - var unaware_timestamp_collection = new Gee.ArrayList(); - unaware_timestamp_collection.add(5); - unaware_timestamp_collection.add(10); - unaware_timestamp_collection.add(15); + var unaware_timestamp_collection = new Gee.ArrayList (); + unaware_timestamp_collection.add (5); + unaware_timestamp_collection.add (10); + unaware_timestamp_collection.add (15); var timespan_between_value = 5000; //when - var now = GLib.get_real_time() / chart.config.time.conv_us; - chart.add_unaware_timestamp_collection(serie, unaware_timestamp_collection, timespan_between_value); + var now = GLib.get_real_time () / chart.config.time.conv_us; + chart.add_unaware_timestamp_collection (serie, unaware_timestamp_collection, timespan_between_value); //then - assert(serie.get_values().size == 3); - assert(serie.get_values().get(0).value == 5); - assert(serie.get_values().get(1).value == 10); - assert(serie.get_values().get(2).value == 15); - assert(serie.get_values().get(2).timestamp == now); - assert(serie.get_values().get(1).timestamp == now - 5000); - assert(serie.get_values().get(0).timestamp == now - 10000); - - assert(chart.config.y_axis.get_bounds().lower == 5); - assert(chart.config.y_axis.get_bounds().upper == 15); + assert (serie.get_values ().size == 3); + assert (serie.get_values ().get (0).value == 5); + assert (serie.get_values ().get (1).value == 10); + assert (serie.get_values ().get (2).value == 15); + assert (serie.get_values ().get (2).timestamp == now); + assert (serie.get_values ().get (1).timestamp == now - 5000); + assert (serie.get_values ().get (0).timestamp == now - 10000); + + assert (chart.config.y_axis.get_bounds ().lower == 5); + assert (chart.config.y_axis.get_bounds ().upper == 15); }); - Test.add_func("/Chart/serie/add_value_by_index", () => { + Test.add_func ("/Chart/serie/add_value_by_index", () => { //given - var chart = new LiveChart.Chart(); - var serie = new LiveChart.Serie("TEST"); - - chart.add_serie(serie); - + var chart = new LiveChart.Chart (); + var serie = new LiveChart.Serie ("TEST"); + + chart.add_serie (serie); + //when try { - chart.series[0].add(100); + chart.series[0].add (100); } catch (LiveChart.ChartError e) { - assert_not_reached(); + assert_not_reached (); } //then - assert(serie.get_values().size == 1); - assert(serie.get_values().get(0).value == 100); + assert (serie.get_values ().size == 1); + assert (serie.get_values ().get (0).value == 100); }); //Deprecated - Test.add_func("/Chart/add_value_by_index", () => { + Test.add_func ("/Chart/add_value_by_index", () => { //given - var chart = new LiveChart.Chart(); - var serie = new LiveChart.Serie("TEST"); - - chart.add_serie(serie); - + var chart = new LiveChart.Chart (); + var serie = new LiveChart.Serie ("TEST"); + + chart.add_serie (serie); + //when try { - chart.add_value_by_index(0, 100); + chart.add_value_by_index (0, 100); } catch (LiveChart.ChartError e) { - assert_not_reached(); + assert_not_reached (); } //then - assert(serie.get_values().size == 1); - assert(serie.get_values().get(0).value == 100); + assert (serie.get_values ().size == 1); + assert (serie.get_values ().get (0).value == 100); }); - Test.add_func("/Chart/add_unaware_timestamp_collection_by_index", () => { + Test.add_func ("/Chart/add_unaware_timestamp_collection_by_index", () => { //given - var chart = new LiveChart.Chart(); - var serie = new LiveChart.Serie("TEST"); - - chart.add_serie(serie); - - var unaware_timestamp_collection = new Gee.ArrayList(); - unaware_timestamp_collection.add(5); - unaware_timestamp_collection.add(10); - unaware_timestamp_collection.add(15); + var chart = new LiveChart.Chart (); + var serie = new LiveChart.Serie ("TEST"); + + chart.add_serie (serie); + + var unaware_timestamp_collection = new Gee.ArrayList (); + unaware_timestamp_collection.add (5); + unaware_timestamp_collection.add (10); + unaware_timestamp_collection.add (15); var timespan_between_value = 5000; //when - var now = GLib.get_real_time() / chart.config.time.conv_us; + var now = GLib.get_real_time () / chart.config.time.conv_us; try { - chart.add_unaware_timestamp_collection_by_index(0, unaware_timestamp_collection, timespan_between_value); + chart.add_unaware_timestamp_collection_by_index (0, unaware_timestamp_collection, timespan_between_value); } catch (LiveChart.ChartError e) { - assert_not_reached(); + assert_not_reached (); } //then - assert(serie.get_values().size == 3); - assert(serie.get_values().get(0).value == 5); - assert(serie.get_values().get(1).value == 10); - assert(serie.get_values().get(2).value == 15); - assert(serie.get_values().get(2).timestamp == now); - assert(serie.get_values().get(1).timestamp == now - 5000); - assert(serie.get_values().get(0).timestamp == now - 10000); - - assert(chart.config.y_axis.get_bounds().lower == 5); - assert(chart.config.y_axis.get_bounds().upper == 15); - }); - - Test.add_func("/Chart/#ShouldNotCrashWhenRevealingAChartWithoutAnyValueAdded", () => { + assert (serie.get_values ().size == 3); + assert (serie.get_values ().get (0).value == 5); + assert (serie.get_values ().get (1).value == 10); + assert (serie.get_values ().get (2).value == 15); + assert (serie.get_values ().get (2).timestamp == now); + assert (serie.get_values ().get (1).timestamp == now - 5000); + assert (serie.get_values ().get (0).timestamp == now - 10000); + + assert (chart.config.y_axis.get_bounds ().lower == 5); + assert (chart.config.y_axis.get_bounds ().upper == 15); + }); + + Test.add_func ("/Chart/#ShouldNotCrashWhenRevealingAChartWithoutAnyValueAdded", () => { //given - var chart = new LiveChart.Chart(); - chart.add_serie(new LiveChart.Serie("Test")); - + var chart = new LiveChart.Chart (); + chart.add_serie (new LiveChart.Serie ("Test")); + //when //then - Timeout.add(1000, () => { + Timeout.add (1000, () => { //FIXME: Gtk.main_quit(); return false; }); //FIXME: Gtk.main(); }); - Test.add_func("/Chart/background#main_color_should_be_accessible_even_if_deprecated", () => { + Test.add_func ("/Chart/background#main_color_should_be_accessible_even_if_deprecated", () => { //given - var chart = new LiveChart.Chart(); + var chart = new LiveChart.Chart (); //when chart.background.main_color = { 1f, 1f, 1f, 1f }; - + //then //ok - + }); - - Test.add_func("/Chart/#destroy_chart_should_remove_all_series", () => { + + Test.add_func ("/Chart/#destroy_chart_should_remove_all_series", () => { //given - var chart = new LiveChart.Chart(); - chart.add_serie(new LiveChart.Serie("TEST")); + var chart = new LiveChart.Chart (); + chart.add_serie (new LiveChart.Serie ("TEST")); //when - chart.destroy(); - + chart.destroy (); + //then - assert(chart.series.size() == 0); + assert (chart.series.size () == 0); }); - Test.add_func("/Chart/#destroy_chart_should_stop_refresh", () => { + Test.add_func ("/Chart/#destroy_chart_should_stop_refresh", () => { //given - var chart = new LiveChart.Chart(); - chart.add_serie(new LiveChart.Serie("TEST")); + var chart = new LiveChart.Chart (); + chart.add_serie (new LiveChart.Serie ("TEST")); //when - chart.destroy(); - + chart.destroy (); + //then - assert(chart.refresh_rate == 0); + assert (chart.refresh_rate == 0); }); - + } diff --git a/tests/config.vala b/tests/config.vala index dfd8d46..d1ec2b4 100644 --- a/tests/config.vala +++ b/tests/config.vala @@ -1,60 +1,58 @@ - -private void register_config() { - - Test.add_func("/Config#boundaries", () => { +private void register_config () { + Test.add_func ("/Config#boundaries", () => { //given - var config = new LiveChart.Config(); + var config = new LiveChart.Config (); config.width = 100; config.height = 200; config.padding = { smart: LiveChart.AutoPadding.NONE, 20, 25, 10, 30 }; //when - var boundaries = config.boundaries(); - + var boundaries = config.boundaries (); + //then - assert(boundaries.x.min == 30); - assert(boundaries.x.max == 75); - assert(boundaries.y.min == 20); - assert(boundaries.y.max == 190); - assert(boundaries.width == 45); - assert(boundaries.height == 170); + assert (boundaries.x.min == 30); + assert (boundaries.x.max == 75); + assert (boundaries.y.min == 20); + assert (boundaries.y.max == 190); + assert (boundaries.width == 45); + assert (boundaries.height == 170); }); - Test.add_func("/Config#axis_text_extents_without_no_visible_labels", () => { + Test.add_func ("/Config#axis_text_extents_without_no_visible_labels", () => { //given - Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, SURFACE_WIDTH, SURFACE_HEIGHT); - Cairo.Context context = new Cairo.Context(surface); + Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, SURFACE_WIDTH, SURFACE_HEIGHT); + Cairo.Context context = new Cairo.Context (surface); - var config = new LiveChart.Config(); + var config = new LiveChart.Config (); config.y_axis.visible = false; - + //when - config.configure(context, null); - + config.configure (context, null); + //then - assert(config.y_axis.labels.extents.height == 0); - assert(config.y_axis.labels.extents.width == 0); - assert(config.y_axis.labels.extents.x_advance == 0); - assert(config.y_axis.labels.extents.x_bearing == 0); - assert(config.y_axis.labels.extents.y_advance == 0); - assert(config.y_axis.labels.extents.y_bearing == 0); + assert (config.y_axis.labels.extents.height == 0); + assert (config.y_axis.labels.extents.width == 0); + assert (config.y_axis.labels.extents.x_advance == 0); + assert (config.y_axis.labels.extents.x_bearing == 0); + assert (config.y_axis.labels.extents.y_advance == 0); + assert (config.y_axis.labels.extents.y_bearing == 0); }); - Test.add_func("/Config#should_compute_max_displayed_value", () => { + Test.add_func ("/Config#should_compute_max_displayed_value", () => { //given - Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 100, 100); - Cairo.Context context = new Cairo.Context(surface); + Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 100, 100); + Cairo.Context context = new Cairo.Context (surface); - var config = new LiveChart.Config(); - config.y_axis.update_bounds(95.0); + var config = new LiveChart.Config (); + config.y_axis.update_bounds (95.0); config.padding = { LiveChart.AutoPadding.NONE, 0, 0, 0, 0 }; config.height = 100; config.width = 100; - + //when - config.configure(context, null); + config.configure (context, null); //then - assert(config.y_axis.get_max_displayed_value() == "100"); + assert (config.y_axis.get_max_displayed_value () == "100"); }); -} \ No newline at end of file +} diff --git a/tests/fakes.vala b/tests/fakes.vala index b80ab16..5cc98cb 100644 --- a/tests/fakes.vala +++ b/tests/fakes.vala @@ -7,192 +7,200 @@ public class TestContext : Object { public Cairo.Context ctx { get; set; } public Cairo.ImageSurface surface { get; set; } - public TestContext(Cairo.Context ctx, Cairo.ImageSurface surface) { + public TestContext (Cairo.Context ctx, Cairo.ImageSurface surface) { this.ctx = ctx; this.surface = surface; } - public void set_background_color(Gdk.RGBA color) { - cairo_background(ctx, color, surface.get_width(), surface.get_height()); + public void set_background_color (Gdk.RGBA color) { + cairo_background (ctx, color, surface.get_width (), surface.get_height ()); } } -TestContext create_context(int width = SURFACE_WIDTH, int height = SURFACE_HEIGHT) { - Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, width, height); - Cairo.Context context = new Cairo.Context(surface); - context.set_antialias(Cairo.Antialias.NONE); - cairo_background(context, DEFAULT_BACKGROUND_COLOR, width, height); +TestContext create_context (int width = SURFACE_WIDTH, int height = SURFACE_HEIGHT) { + Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height); + Cairo.Context context = new Cairo.Context (surface); + context.set_antialias (Cairo.Antialias.NONE); + cairo_background (context, DEFAULT_BACKGROUND_COLOR, width, height); - var test_context = new TestContext(context, surface); + var test_context = new TestContext (context, surface); test_context.ctx = context; test_context.surface = surface; return test_context; } -void cairo_background(Cairo.Context ctx, Gdk.RGBA color, int width, int height) { - ctx.set_source_rgba(color.red, color.green, color.blue, color.alpha); - ctx.rectangle(-1, -1,width + 1, height + 1); - ctx.fill(); +void cairo_background (Cairo.Context ctx, Gdk.RGBA color, int width, int height) { + ctx.set_source_rgba (color.red, color.green, color.blue, color.alpha); + ctx.rectangle (-1, -1, width + 1, height + 1); + ctx.fill (); } -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(); +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; } -delegate Gee.HashSet IntFromToCoodinates(int from_x, int from_y, int to_x, int to_y); +delegate Gee.HashSet IntFromToCoodinates (int from_x, int from_y, int to_x, int to_y); -delegate bool HasOnlyOneColor(Gdk.RGBA color); +delegate bool HasOnlyOneColor (Gdk.RGBA color); + +HasOnlyOneColor has_only_one_color (TestContext context) { + + int width = context.surface.get_width (); + int height = context.surface.get_height (); -HasOnlyOneColor has_only_one_color(TestContext context) { - - int width = context.surface.get_width(); - int height = context.surface.get_height(); - return (color) => { - var colors = get_colors_in_rectangle(context, 0, 0, width - 1, height - 1); - return colors.all_match((c) => { - return c.equal(color); + var colors = get_colors_in_rectangle (context, 0, 0, width - 1, height - 1); + return colors.all_match ((c) => { + return c.equal (color); }); }; } -HasOnlyOneColor has_only_one_color_in_rectangle(TestContext context, int from_x, int from_y, int to_x, int to_y) { +HasOnlyOneColor has_only_one_color_in_rectangle (TestContext context, int from_x, int from_y, int to_x, int to_y) { return (color) => { - var colors = get_colors_in_rectangle(context, from_x, from_y, to_x, to_y); - return colors.all_match((c) => { - return c.equal(color); + var colors = get_colors_in_rectangle (context, from_x, from_y, to_x, to_y); + return colors.all_match ((c) => { + return c.equal (color); }); }; } -Gee.HashSet get_colors_in_rectangle(TestContext context, int from_x, int from_y, int to_x, int to_y) { - - int width = context.surface.get_width(); - int height = context.surface.get_height(); - - var pixbuff = Gdk.pixbuf_get_from_surface(context.surface, 0, 0, width, height); - assert(pixbuff != null); +Gee.HashSet get_colors_in_rectangle (TestContext context, int from_x, int from_y, int to_x, int to_y) { + + int width = context.surface.get_width (); + int height = context.surface.get_height (); + + var pixbuff = Gdk.pixbuf_get_from_surface (context.surface, 0, 0, width, height); + assert (pixbuff != null); - unowned uint8[] pixels = pixbuff.get_pixels(); - var channels = pixbuff.get_n_channels(); + unowned uint8[] pixels = pixbuff.get_pixels (); + var channels = pixbuff.get_n_channels (); var stride = pixbuff.rowstride; - var colors = new Gee.HashSet(); + var colors = new Gee.HashSet (); for (var x = from_x; x <= to_x; x++) { for (var y = from_y; y <= to_y; y++) { - var rgba = get_color_at_from_pixels(pixels, stride, channels)(x, y); - colors.add(rgba); + var rgba = get_color_at_from_pixels (pixels, stride, channels)(x, y); + colors.add (rgba); } } return colors; } -delegate bool HasOnlyOneColorAtRow(Gdk.RGBA color, int row); -HasOnlyOneColorAtRow has_only_one_color_at_row(TestContext context) { - - int width = context.surface.get_width(); - int height = context.surface.get_height(); - +delegate bool HasOnlyOneColorAtRow (Gdk.RGBA color, int row); +HasOnlyOneColorAtRow has_only_one_color_at_row (TestContext context) { + + int width = context.surface.get_width (); + int height = context.surface.get_height (); + return (color, row) => { - var pixbuff = Gdk.pixbuf_get_from_surface(context.surface, 0, 0, width - 1, height - 1); - assert(pixbuff != null); + var pixbuff = Gdk.pixbuf_get_from_surface (context.surface, 0, 0, width - 1, height - 1); + assert (pixbuff != null); - unowned uint8[] pixels = pixbuff.get_pixels(); - var channels = pixbuff.get_n_channels(); + unowned uint8[] pixels = pixbuff.get_pixels (); + var channels = pixbuff.get_n_channels (); var stride = pixbuff.rowstride; - var colors = new Gee.HashSet(); + var colors = new Gee.HashSet (); for (var x = 0; x < width - 1; x++) { - var rgba = get_color_at_from_pixels(pixels, stride, channels)(x, row); - colors.add(rgba); + var rgba = get_color_at_from_pixels (pixels, stride, channels)(x, row); + colors.add (rgba); } - return colors.all_match((c) => { - return c.equal(color); + return colors.all_match ((c) => { + return c.equal (color); }); }; } -delegate Gdk.RGBA GetColorAt(LiveChart.Coord coord); -GetColorAt get_color_at(TestContext context) { - - int width = context.surface.get_width(); - int height = context.surface.get_height(); - +delegate Gdk.RGBA GetColorAt (LiveChart.Coord coord); +GetColorAt get_color_at (TestContext context) { + + int width = context.surface.get_width (); + int height = context.surface.get_height (); + return (coord) => { - var pixbuff = Gdk.pixbuf_get_from_surface(context.surface, 0, 0, width, height); - assert(pixbuff != null); + var pixbuff = Gdk.pixbuf_get_from_surface (context.surface, 0, 0, width, height); + assert (pixbuff != null); - unowned uint8[] pixels = pixbuff.get_pixels(); - var channels = pixbuff.get_n_channels(); + unowned uint8[] pixels = pixbuff.get_pixels (); + var channels = pixbuff.get_n_channels (); var stride = pixbuff.rowstride; - return get_color_at_from_pixels(pixels, stride, channels)((int) coord.x, (int) coord.y); + return get_color_at_from_pixels (pixels, stride, channels)((int) coord.x, (int) coord.y); }; } -private delegate Gdk.RGBA ColorAtCoodinates(int x, int y); -private ColorAtCoodinates get_color_at_from_pixels(uint8[] pixels, int stride, int channels) { +private delegate Gdk.RGBA ColorAtCoodinates (int x, int y); +private ColorAtCoodinates get_color_at_from_pixels (uint8[] pixels, int stride, int channels) { return (x, y) => { var pos = (stride * y) + (channels * x); - + var r = pixels[pos]; var g = pixels[pos + 1]; var b = pixels[pos + 2]; var alpha = pixels[pos + 3]; - var c = color8_to_rgba(r, g, b, alpha); + var c = color8_to_rgba (r, g, b, alpha); - return flat(c); + return flat (c); }; } -public void screenshot(TestContext context, string suffix = "") { - int width = context.surface.get_width(); - int height = context.surface.get_height(); - - var pixbuff = Gdk.pixbuf_get_from_surface(context.surface, 0, 0, width, height); - var test_path = Test.get_path().replace("/", "____"); +public void screenshot (TestContext context, string suffix = "") { + int width = context.surface.get_width (); + int height = context.surface.get_height (); + + var pixbuff = Gdk.pixbuf_get_from_surface (context.surface, 0, 0, width, height); + var test_path = Test.get_path ().replace ("/", "____"); try { - pixbuff.save(@"screenshots/$(test_path).png", "png"); + pixbuff.save (@"screenshots/$(test_path).png", "png"); } catch (Error e) { - message(@"Screenshot error in $(test_path): $(e.message)"); + message (@"Screenshot error in $(test_path): $(e.message)"); } } -private Gdk.RGBA color8_to_rgba(uint8 red, uint8 green, uint8 blue, uint8 alpha) { - return flat({ (float) red / 255f, (float) green / 255f, (float) blue / 255.0f, (float) alpha / 255f }); +private Gdk.RGBA color8_to_rgba (uint8 red, uint8 green, uint8 blue, uint8 alpha) { + return flat ({ (float) red / 255f, (float) green / 255f, (float) blue / 255.0f, (float) alpha / 255f }); } -private Gdk.RGBA flat(Gdk.RGBA color) { - return { (float)Math.ceil(color.red * 100) / 100f, (float)Math.ceil(color.green * 100) / 100f, (float)Math.ceil(color.blue * 100) / 100f, 1f}; +private Gdk.RGBA flat (Gdk.RGBA color) { + return { + (float)Math.ceil (color.red * 100) / 100f, + (float)Math.ceil (color.green * 100) / 100f, + (float)Math.ceil (color.blue * 100) / 100f, + 1f + }; } public class PointBuilder { private double _x = 0; private double _y = 0; private double _height = 0; - private LiveChart.TimestampedValue _data = LiveChart.TimestampedValue() { + + private LiveChart.TimestampedValue _data = LiveChart.TimestampedValue () { timestamp = 0, value = 0 }; - public PointBuilder.from_value(double value) { + public PointBuilder.from_value (double value) { this._data.value = value; } - public PointBuilder x(double x) { + + public PointBuilder x (double x) { this._x = x; return this; } - public LiveChart.Point build() { + + public LiveChart.Point build () { return { x: this._x, y: this._y, @@ -200,5 +208,4 @@ public class PointBuilder { data: _data }; } - -} \ No newline at end of file +} diff --git a/tests/geometry.vala b/tests/geometry.vala index 6ba01db..b9fa48b 100644 --- a/tests/geometry.vala +++ b/tests/geometry.vala @@ -1,11 +1,11 @@ using LiveChart; -private void register_geometry() { - Test.add_func("/Geometry/find_intersection_between_two_segments/find_no_intersects_because_colinaear", () => { +private void register_geometry () { + Test.add_func ("/Geometry/find_intersection_between_two_segments/find_no_intersects_because_colinaear", () => { //given - var s1 = Segment() { + var s1 = Segment () { from = { - x: 0, + x: 0, y: 0 }, to = { @@ -14,9 +14,9 @@ private void register_geometry() { } }; - var s2 = Segment() { + var s2 = Segment () { from = { - x: 2, + x: 2, y: 2 }, to = { @@ -26,17 +26,17 @@ private void register_geometry() { }; //when - var coord = find_intersection_between_two_segments(s1, s2); - + var coord = find_intersection_between_two_segments (s1, s2); + //then - assert(coord == null); + assert (coord == null); }); - Test.add_func("/Geometry/find_intersection_between_two_segments/find_no_intersects_because_parallel", () => { + Test.add_func ("/Geometry/find_intersection_between_two_segments/find_no_intersects_because_parallel", () => { //given - var s1 = Segment() { + var s1 = Segment () { from = { - x: 0, + x: 0, y: 0 }, to = { @@ -45,9 +45,9 @@ private void register_geometry() { } }; - var s2 = Segment() { + var s2 = Segment () { from = { - x: 5, + x: 5, y: 2 }, to = { @@ -57,17 +57,17 @@ private void register_geometry() { }; //when - var coord = find_intersection_between_two_segments(s1, s2); - + var coord = find_intersection_between_two_segments( s1, s2); + //then - assert(coord == null); + assert (coord == null); }); - Test.add_func("/Geometry/find_intersection_between_two_segments/find_intersects", () => { + Test.add_func ("/Geometry/find_intersection_between_two_segments/find_intersects", () => { //given - var s1 = Segment() { + var s1 = Segment () { from = { - x: 0, + x: 0, y: 0 }, to = { @@ -76,9 +76,9 @@ private void register_geometry() { } }; - var s2 = Segment() { + var s2 = Segment () { from = { - x: 0, + x: 0, y: 10 }, to = { @@ -88,9 +88,9 @@ private void register_geometry() { }; //when - var coord = find_intersection_between_two_segments(s1, s2); - + var coord = find_intersection_between_two_segments (s1, s2); + //then - assert(coord == Coord() { x = 5, y = 5 }); + assert (coord == Coord () { x = 5, y = 5 }); }); -} \ No newline at end of file +} diff --git a/tests/grid.vala b/tests/grid.vala index 180b190..3ba5d16 100644 --- a/tests/grid.vala +++ b/tests/grid.vala @@ -1,30 +1,27 @@ - -private void register_grid() { - - Test.add_func("/Grid/should_generate_padding_when_y_axis_has_not_unit", () => { +private void register_grid () { + 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 red = Gdk.RGBA () { red = 1f, green = 0f, blue = 0f, alpha = 1f }; - var context = create_context(WIDTH, HEIGHT); - context.set_background_color(red); + var context = create_context (WIDTH, HEIGHT); + context.set_background_color (red); - var config = new LiveChart.Config(); + var config = new LiveChart.Config (); config.height = HEIGHT; config.width = WIDTH; - config.configure(context.ctx, null); - - var grid = new LiveChart.Grid(); + config.configure (context.ctx, null); + + var grid = new LiveChart.Grid (); //when - grid.draw(context.ctx, config); - screenshot(context); + grid.draw (context.ctx, config); + screenshot (context); //then //Colors between left side and first pixels of "0" char on y-axis - assert(has_only_one_color_in_rectangle(context, 0, 80, 10, 80)(red)); + assert (has_only_one_color_in_rectangle (context, 0, 80, 10, 80)(red)); }); } - diff --git a/tests/points.vala b/tests/points.vala index c866331..7c9e45b 100644 --- a/tests/points.vala +++ b/tests/points.vala @@ -1,44 +1,42 @@ - -private void register_points() { - - Test.add_func("/Points#Create", () => { +private void register_points () { + Test.add_func ("/Points#Create", () => { //given - var config = new LiveChart.Config(); + var config = new LiveChart.Config (); config.width = 100; config.height = 100; config.padding = { 0, 0, 0, 0 }; - var values = new LiveChart.Values(); - var now = GLib.get_real_time() / 1000; + var values = new LiveChart.Values (); + var now = GLib.get_real_time () / 1000; - values.add({now - 2, 1}); - values.add({now - 1, 10}); - values.add({now, 100}); + values.add ({now - 2, 1}); + values.add ({now - 1, 10}); + values.add ({now, 100}); //when - var points = LiveChart.Points.create(values, config); + var points = LiveChart.Points.create (values, config); //then - assert(points.size == values.size); - - var first_point = points.get(0); - assert((int) first_point.x == 99); - assert((int) first_point.y == 99); - assert((int) first_point.height == 1); - - var last_point = points.get(2); - stdout.printf("(int) last_point.x == 100 %f\n", last_point.x); - assert((int) last_point.x == 100); - assert((int) last_point.y == 0); - assert((int) last_point.height == 100); + assert (points.size == values.size); + + var first_point = points.get (0); + assert ((int) first_point.x == 99); + assert ((int) first_point.y == 99); + assert ((int) first_point.height == 1); + + var last_point = points.get (2); + stdout.printf ("(int) last_point.x == 100 %f\n", last_point.x); + assert ((int) last_point.x == 100); + assert ((int) last_point.y == 0); + assert ((int) last_point.height == 100); }); - Test.add_func("/Points#Create#ShouldntCrashOnEmptyValues", () => { + Test.add_func ("/Points#Create#ShouldntCrashOnEmptyValues", () => { //given - var config = new LiveChart.Config(); - var values = new LiveChart.Values(); + var config = new LiveChart.Config (); + var values = new LiveChart.Values (); //when //then - LiveChart.Points.create(values, config); - }); -} \ No newline at end of file + LiveChart.Points.create (values, config); + }); +} diff --git a/tests/runner.vala b/tests/runner.vala index e373804..db8c4d5 100644 --- a/tests/runner.vala +++ b/tests/runner.vala @@ -1,52 +1,51 @@ void main (string[] args) { + Test.init (ref args); + Gtk.init (); - Test.init(ref args); - Gtk.init(); + prepare_screenshots_directory (); - prepare_screenshots_directory(); + register_config (); + register_bounds (); + register_values (); + register_points (); + register_chart (); + register_axis (); + register_area (); + register_line_area (); + register_line (); + register_smooth_line (); + register_smooth_line_area (); + register_bar (); + register_utils (); + register_geometry (); + register_grid (); + register_background (); + register_legend (); + register_serie (); + register_series (); + register_threshold_line (); + register_min_bound_line (); + register_max_bound_line (); + register_regions_curve_resolver (); + register_bezier_intersector (); + register_segment_interector (); - register_config(); - register_bounds(); - register_values(); - register_points(); - register_chart(); - register_axis(); - register_area(); - register_line_area(); - register_line(); - register_smooth_line(); - register_smooth_line_area(); - register_bar(); - register_utils(); - register_geometry(); - register_grid(); - register_background(); - register_legend(); - register_serie(); - register_series(); - register_threshold_line(); - register_min_bound_line(); - register_max_bound_line(); - register_regions_curve_resolver(); - register_bezier_intersector(); - register_segment_interector(); - - Test.run(); + Test.run (); } -private void prepare_screenshots_directory() { +private void prepare_screenshots_directory () { try { - var directory = File.new_for_path("screenshots"); - if(directory.query_exists()) { - Dir screenshot_dir = Dir.open("screenshots", 0); + var directory = File.new_for_path ("screenshots"); + if (directory.query_exists ()) { + Dir screenshot_dir = Dir.open ("screenshots", 0); string? name = null; while ((name = screenshot_dir.read_name ()) != null) { - File.new_for_path(@"screenshots/$(name)").delete(); + File.new_for_path (@"screenshots/$(name)").delete (); } - directory.delete(); + directory.delete (); } - directory.make_directory(); + directory.make_directory (); } catch (Error e) { - message(@"Error while preparing screenshots directory : $(e.message)"); + message (@"Error while preparing screenshots directory : $(e.message)"); } -} \ No newline at end of file +} diff --git a/tests/smooth_line.vala b/tests/smooth_line.vala index d001b5f..77ec663 100644 --- a/tests/smooth_line.vala +++ b/tests/smooth_line.vala @@ -1,71 +1,71 @@ -private void register_smooth_line() { - Test.add_func("/SmoothLine/should_not_render_if_no_values", () => { +private void register_smooth_line () { + Test.add_func ("/SmoothLine/should_not_render_if_no_values", () => { //Given - var context = create_context(); + var context = create_context (); - var values = new LiveChart.Values(); - - var line = new LiveChart.SmoothLine(values); - line.line.color = Gdk.RGBA() {red = 1.0f, green = 0.0f, blue = 0.0f, alpha = 1.0f }; + var values = new LiveChart.Values (); + + var line = new LiveChart.SmoothLine (values); + line.line.color = Gdk.RGBA () {red = 1.0f, green = 0.0f, blue = 0.0f, alpha = 1.0f }; //When - line.draw(context.ctx, create_config(context)); - screenshot(context); + line.draw (context.ctx, create_config (context)); + screenshot (context); //Then - assert(has_only_one_color(context)(DEFAULT_BACKGROUND_COLOR)); + assert (has_only_one_color (context)(DEFAULT_BACKGROUND_COLOR)); }); - Test.add_func("/SmoothLine/should_render_smooth_line", () => { + Test.add_func ("/SmoothLine/should_render_smooth_line", () => { //Given - var green = Gdk.RGBA() { red = 0.0f, green = 1.0f, blue = 0.0f, alpha = 1.0f }; + var green = Gdk.RGBA () { red = 0.0f, green = 1.0f, blue = 0.0f, alpha = 1.0f }; + + var context = create_context (43, 20); - var context = create_context(43, 20); + var values = new LiveChart.Values (); + values.add ({timestamp: (GLib.get_real_time () / 1000) - 7200, value: 5}); + values.add ({timestamp: (GLib.get_real_time () / 1000) - 3600, value: 20}); + values.add ({timestamp: (GLib.get_real_time () / 1000), value: 5}); - var values = new LiveChart.Values(); - values.add({timestamp: (GLib.get_real_time() / 1000) - 7200, value: 5}); - values.add({timestamp: (GLib.get_real_time() / 1000) - 3600, value: 20}); - values.add({timestamp: (GLib.get_real_time() / 1000), value: 5}); - - var line = new LiveChart.SmoothLine(values); + var line = new LiveChart.SmoothLine (values); line.line.color = green; //When - line.draw(context.ctx, create_config(context)); - screenshot(context); + line.draw (context.ctx, create_config (context)); + screenshot (context); //Then the curve colors are... - assert(get_color_at(context)({x: 0, y: 14}) == green); - assert(get_color_at(context)({x: 22, y: 0}) == green); - assert(get_color_at(context)({x: 42, y: 14}) == green); + assert( get_color_at (context)({x: 0, y: 14}) == green); + assert (get_color_at (context)({x: 22, y: 0}) == green); + assert (get_color_at (context)({x: 42, y: 14}) == green); //And below the curve, color is... - assert(get_color_at(context)({x: 22, y: 7}) == DEFAULT_BACKGROUND_COLOR); + assert (get_color_at (context)({x: 22, y: 7}) == DEFAULT_BACKGROUND_COLOR); }); - Test.add_func("/SmoothLine/should_render_smooth_line_with_region", () => { + Test.add_func ("/SmoothLine/should_render_smooth_line_with_region", () => { //Given - var red = Gdk.RGBA() { red = 1.0f, green = 0.0f, blue = 0.0f, alpha = 1.0f }; - var green = Gdk.RGBA() { red = 0.0f, green = 1.0f, blue = 0.0f, alpha = 1.0f }; + var red = Gdk.RGBA () { red = 1.0f, green = 0.0f, blue = 0.0f, alpha = 1.0f }; + var green = Gdk.RGBA () { red = 0.0f, green = 1.0f, blue = 0.0f, alpha = 1.0f }; + + var context = create_context (43, 20); - var context = create_context(43, 20); + var values = new LiveChart.Values (); + values.add ({timestamp: (GLib.get_real_time () / 1000) - 7200, value: 5}); + values.add ({timestamp: (GLib.get_real_time () / 1000) - 3600, value: 20}); + values.add ({timestamp: (GLib.get_real_time () / 1000), value: 5}); - var values = new LiveChart.Values(); - values.add({timestamp: (GLib.get_real_time() / 1000) - 7200, value: 5}); - values.add({timestamp: (GLib.get_real_time() / 1000) - 3600, value: 20}); - values.add({timestamp: (GLib.get_real_time() / 1000), value: 5}); - - var line = new LiveChart.SmoothLine(values); + var line = new LiveChart.SmoothLine (values); line.line.color = green; - line.region = new LiveChart.Region.between(10, 100).with_line_color(red); + line.region = new LiveChart.Region.between (10, 100).with_line_color (red); //When - line.draw(context.ctx, create_config(context)); - screenshot(context); + line.draw (context.ctx, create_config (context)); + screenshot (context); //Then the curve colors are... - assert(get_color_at(context)({x: 0, y: 14}) == green); - assert(get_color_at(context)({x: 22, y: 0}) == red); - assert(get_color_at(context)({x: 42, y: 14}) == green); + assert( get_color_at( context)({x: 0, y: 14}) == green); + assert (get_color_at (context)({x: 22, y: 0}) == red); + assert (get_color_at (context)({x: 42, y: 14}) == green); }); -} \ No newline at end of file +} diff --git a/tests/threshold_line.vala b/tests/threshold_line.vala index b291341..fbad1f8 100644 --- a/tests/threshold_line.vala +++ b/tests/threshold_line.vala @@ -1,24 +1,24 @@ -private void register_threshold_line() { - Test.add_func("/ThresholdLine", () => { +private void register_threshold_line () { + Test.add_func ("/ThresholdLine", () => { //Given - var red = Gdk.RGBA() {red = 1.0f, green = 0.0f, blue = 0.0f, alpha = 1.0f }; + var red = Gdk.RGBA () {red = 1.0f, green = 0.0f, blue = 0.0f, alpha = 1.0f }; - var context = create_context(SURFACE_WIDTH, SURFACE_HEIGHT); + var context = create_context (SURFACE_WIDTH, SURFACE_HEIGHT); - var line = new LiveChart.ThresholdLine(7.5); + var line = new LiveChart.ThresholdLine (7.5); line.line.color = red; //When - line.draw(context.ctx, create_config(context)); - screenshot(context); + line.draw (context.ctx, create_config (context)); + screenshot (context); //Then - assert(has_only_one_color_at_row(context)(DEFAULT_BACKGROUND_COLOR, 0)); - assert(has_only_one_color_at_row(context)(DEFAULT_BACKGROUND_COLOR, 1)); - - assert(has_only_one_color_at_row(context)(red, 2)); - - assert(has_only_one_color_at_row(context)(DEFAULT_BACKGROUND_COLOR, 3)); - assert(has_only_one_color_at_row(context)(DEFAULT_BACKGROUND_COLOR, 4)); + assert (has_only_one_color_at_row (context)(DEFAULT_BACKGROUND_COLOR, 0)); + assert (has_only_one_color_at_row (context)(DEFAULT_BACKGROUND_COLOR, 1)); + + assert (has_only_one_color_at_row (context)(red, 2)); + + assert (has_only_one_color_at_row (context)(DEFAULT_BACKGROUND_COLOR, 3)); + assert (has_only_one_color_at_row (context)(DEFAULT_BACKGROUND_COLOR, 4)); }); -} \ No newline at end of file +} diff --git a/tests/utils.vala b/tests/utils.vala index f839bf3..216ff92 100644 --- a/tests/utils.vala +++ b/tests/utils.vala @@ -1,120 +1,118 @@ - -private void register_utils() { - - Test.add_func("/Utils/Cap#IntegerBelow10", () => { +private void register_utils () { + Test.add_func ("/Utils/Cap#IntegerBelow10", () => { //given var fixed_max = 8.2f; - //when - var next = LiveChart.cap(fixed_max); + //when + var next = LiveChart.cap (fixed_max); //then - assert(next == 9f); + assert (next == 9f); }); - Test.add_func("/Utils/Cap#IntegerAlreadyCapped", () => { + Test.add_func ("/Utils/Cap#IntegerAlreadyCapped", () => { //given var fixed_max = 10f; - //when - var next = LiveChart.cap(fixed_max); + //when + var next = LiveChart.cap (fixed_max); //then - assert(next == 10f); + assert (next == 10f); }); - Test.add_func("/Utils/Cap#IntegerBelow100", () => { + Test.add_func ("/Utils/Cap#IntegerBelow100", () => { //given var fixed_max = 76f; - //when - var next = LiveChart.cap(fixed_max); - + //when + var next = LiveChart.cap (fixed_max); + //then - assert(next == 80f); + assert (next == 80f); }); - Test.add_func("/Utils/Cap#IntegerBelow1000", () => { + Test.add_func ("/Utils/Cap#IntegerBelow1000", () => { //given var fixed_max = 923f; - //when - var next = LiveChart.cap(fixed_max); - + //when + var next = LiveChart.cap (fixed_max); + //then - assert(next == 1000f); + assert (next == 1000f); }); - Test.add_func("/Utils/HasFractionalPart#8", () => { + Test.add_func ("/Utils/HasFractionalPart#8", () => { //given var value = 8; - //when - var has_fractional_part = LiveChart.has_fractional_part(value); - + //when + var has_fractional_part = LiveChart.has_fractional_part (value); + //then - assert(has_fractional_part == false); + assert (has_fractional_part == false); }); - Test.add_func("/Utils/HasFractionalPart#8.00", () => { + Test.add_func ("/Utils/HasFractionalPart#8.00", () => { //given var value = 8.00f; - //when - var has_fractional_part = LiveChart.has_fractional_part(value); - + //when + var has_fractional_part = LiveChart.has_fractional_part (value); + //then - assert(has_fractional_part == false); + assert (has_fractional_part == false); }); - Test.add_func("/Utils/HasFractionalPart#8.86", () => { + Test.add_func ("/Utils/HasFractionalPart#8.86", () => { //given var value = 8.86f; - //when - var has_fractional_part = LiveChart.has_fractional_part(value); - + //when + var has_fractional_part = LiveChart.has_fractional_part (value); + //then - assert(has_fractional_part == true); + assert (has_fractional_part == true); }); - Test.add_func("/Utils/golden_divisors", () => { + Test.add_func ("/Utils/golden_divisors", () => { //given var value = 100f; - //when - var divisors = LiveChart.golden_divisors(value); + //when + var divisors = LiveChart.golden_divisors (value); //then - assert(divisors.get(0) == 50); - assert(divisors.get(1) == 25); // Golden: 50 / 2 = 25 - //assert(divisors.get(2) == 20); Not golden: 25 / 2 != 20 - assert(divisors.get(2) == 10); // Golden: 20 / 2 = 10 - assert(divisors.get(3) == 5); //Golden; 10 / 2 = 5 - //assert(divisors.get(4) == 4); Not golden - assert(divisors.get(4) == 2); // Golden - assert(divisors.get(5) == 1); // Golden + assert (divisors.get (0) == 50); + assert (divisors.get (1) == 25); // Golden: 50 / 2 = 25 + //assert (divisors.get (2) == 20); Not golden: 25 / 2 != 20 + assert (divisors.get (2) == 10); // Golden: 20 / 2 = 10 + assert (divisors.get (3) == 5); //Golden; 10 / 2 = 5 + //assert (divisors.get (4) == 4); Not golden + assert (divisors.get (4) == 2); // Golden + assert (divisors.get (5) == 1); // Golden }); - Test.add_func("/Utils/golden_divisors_value_below_1", () => { + Test.add_func ("/Utils/golden_divisors_value_below_1", () => { //given var value = 0.10f; - //when - var divisors = LiveChart.golden_divisors(value); + //when + var divisors = LiveChart.golden_divisors (value); //then - assert(divisors.get(0) == 50f); - assert(divisors.get(1) == 25f); - assert(divisors.get(2) == 10f); - assert(divisors.get(3) == 5f); - assert(divisors.get(4) == 2f); - assert(divisors.get(5) == 1f); + assert (divisors.get (0) == 50f); + assert (divisors.get (1) == 25f); + assert (divisors.get (2) == 10f); + assert (divisors.get (3) == 5f); + assert (divisors.get (4) == 2f); + assert (divisors.get (5) == 1f); }); - Test.add_func("/Utils/golden_divisors#ShouldNotCrashWhenComputingGoldenDivisorForZero", () => { + Test.add_func ("/Utils/golden_divisors#ShouldNotCrashWhenComputingGoldenDivisorForZero", () => { //given var value = 0f; - //when //then - LiveChart.golden_divisors(value); - }); -} \ No newline at end of file + //when//then + LiveChart.golden_divisors (value); + }); +} diff --git a/tests/values.vala b/tests/values.vala index f20a649..27e48df 100644 --- a/tests/values.vala +++ b/tests/values.vala @@ -1,18 +1,16 @@ - -private void register_values() { - - Test.add_func("/Values#Buffer", () => { +private void rgister_values () { + Test.add_func ("/Values#Buffer", () => { //given - var values = new LiveChart.Values(2); + var values = new LiveChart.Values (2); //when - values.add({0, 1}); - values.add({1, 10}); - values.add({2, 100}); - + values.add ({0, 1}); + values.add ({1, 10}); + values.add ({2, 100}); + //then - assert(values.size == 2); - assert(values.get(0) == LiveChart.TimestampedValue(){timestamp = 1, value = 10}); - assert(values.get(1) == LiveChart.TimestampedValue(){timestamp = 2, value = 100}); + assert (values.size == 2); + assert (values.get (0) == LiveChart.TimestampedValue () { timestamp = 1, value = 10 }); + assert (values.get (1) == LiveChart.TimestampedValue () { timestamp = 2, value = 100 }); }); -} \ No newline at end of file +}