[983] | 1 | using System;
|
---|
[869] | 2 | using System.Drawing;
|
---|
[1326] | 3 | using System.Threading;
|
---|
[861] | 4 | using NUnit.Framework;
|
---|
| 5 |
|
---|
| 6 | namespace HeuristicLab.Visualization.Test {
|
---|
| 7 | [TestFixture]
|
---|
| 8 | public class LineChartTests {
|
---|
[1038] | 9 | private ChartDataRowsModel model;
|
---|
| 10 |
|
---|
| 11 | [SetUp]
|
---|
| 12 | public void SetUp() {
|
---|
| 13 | model = new ChartDataRowsModel();
|
---|
| 14 | }
|
---|
| 15 |
|
---|
[861] | 16 | [Test]
|
---|
| 17 | public void TestLineChart() {
|
---|
[1038] | 18 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
[861] | 19 |
|
---|
[869] | 20 | IDataRow row1 = new DataRow();
|
---|
| 21 | IDataRow row2 = new DataRow();
|
---|
| 22 | IDataRow row3 = new DataRow();
|
---|
[861] | 23 |
|
---|
[869] | 24 | row1.Color = Color.Red;
|
---|
| 25 | row2.Color = Color.Green;
|
---|
| 26 | row3.Color = Color.Blue;
|
---|
[861] | 27 |
|
---|
[869] | 28 | row1.Thickness = 3;
|
---|
| 29 | row2.Thickness = 4;
|
---|
| 30 | row3.Thickness = 5;
|
---|
| 31 |
|
---|
[1049] | 32 | row1.Label = "Simon";
|
---|
| 33 | row2.Label = "Gertschi";
|
---|
| 34 | row3.Label = "Maxi";
|
---|
| 35 |
|
---|
[980] | 36 | row1.Style = DrawingStyle.Solid;
|
---|
| 37 | row2.Style = DrawingStyle.Solid;
|
---|
| 38 | row3.Style = DrawingStyle.Dashed;
|
---|
| 39 |
|
---|
| 40 |
|
---|
[1038] | 41 | model.AddDataRow(row1);
|
---|
| 42 | model.AddDataRow(row2);
|
---|
| 43 | model.AddDataRow(row3);
|
---|
[869] | 44 |
|
---|
| 45 | row1.AddValue(10);
|
---|
| 46 | row1.AddValue(5);
|
---|
| 47 | row1.AddValue(7);
|
---|
| 48 | row1.AddValue(3);
|
---|
| 49 | row1.AddValue(10);
|
---|
| 50 | row1.AddValue(2);
|
---|
| 51 |
|
---|
| 52 | row2.AddValue(5);
|
---|
| 53 | row2.AddValue(6);
|
---|
| 54 | row2.AddValue(5);
|
---|
| 55 |
|
---|
| 56 | row3.AddValue(2);
|
---|
| 57 | row3.AddValue(2);
|
---|
| 58 | row3.AddValue(2);
|
---|
| 59 | row3.AddValue(2);
|
---|
| 60 | row3.AddValue(2);
|
---|
| 61 |
|
---|
[983] | 62 | Random rand = new Random();
|
---|
| 63 |
|
---|
[1038] | 64 | for (int i = 0; i < 10000; i++) {
|
---|
[983] | 65 | row1.AddValue(rand.NextDouble()*10);
|
---|
| 66 | row2.AddValue(rand.NextDouble()*10);
|
---|
| 67 | row3.AddValue(rand.NextDouble()*10);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
[861] | 70 | f.ShowDialog();
|
---|
| 71 | }
|
---|
[983] | 72 |
|
---|
| 73 | [Test]
|
---|
| 74 | public void TestAxes() {
|
---|
[1038] | 75 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
[983] | 76 |
|
---|
| 77 | IDataRow row1 = new DataRow();
|
---|
[1285] | 78 | IDataRow row2 = new DataRow();
|
---|
[983] | 79 |
|
---|
| 80 | row1.Color = Color.Red;
|
---|
| 81 | row1.Thickness = 3;
|
---|
| 82 | row1.Style = DrawingStyle.Solid;
|
---|
| 83 |
|
---|
[1285] | 84 | row2.Color = Color.Green;
|
---|
| 85 | row2.Thickness = 3;
|
---|
| 86 | row2.Style = DrawingStyle.Solid;
|
---|
| 87 |
|
---|
[1038] | 88 | model.AddDataRow(row1);
|
---|
[1285] | 89 | model.AddDataRow(row2);
|
---|
[983] | 90 |
|
---|
[1285] | 91 | Random rand = new Random(42);
|
---|
| 92 |
|
---|
| 93 | for (int i = 0; i < 10; i++) {
|
---|
| 94 | row1.AddValue(rand.NextDouble()*10);
|
---|
| 95 | row2.AddValue(rand.NextDouble()*10);
|
---|
| 96 | }
|
---|
[983] | 97 |
|
---|
| 98 | f.ShowDialog();
|
---|
| 99 | }
|
---|
[1040] | 100 |
|
---|
| 101 | [Test]
|
---|
[1326] | 102 | public void TestAggregator() {
|
---|
| 103 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
| 104 |
|
---|
| 105 | IDataRow row1 = new DataRow();
|
---|
| 106 | row1.Label = "row";
|
---|
| 107 | row1.Color = Color.Red;
|
---|
| 108 | row1.Thickness = 3;
|
---|
| 109 | row1.Style = DrawingStyle.Solid;
|
---|
| 110 |
|
---|
| 111 | model.AddDataRow(row1);
|
---|
| 112 |
|
---|
| 113 |
|
---|
| 114 | IAggregator aggregator = new MinAggregator();
|
---|
| 115 | aggregator.Label = "MinAggregator";
|
---|
| 116 | aggregator.Color = Color.Pink;
|
---|
| 117 | aggregator.Thickness = 5;
|
---|
| 118 | aggregator.Style = DrawingStyle.Solid;
|
---|
| 119 | aggregator.AddValue(2);
|
---|
| 120 | aggregator.LineType = DataRowType.SingleValue;
|
---|
| 121 |
|
---|
| 122 | IDataRow lineTest = new DataRow("testline");
|
---|
| 123 | lineTest.Color = Color.DarkSalmon;
|
---|
| 124 | lineTest.Thickness = 2;
|
---|
| 125 | lineTest.Style = DrawingStyle.Dashed;
|
---|
| 126 | lineTest.LineType = DataRowType.SingleValue;
|
---|
| 127 | model.AddDataRow(lineTest);
|
---|
| 128 | lineTest.AddValue(9);
|
---|
| 129 | lineTest.AddValue(2);
|
---|
| 130 | lineTest.AddValue(3);
|
---|
| 131 | lineTest.AddValue(4);
|
---|
| 132 |
|
---|
| 133 | aggregator.AddWatch(row1);
|
---|
| 134 |
|
---|
| 135 | model.AddDataRow(aggregator);
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | row1.AddValue(10);
|
---|
| 139 | row1.AddValue(5);
|
---|
| 140 | row1.AddValue(7);
|
---|
| 141 | row1.AddValue(3);
|
---|
| 142 | row1.AddValue(10);
|
---|
| 143 | row1.AddValue(2);
|
---|
| 144 |
|
---|
| 145 | f.ShowDialog();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 |
|
---|
| 149 | public class Worker {
|
---|
| 150 | // This method will be called when the thread is started.
|
---|
| 151 | private ChartDataRowsModel model;
|
---|
| 152 | public Worker(ChartDataRowsModel model) {
|
---|
| 153 | this.model = model;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | public void DoWork() {
|
---|
| 157 |
|
---|
| 158 | IDataRow row1 = new DataRow();
|
---|
| 159 | row1.Color = Color.Red;
|
---|
| 160 | row1.Thickness = 2;
|
---|
| 161 | row1.Label = "Simon";
|
---|
| 162 | row1.Style = DrawingStyle.Solid;
|
---|
| 163 | model.AddDataRow(row1);
|
---|
| 164 |
|
---|
| 165 | IDataRow row2 = new DataRow();
|
---|
| 166 | row2.Color = Color.Red;
|
---|
| 167 | row2.Thickness = 3;
|
---|
| 168 | row2.Label = "Simon";
|
---|
| 169 | row2.Style = DrawingStyle.Solid;
|
---|
| 170 | model.AddDataRow(row2);
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 | IAggregator aggregator = new MinAggregator();
|
---|
| 174 | aggregator.Label = "MinAggregator";
|
---|
| 175 | aggregator.Color = Color.Pink;
|
---|
| 176 | aggregator.Thickness = 3;
|
---|
| 177 | aggregator.Style = DrawingStyle.Solid;
|
---|
| 178 | aggregator.LineType = DataRowType.SingleValue;
|
---|
| 179 | aggregator.AddWatch(row1);
|
---|
| 180 | model.AddDataRow(aggregator);
|
---|
| 181 |
|
---|
| 182 | IAggregator maxAggregator = new MaxAggregator();
|
---|
| 183 | maxAggregator.Label = "MaxAggregator";
|
---|
| 184 | maxAggregator.Color = Color.DeepSkyBlue;
|
---|
| 185 | maxAggregator.Thickness = 3;
|
---|
| 186 | maxAggregator.Style = DrawingStyle.Solid;
|
---|
| 187 | maxAggregator.LineType = DataRowType.SingleValue;
|
---|
| 188 | maxAggregator.AddWatch(row1);
|
---|
| 189 | model.AddDataRow(maxAggregator);
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 | IAggregator avgAggregator = new AvgAggregator();
|
---|
| 193 | avgAggregator.Label = "AvgAggregator";
|
---|
| 194 | avgAggregator.Color = Color.Violet;
|
---|
| 195 | avgAggregator.Thickness = 3;
|
---|
| 196 | avgAggregator.Style = DrawingStyle.Solid;
|
---|
| 197 | avgAggregator.LineType = DataRowType.SingleValue;
|
---|
| 198 | avgAggregator.AddWatch(row1);
|
---|
| 199 | model.AddDataRow(avgAggregator);
|
---|
| 200 |
|
---|
| 201 | IAggregator multiAvgAggregator = new AvgAggregator();
|
---|
| 202 | multiAvgAggregator.Label = "MultiAvgAggregator";
|
---|
| 203 | multiAvgAggregator.Color = Color.DarkOliveGreen;
|
---|
| 204 | multiAvgAggregator.Thickness = 3;
|
---|
| 205 | multiAvgAggregator.Style = DrawingStyle.Solid;
|
---|
| 206 | multiAvgAggregator.LineType = DataRowType.SingleValue;
|
---|
| 207 | multiAvgAggregator.AddWatch(row1);
|
---|
| 208 | multiAvgAggregator.AddWatch(row2);
|
---|
| 209 | model.AddDataRow(multiAvgAggregator);
|
---|
| 210 |
|
---|
| 211 | IAggregator multiMaxAggregator = new MaxAggregator();
|
---|
| 212 | multiMaxAggregator.Label = "MultiMaxAggregator";
|
---|
| 213 | multiMaxAggregator.Color = Color.DarkKhaki;
|
---|
| 214 | multiMaxAggregator.Thickness = 3;
|
---|
| 215 | multiMaxAggregator.Style = DrawingStyle.Solid;
|
---|
| 216 | multiMaxAggregator.LineType = DataRowType.SingleValue;
|
---|
| 217 | multiMaxAggregator.AddWatch(row1);
|
---|
| 218 | multiMaxAggregator.AddWatch(row2);
|
---|
| 219 | model.AddDataRow(multiMaxAggregator);
|
---|
| 220 |
|
---|
| 221 | IAggregator multiMinAggregator = new MinAggregator();
|
---|
| 222 | multiMinAggregator.Label = "MultiMinAggregator";
|
---|
| 223 | multiMinAggregator.Color = Color.DarkRed;
|
---|
| 224 | multiMinAggregator.Thickness = 3;
|
---|
| 225 | multiMinAggregator.Style = DrawingStyle.Solid;
|
---|
| 226 | multiMinAggregator.LineType = DataRowType.SingleValue;
|
---|
| 227 | multiMinAggregator.AddWatch(row1);
|
---|
| 228 | multiMinAggregator.AddWatch(row2);
|
---|
| 229 | model.AddDataRow(multiMinAggregator);
|
---|
| 230 |
|
---|
| 231 | IAggregator multiLineAvgAggregator = new AvgLineAggregator();
|
---|
| 232 | multiLineAvgAggregator.Label = "MultiLineAvgAggregator";
|
---|
| 233 | multiLineAvgAggregator.Color = Color.Red;
|
---|
| 234 | multiLineAvgAggregator.Thickness = 4;
|
---|
| 235 | multiLineAvgAggregator.Style = DrawingStyle.Solid;
|
---|
| 236 | multiLineAvgAggregator.LineType = DataRowType.Normal;
|
---|
| 237 | multiLineAvgAggregator.AddWatch(row1);
|
---|
| 238 | multiLineAvgAggregator.AddWatch(row2);
|
---|
| 239 | multiLineAvgAggregator.AddValue(0);
|
---|
| 240 | model.AddDataRow(multiLineAvgAggregator);
|
---|
| 241 |
|
---|
| 242 | double i = 0;
|
---|
| 243 | double newY;
|
---|
| 244 |
|
---|
| 245 | Random rand = new Random();
|
---|
| 246 | while (!_shouldStop && i <= 24) {
|
---|
| 247 | i += 0.2;
|
---|
| 248 | newY = Math.Sin(i);
|
---|
| 249 | System.Console.WriteLine("working");
|
---|
| 250 | //row1.AddValue(rand.NextDouble() * 10);
|
---|
| 251 | row1.AddValue(newY * 10);
|
---|
| 252 | row2.AddValue(i*2-15);
|
---|
| 253 | System.Threading.Thread.Sleep(100);
|
---|
| 254 | }
|
---|
| 255 | Console.WriteLine("worker thread: terminating gracefully.");
|
---|
| 256 | }
|
---|
| 257 | public void RequestStop() {
|
---|
| 258 | _shouldStop = true;
|
---|
| 259 | }
|
---|
| 260 | // Volatile is used as hint to the compiler that this data
|
---|
| 261 | // member will be accessed by multiple threads.
|
---|
| 262 | private volatile bool _shouldStop;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 |
|
---|
| 266 | [Test]
|
---|
| 267 | public void TestAggregator2() {
|
---|
| 268 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
| 269 |
|
---|
| 270 | // Create the thread object. This does not start the thread.
|
---|
| 271 | Worker workerObject = new Worker(model);
|
---|
| 272 | Thread workerThread = new Thread(workerObject.DoWork);
|
---|
| 273 |
|
---|
| 274 | // Start the worker thread.
|
---|
| 275 | workerThread.Start();
|
---|
| 276 |
|
---|
| 277 | f.ShowDialog();
|
---|
| 278 | workerObject.RequestStop();
|
---|
| 279 | }
|
---|
| 280 |
|
---|
| 281 |
|
---|
| 282 |
|
---|
| 283 | [Test]
|
---|
[1040] | 284 | public void TestAutoZoomInConstructor() {
|
---|
| 285 | IDataRow row1 = new DataRow();
|
---|
| 286 |
|
---|
| 287 | row1.Color = Color.Red;
|
---|
| 288 | row1.Thickness = 3;
|
---|
| 289 | row1.Style = DrawingStyle.Solid;
|
---|
| 290 |
|
---|
| 291 | model.AddDataRow(row1);
|
---|
| 292 |
|
---|
| 293 | row1.AddValue(10);
|
---|
| 294 | row1.AddValue(5);
|
---|
| 295 | row1.AddValue(7);
|
---|
| 296 | row1.AddValue(3);
|
---|
| 297 | row1.AddValue(10);
|
---|
| 298 | row1.AddValue(2);
|
---|
| 299 |
|
---|
| 300 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
| 301 | f.ShowDialog();
|
---|
| 302 | }
|
---|
[1240] | 303 |
|
---|
[1243] | 304 |
|
---|
[1240] | 305 | [Test]
|
---|
[1243] | 306 | public void TestSingleValueDataRows() {
|
---|
| 307 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
| 308 |
|
---|
| 309 | IDataRow row1 = new DataRow();
|
---|
| 310 | IDataRow row2 = new DataRow();
|
---|
| 311 | IDataRow row3 = new DataRow();
|
---|
| 312 |
|
---|
| 313 | row1.Color = Color.Red;
|
---|
| 314 | row2.Color = Color.Green;
|
---|
| 315 | row3.Color = Color.Blue;
|
---|
| 316 |
|
---|
| 317 | row1.Thickness = 3;
|
---|
| 318 | row2.Thickness = 4;
|
---|
| 319 | row3.Thickness = 5;
|
---|
| 320 |
|
---|
| 321 | row1.Label = "SingleValue";
|
---|
| 322 | row2.Label = "Gertschi";
|
---|
| 323 | row3.Label = "Maxi";
|
---|
| 324 |
|
---|
| 325 | row1.Style = DrawingStyle.Solid;
|
---|
| 326 | row2.Style = DrawingStyle.Solid;
|
---|
| 327 | row3.Style = DrawingStyle.Dashed;
|
---|
| 328 |
|
---|
| 329 | row1.LineType = DataRowType.SingleValue;
|
---|
| 330 | row2.LineType = DataRowType.SingleValue;
|
---|
| 331 | row1.AddValue(12);
|
---|
| 332 |
|
---|
| 333 | model.AddDataRow(row1);
|
---|
| 334 | model.AddDataRow(row2);
|
---|
| 335 | model.AddDataRow(row3);
|
---|
| 336 |
|
---|
| 337 |
|
---|
| 338 |
|
---|
| 339 | row2.AddValue(5);
|
---|
| 340 |
|
---|
| 341 |
|
---|
| 342 | row3.AddValue(2);
|
---|
| 343 | row3.AddValue(5);
|
---|
| 344 | row3.AddValue(9);
|
---|
| 345 | row3.AddValue(1);
|
---|
| 346 | row3.AddValue(3);
|
---|
| 347 |
|
---|
| 348 |
|
---|
| 349 |
|
---|
| 350 |
|
---|
| 351 | f.ShowDialog();
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 |
|
---|
| 355 |
|
---|
| 356 | [Test]
|
---|
[1240] | 357 | public void TestMainForm() {
|
---|
| 358 | MainForm f = new MainForm();
|
---|
| 359 | f.ShowDialog();
|
---|
| 360 | }
|
---|
[861] | 361 | }
|
---|
[1243] | 362 | }
|
---|