source: trunk/sources/HeuristicLab.Visualization.Test/LineChartTests.cs @ 1386

Last change on this file since 1386 was 1386, checked in by cbahner, 12 years ago

#519 test cases

File size: 14.4 KB
Line 
1using System;
2using System.Drawing;
3using System.Threading;
4using NUnit.Framework;
5
6namespace HeuristicLab.Visualization.Test {
7  [TestFixture]
8  public class LineChartTests {
9    private ChartDataRowsModel model;
10
11    [SetUp]
12    public void SetUp() {
13      model = new ChartDataRowsModel();
14    }
15
16    [Test]
17    public void TestLineChart() {
18      LineChartTestForm f = new LineChartTestForm(model);
19
20      IDataRow row1 = new DataRow();
21      IDataRow row2 = new DataRow();
22      IDataRow row3 = new DataRow();
23
24      row1.Color = Color.Red;
25      row2.Color = Color.Green;
26      row3.Color = Color.Blue;
27
28      row1.Thickness = 3;
29      row2.Thickness = 4;
30      row3.Thickness = 5;
31
32      row1.Label = "Simon";
33      row2.Label = "Gertschi";
34      row3.Label = "Maxi";
35
36      row1.Style = DrawingStyle.Solid;
37      row2.Style = DrawingStyle.Solid;
38      row3.Style = DrawingStyle.Dashed;
39     
40
41      model.AddDataRow(row1);
42      model.AddDataRow(row2);
43      model.AddDataRow(row3);
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
62      Random rand = new Random();
63
64      for (int i = 0; i < 10000; i++) {
65        row1.AddValue(rand.NextDouble()*10);
66        row2.AddValue(rand.NextDouble()*10);
67        row3.AddValue(rand.NextDouble()*10);
68      }
69
70      f.ShowDialog();
71    }
72
73    [Test]
74    public void TestAxes() {
75      LineChartTestForm f = new LineChartTestForm(model);
76
77      IDataRow row1 = new DataRow();
78      IDataRow row2 = new DataRow();
79      IDataRow row3 = new DataRow();
80
81      row1.Color = Color.Red;
82      row1.Thickness = 3;
83      row1.Style = DrawingStyle.Solid;
84      row1.Label = "Die Rote";
85
86      row2.Color = Color.Green;
87      row2.Thickness = 3;
88      row2.Style = DrawingStyle.Solid;
89      row2.Label = "Die Grüne";
90
91      row3.Color = Color.Blue;
92      row3.Thickness = 3;
93      row3.Style = DrawingStyle.Solid;
94      row3.Label = "Die Blaue";
95      row3.YAxis = new YAxisDescriptor();
96
97      model.AddDataRow(row1);
98      model.AddDataRow(row2);
99      model.AddDataRow(row3);
100
101      Random rand = new Random(42);
102
103      for (int i = 0; i < 10; i++) {
104        row1.AddValue(rand.NextDouble()*10);
105        row2.AddValue(rand.NextDouble()*10);
106        row3.AddValue(rand.NextDouble()*1);
107      }
108
109      f.AddValue += delegate {
110        row1.AddValue(rand.NextDouble()*10);
111        row2.AddValue(rand.NextDouble()*10);
112        row3.AddValue(rand.NextDouble()*1);
113      };
114
115      f.ShowDialog();
116    }
117
118    [Test]
119    public void TestAggregator() {
120      LineChartTestForm f = new LineChartTestForm(model);
121
122      IDataRow row1 = new DataRow();
123      row1.Label = "row";
124      row1.Color = Color.Red;
125      row1.Thickness = 3;
126      row1.Style = DrawingStyle.Solid;
127
128      model.AddDataRow(row1);
129
130
131      MinAggregator aggregator = new MinAggregator();
132      aggregator.Label = "MinAggregator";
133      aggregator.Color = Color.Pink;
134      aggregator.Thickness = 5;
135      aggregator.Style = DrawingStyle.Solid;
136      aggregator.AddValue(2);
137      aggregator.LineType = DataRowType.SingleValue;
138
139      IDataRow lineTest = new DataRow("testline");
140      lineTest.Color = Color.DarkSalmon;
141      lineTest.Thickness = 2;
142      lineTest.Style = DrawingStyle.Dashed;
143      lineTest.LineType = DataRowType.SingleValue;
144      model.AddDataRow(lineTest);
145      lineTest.AddValue(9);
146      lineTest.AddValue(2);
147      lineTest.AddValue(3);
148      lineTest.AddValue(4);
149
150      aggregator.AddWatch(row1);
151
152      model.AddDataRow(aggregator);
153
154
155      row1.AddValue(10);
156      row1.AddValue(5);
157      row1.AddValue(7);
158      row1.AddValue(3);
159      row1.AddValue(10);
160      row1.AddValue(2);
161
162      f.ShowDialog();
163    }
164
165
166    public class Worker {
167      // This method will be called when the thread is started.
168      private ChartDataRowsModel model;
169      public Worker(ChartDataRowsModel model) {
170        this.model = model;
171      }
172     
173      public void DoWorkMultiLine() {
174
175        IDataRow row1 = new DataRow();
176        row1.Color = Color.Red;
177        row1.Thickness = 2;
178        row1.Label = "Sinus";
179        row1.Style = DrawingStyle.Solid;
180        model.AddDataRow(row1);
181
182        IDataRow row2 = new DataRow();
183        row2.Color = Color.Red;
184        row2.Thickness = 3;
185        row2.Label = "Growing";
186        row2.Style = DrawingStyle.Solid;
187        model.AddDataRow(row2);
188
189        AvgAggregator multiAvgAggregator = new AvgAggregator();
190        multiAvgAggregator.Label = "MultiAvgAggregator";
191        multiAvgAggregator.Color = Color.DarkOliveGreen;
192        multiAvgAggregator.Thickness = 3;
193        multiAvgAggregator.Style = DrawingStyle.Solid;
194        multiAvgAggregator.LineType = DataRowType.SingleValue;
195        multiAvgAggregator.AddWatch(row1);
196        multiAvgAggregator.AddWatch(row2);
197        model.AddDataRow(multiAvgAggregator);
198
199        MaxAggregator multiMaxAggregator = new MaxAggregator();
200        multiMaxAggregator.Label = "MultiMaxAggregator";
201        multiMaxAggregator.Color = Color.DarkKhaki;
202        multiMaxAggregator.Thickness = 3;
203        multiMaxAggregator.Style = DrawingStyle.Solid;
204        multiMaxAggregator.LineType = DataRowType.SingleValue;
205        multiMaxAggregator.AddWatch(row1);
206        multiMaxAggregator.AddWatch(row2);
207        model.AddDataRow(multiMaxAggregator);
208
209        MinAggregator multiMinAggregator = new MinAggregator();
210        multiMinAggregator.Label = "MultiMinAggregator";
211        multiMinAggregator.Color = Color.DarkRed;
212        multiMinAggregator.Thickness = 3;
213        multiMinAggregator.Style = DrawingStyle.Solid;
214        multiMinAggregator.LineType = DataRowType.SingleValue;
215        multiMinAggregator.AddWatch(row1);
216        multiMinAggregator.AddWatch(row2);
217        model.AddDataRow(multiMinAggregator);
218
219        AvgLineAggregator multiLineAvgAggregator = new AvgLineAggregator();
220        multiLineAvgAggregator.Label = "MultiLineAvgAggregator";
221        multiLineAvgAggregator.Color = Color.Red;
222        multiLineAvgAggregator.Thickness = 4;
223        multiLineAvgAggregator.Style = DrawingStyle.Solid;
224        multiLineAvgAggregator.LineType = DataRowType.Normal;
225        multiLineAvgAggregator.AddWatch(row1);
226        multiLineAvgAggregator.AddWatch(row2);
227        multiLineAvgAggregator.AddValue(0);
228        model.AddDataRow(multiLineAvgAggregator);
229
230        double i = 0;
231        double newY;
232
233        Random rand = new Random();
234        while (!_shouldStop && i <= 24) {
235          i += 0.2;
236          newY = Math.Sin(i);
237          System.Console.WriteLine("working");
238          //row1.AddValue(rand.NextDouble() * 10);
239          row1.AddValue(newY * 10);
240          row2.AddValue(i*2-15);
241          System.Threading.Thread.Sleep(100);
242        }
243        Console.WriteLine("worker thread: terminating gracefully.");
244      }
245      public void DoWorkSingleLine() {
246
247        IDataRow row1 = new DataRow();
248        row1.Color = Color.Red;
249        row1.Thickness = 2;
250        row1.Label = "Sinus";
251        row1.Style = DrawingStyle.Solid;
252        model.AddDataRow(row1);
253
254        IDataRow row2 = new DataRow();
255        row2.Color = Color.Red;
256        row2.Thickness = 3;
257        row2.Label = "Growing";
258        row2.Style = DrawingStyle.Solid;
259        model.AddDataRow(row2);
260
261        MinAggregator aggregator = new MinAggregator();
262        aggregator.Label = "MinAggregator";
263        aggregator.Color = Color.Pink;
264        aggregator.Thickness = 3;
265        aggregator.Style = DrawingStyle.Solid;
266        aggregator.LineType = DataRowType.SingleValue;
267        aggregator.AddWatch(row1);
268        model.AddDataRow(aggregator);
269
270        MaxAggregator maxAggregator = new MaxAggregator();
271        maxAggregator.Label = "MaxAggregator";
272        maxAggregator.Color = Color.DeepSkyBlue;
273        maxAggregator.Thickness = 3;
274        maxAggregator.Style = DrawingStyle.Solid;
275        maxAggregator.LineType = DataRowType.SingleValue;
276        maxAggregator.AddWatch(row1);
277        model.AddDataRow(maxAggregator);
278
279        AvgAggregator avgAggregator = new AvgAggregator();
280        avgAggregator.Label = "AvgAggregator";
281        avgAggregator.Color = Color.Violet;
282        avgAggregator.Thickness = 3;
283        avgAggregator.Style = DrawingStyle.Solid;
284        avgAggregator.LineType = DataRowType.SingleValue;
285        avgAggregator.AddWatch(row1);
286        model.AddDataRow(avgAggregator);
287
288        double i = 0;
289        double newY;
290
291        Random rand = new Random();
292        while (!_shouldStop && i <= 24) {
293          i += 0.2;
294          newY = Math.Sin(i);
295          System.Console.WriteLine("working");
296          //row1.AddValue(rand.NextDouble() * 10);
297          row1.AddValue(newY * 10);
298          row2.AddValue(i * 2 - 15);
299          System.Threading.Thread.Sleep(100);
300        }
301        Console.WriteLine("worker thread: terminating gracefully.");
302      }
303      public void DoWorkAvgLine() {
304
305        IDataRow row1 = new DataRow();
306        row1.Color = Color.Red;
307        row1.Thickness = 2;
308        row1.Label = "Sinus";
309        row1.Style = DrawingStyle.Solid;
310        model.AddDataRow(row1);
311
312        IDataRow row2 = new DataRow();
313        row2.Color = Color.Red;
314        row2.Thickness = 3;
315        row2.Label = "Growing";
316        row2.Style = DrawingStyle.Solid;
317        model.AddDataRow(row2);
318
319        AvgLineAggregator avgLineAggregator = new AvgLineAggregator();
320        avgLineAggregator.Label = "AvgLineAggregator";
321        avgLineAggregator.Color = Color.Violet;
322        avgLineAggregator.Thickness = 3;
323        avgLineAggregator.Style = DrawingStyle.Solid;
324        avgLineAggregator.LineType = DataRowType.Normal;
325        avgLineAggregator.AddWatch(row1);
326        avgLineAggregator.AddWatch(row2);
327        model.AddDataRow(avgLineAggregator);
328
329        double i = 0;
330        double newY;
331
332        Random rand = new Random();
333        while (!_shouldStop && i <= 24) {
334          i += 0.2;
335          newY = Math.Sin(i);
336          System.Console.WriteLine("working");
337          //row1.AddValue(rand.NextDouble() * 10);
338          row1.AddValue(newY * 10);
339          row2.AddValue(i * 2 - 15);
340          System.Threading.Thread.Sleep(100);
341        }
342        Console.WriteLine("worker thread: terminating gracefully.");
343      }
344      public void RequestStop() {
345        _shouldStop = true;
346      }
347      // Volatile is used as hint to the compiler that this data
348      // member will be accessed by multiple threads.
349      private volatile bool _shouldStop;
350    }
351
352
353    [Test]
354    public void TestAggregatorMultiLine() {
355      LineChartTestForm f = new LineChartTestForm(model);
356
357      // Create the thread object. This does not start the thread.
358      Worker workerObject = new Worker(model);
359      Thread workerThread = new Thread(workerObject.DoWorkMultiLine);
360
361      // Start the worker thread.
362      workerThread.Start();
363
364      f.ShowDialog();
365      workerObject.RequestStop();
366    }
367
368    [Test]
369    public void TestAggregatorSingleLine() {
370      LineChartTestForm f = new LineChartTestForm(model);
371   
372      // Create the thread object. This does not start the thread.
373      Worker workerObject = new Worker(model);
374      Thread workerThread = new Thread(workerObject.DoWorkSingleLine);
375
376      // Start the worker thread.
377      workerThread.Start();
378
379      f.ShowDialog();
380      workerObject.RequestStop();
381    }
382    [Test]
383    public void TestAggregatorAvgLine() {
384      LineChartTestForm f = new LineChartTestForm(model);
385
386      // Create the thread object. This does not start the thread.
387      Worker workerObject = new Worker(model);
388      Thread workerThread = new Thread(workerObject.DoWorkAvgLine);
389
390      // Start the worker thread.
391      workerThread.Start();
392
393      f.ShowDialog();
394      workerObject.RequestStop();
395    }
396
397   
398
399    [Test]
400    public void TestAutoZoomInConstructor() {
401      IDataRow row1 = new DataRow();
402
403      row1.Color = Color.Red;
404      row1.Thickness = 3;
405      row1.Style = DrawingStyle.Solid;
406
407      model.AddDataRow(row1);
408
409      row1.AddValue(10);
410      row1.AddValue(5);
411      row1.AddValue(7);
412      row1.AddValue(3);
413      row1.AddValue(10);
414      row1.AddValue(2);
415
416      LineChartTestForm f = new LineChartTestForm(model);
417      f.ShowDialog();
418    }
419
420
421    [Test]
422    public void TestSingleValueDataRows() {
423      LineChartTestForm f = new LineChartTestForm(model);
424
425      IDataRow row1 = new DataRow();
426      IDataRow row2 = new DataRow();
427      IDataRow row3 = new DataRow();
428
429      IDataRow row4 = new DataRow();
430      IDataRow row5 = new DataRow();
431      IDataRow row6 = new DataRow();
432
433      row1.Color = Color.Red;
434      row2.Color = Color.Green;
435      row3.Color = Color.Blue;
436
437      row4.Color = Color.DeepPink;
438      row5.Color = Color.Firebrick;
439      row6.Color = Color.DarkSlateGray;
440
441      row1.Thickness = 3;
442      row2.Thickness = 4;
443      row3.Thickness = 5;
444
445      row4.Thickness = 3;
446      row5.Thickness = 4;
447      row6.Thickness = 5;
448
449      row1.Label = "SingleValue";
450      row2.Label = "Gertschi";
451      row3.Label = "Maxi";
452
453      row4.Label = "Simon";
454      row5.Label = "klausmuellerwesternhagenunddierasperies";
455      row6.Label = "anyways";
456
457      row1.Style = DrawingStyle.Solid;
458      row2.Style = DrawingStyle.Solid;
459      row3.Style = DrawingStyle.Dashed;
460
461      row4.Style = DrawingStyle.Solid;
462      row5.Style = DrawingStyle.Solid;
463      row6.Style = DrawingStyle.Dashed;
464
465      row1.LineType = DataRowType.SingleValue;
466      row2.LineType = DataRowType.SingleValue;
467      row1.AddValue(12);
468
469      row2.AddValue(5);
470     
471
472      row3.AddValue(2);
473      row3.AddValue(5);
474      row3.AddValue(9);
475      row3.AddValue(1);
476      row3.AddValue(3);
477
478
479      row4.AddValue(10);
480      row5.AddValue(11);
481      row6.AddValue(11);
482
483      model.AddDataRow(row1);
484      model.AddDataRow(row2);
485      model.AddDataRow(row3);
486      model.AddDataRow(row4);
487      model.AddDataRow(row5);
488      model.AddDataRow(row6);
489
490      f.ShowDialog();
491    }
492
493
494
495    [Test]
496    public void TestMainForm() {
497      MainForm f = new MainForm();
498      f.ShowDialog();
499    }
500  }
501}
Note: See TracBrowser for help on using the repository browser.