public void TestRandomDataLength() { Random rd = new Random(); Int32 width = rd.Next(); Int32 height = rd.Next(); width %= 2160; height %= 3840; ColorGridData cgd = new ColorGridData(width, height); cgd.generate_random_color_grid(); Assert.AreEqual(width * height * 4, cgd.random_data.Length); }
public void TestHUECalculating() { Random rd = new Random(); Byte[] bgr = new Byte[3]; float expected = 0, actual = 0; rd.NextBytes(bgr); expected = this.TestCalculateHUE(bgr[0], bgr[1], bgr[2]); actual = ColorGridData.calculate_hue(bgr[0], bgr[1], bgr[2]); Assert.AreEqual(expected, actual); }
public ColorForm(ColorMeter c) { InitializeComponent(); tester t = new tester(); _colorMeter = c; _colorMeter.sendData += _colorMeter_sendData; colorDataGridView.CellBeginEdit += ColorDataGridView_CellBeginEdit; colorDataGridView.CellEndEdit += ColorDataGridView_CellEndEdit; _gridData = new ColorGridData(AddRow(true)); }
public void TestRandomDataValue() { Random rd = new Random(); Int32 width = rd.Next(); Int32 height = rd.Next(); width %= 2160; height %= 3840; ColorGridData cgd1 = new ColorGridData(width, height); ColorGridData cgd2 = new ColorGridData(width, height); cgd1.generate_random_color_grid(); cgd2.generate_random_color_grid(); Assert.AreNotEqual(cgd1.random_data, cgd2.random_data); }
public void TestHUESorting() { Int32 width = 600; Int32 height = 600; Byte[] bgr = new Byte[3], sorted_data; Stopwatch stopwatch = new Stopwatch(); long max_time_elapse = 2 * 1000; Int32 x = 0, y = 0, pixel_index = 0; float previous_hue = 0, this_hue = 0; ColorGridData.color_align align = ColorGridData.color_align.left; ColorGridData cgd = new ColorGridData(width, height); cgd.generate_random_color_grid(); stopwatch.Start(); cgd.color_sort_by_hue(align, 360); stopwatch.Stop(); if (max_time_elapse < stopwatch.ElapsedMilliseconds) { Assert.Fail("Spent " + stopwatch.ElapsedMilliseconds + " ms on sorting," + " beyond max [" + max_time_elapse + "] ms"); } sorted_data = cgd.sorted_data; Assert.AreEqual(cgd.random_data.Length, cgd.sorted_data.Length); switch (align) { case ColorGridData.color_align.top: case ColorGridData.color_align.left: x = 0; y = 0; break; case ColorGridData.color_align.right: x = width - 1; y = 0; break; case ColorGridData.color_align.buttom: x = 0; y = height - 1; break; default: return; } while ((x >= 0) && (x < width) && (y >= 0) && (y < height)) { pixel_index = y * width + x; this_hue = this.TestCalculateHUE(sorted_data[pixel_index * 4], sorted_data[pixel_index * 4 + 1], sorted_data[pixel_index * 4 + 2]); if (this_hue < previous_hue) { Assert.Fail("wrong sorting by HUE at point [" + x + "," + y + "]"); } previous_hue = this_hue; switch (align) { case ColorGridData.color_align.left: y++; if (y == height) { x++; y = 0; } break; case ColorGridData.color_align.top: x++; if (x == width) { y++; x = 0; } break; case ColorGridData.color_align.right: y++; if (y == height) { x--; y = 0; } break; case ColorGridData.color_align.buttom: x++; if (x == width) { y--; x = 0; } break; default: return; } } }