Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1884 was 1884, checked in by dwagner, 15 years ago

Added Test for Linetype Points(#637)

File size: 17.9 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      YAxisDescriptor yaxis1 = model.DefaultYAxis;
82      YAxisDescriptor yaxis2 = new YAxisDescriptor();
83
84      model.XAxis.Label = "X Axis";
85      model.XAxis.ShowLabel = true;
86
87      yaxis1.Label = "Y-Axis 1";
88      yaxis1.ShowYAxisLabel = true;
89      yaxis1.Position = AxisPosition.Left;
90      yaxis1.ShowGrid = true;
91      yaxis1.GridColor = Color.Gray;
92
93      yaxis2.Label = "Y-Axis 2";
94      yaxis2.ShowYAxisLabel = true;
95      yaxis2.Position = AxisPosition.Right;
96      yaxis2.ShowGrid = false;
97
98      row1.Color = Color.Red;
99      row1.Thickness = 3;
100      row1.Style = DrawingStyle.Solid;
101      row1.Label = "Die Rote";
102
103      row2.Color = Color.Green;
104      row2.Thickness = 3;
105      row2.Style = DrawingStyle.Solid;
106      row2.Label = "Die Grüne";
107
108      row3.Color = Color.Blue;
109      row3.Thickness = 3;
110      row3.Style = DrawingStyle.Solid;
111      row3.Label = "Die Blaue";
112      row3.YAxis = yaxis2;
113
114      model.AddDataRow(row1);
115      model.AddDataRow(row2);
116      model.AddDataRow(row3);
117
118      Random rand = new Random(42);
119
120      for (int i = 0; i < 10; i++) {
121        row1.AddValue(rand.NextDouble() * 10);
122        row2.AddValue(rand.NextDouble() * 10);
123        row3.AddValue(rand.NextDouble() * 1);
124      }
125
126      f.AddValue += delegate {
127        row1.AddValue(rand.NextDouble() * 10);
128        row2.AddValue(rand.NextDouble() * 10);
129        row3.AddValue(rand.NextDouble() * 1);
130      };
131
132      f.ShowDialog();
133    }
134
135    [Test]
136    public void TestGridX() {
137      LineChartTestForm f = new LineChartTestForm(model);
138      IDataRow row1 = new DataRow();
139      model.AddDataRow(row1);
140
141      model.XAxis.ShowGrid = false;
142
143      Random rand = new Random(42);
144      for (int i = 0; i < 10; i++) {
145        row1.AddValue(rand.NextDouble() * 10);
146      }
147      f.ShowDialog();
148    }
149
150    [Test]
151    public void SimpleTestAggregator() {
152      LineChartTestForm f = new LineChartTestForm(model);
153
154      IDataRow row1 = new DataRow { Label = "row", Color = Color.Red, Thickness = 3, Style = DrawingStyle.Solid };
155
156      model.AddDataRow(row1);
157
158
159      MaxAggregator aggregator = new MaxAggregator {
160        Label = "MinAggregator",
161        Color = Color.Pink,
162        Thickness = 5,
163        Style = DrawingStyle.Solid,
164        LineType = DataRowType.SingleValue
165      };
166      aggregator.AddWatch(row1);
167
168      model.AddDataRow(aggregator);
169
170      row1.AddValue(10);
171      row1.AddValue(5);
172      row1.AddValue(7);
173      row1.AddValue(3);
174      row1.AddValue(10);
175      row1.AddValue(2);
176
177      f.ShowDialog();
178    }
179
180
181    public class Worker {
182      // This method will be called when the thread is started.
183      private readonly ChartDataRowsModel model;
184
185      public Worker(ChartDataRowsModel model) {
186        this.model = model;
187      }
188
189      public void DoWorkMultiLine() {
190        IDataRow row1 = new DataRow { Color = Color.Red, Thickness = 2, Label = "Sinus", Style = DrawingStyle.Solid, ShowMarkers = false };
191        model.AddDataRow(row1);
192
193        IDataRow row2 = new DataRow { Color = Color.Red, Thickness = 3, Label = "Growing", Style = DrawingStyle.Solid, ShowMarkers = false };
194        model.AddDataRow(row2);
195
196        AvgAggregator multiAvgAggregator = new AvgAggregator {
197          Label = "MultiAvgAggregator",
198          Color = Color.DarkOliveGreen,
199          Thickness = 3,
200          Style = DrawingStyle.Solid,
201          LineType = DataRowType.SingleValue,
202          ShowMarkers = false
203        };
204        multiAvgAggregator.AddWatch(row1);
205        multiAvgAggregator.AddWatch(row2);
206        model.AddDataRow(multiAvgAggregator);
207
208        MaxAggregator multiMaxAggregator = new MaxAggregator {
209          Label = "MultiMaxAggregator",
210          Color = Color.DarkKhaki,
211          Thickness = 3,
212          Style = DrawingStyle.Solid,
213          LineType = DataRowType.SingleValue,
214          ShowMarkers = false
215        };
216        multiMaxAggregator.AddWatch(row1);
217        multiMaxAggregator.AddWatch(row2);
218        model.AddDataRow(multiMaxAggregator);
219
220        MinAggregator multiMinAggregator = new MinAggregator {
221          Label = "MultiMinAggregator",
222          Color = Color.DarkRed,
223          Thickness = 3,
224          Style = DrawingStyle.Solid,
225          LineType = DataRowType.SingleValue,
226          ShowMarkers = false
227        };
228        multiMinAggregator.AddWatch(row1);
229        multiMinAggregator.AddWatch(row2);
230        model.AddDataRow(multiMinAggregator);
231
232        //        AvgLineAggregator multiLineAvgAggregator = new AvgLineAggregator {
233        //                                                                           Label = "MultiLineAvgAggregator",
234        //                                                                           Color = Color.Red,
235        //                                                                           Thickness = 4,
236        //                                                                           Style = DrawingStyle.Solid,
237        //                                                                           LineType = DataRowType.Normal,
238        //                                                                           ShowMarkers = false
239        //                                                                         };
240        //        multiLineAvgAggregator.AddWatch(row1);
241        //        multiLineAvgAggregator.AddWatch(row2);
242        //        multiLineAvgAggregator.AddValue(0);
243        //        model.AddDataRow(multiLineAvgAggregator);
244
245        double i = 0;
246
247
248        while (!_shouldStop && i <= 24) {
249          i += 0.2;
250          double newY = Math.Sin(i);
251          Console.WriteLine("working");
252          //row1.AddValue(rand.NextDouble() * 10);
253          row1.AddValue(newY * 10);
254          row2.AddValue(i * 2 - 15);
255          Thread.Sleep(100);
256        }
257        Console.WriteLine("worker thread: terminating gracefully.");
258      }
259
260      public void DoWorkSingleLine() {
261        IDataRow row1 = new DataRow {
262          Color = Color.Red,
263          Thickness = 2,
264          Label = "Sinus",
265          Style = DrawingStyle.Solid,
266          ShowMarkers = false
267        };
268        model.AddDataRow(row1);
269
270        IDataRow row2 = new DataRow {
271          Color = Color.Red,
272          Thickness = 3,
273          Label = "Growing",
274          Style = DrawingStyle.Solid,
275          ShowMarkers = false
276        };
277        model.AddDataRow(row2);
278
279        MinAggregator aggregator = new MinAggregator {
280          Label = "MinAggregator",
281          Color = Color.Pink,
282          Thickness = 3,
283          Style = DrawingStyle.Solid,
284          LineType = DataRowType.SingleValue
285        };
286        aggregator.AddWatch(row1);
287        model.AddDataRow(aggregator);
288
289        MaxAggregator maxAggregator = new MaxAggregator {
290          Label = "MaxAggregator",
291          Color = Color.DeepSkyBlue,
292          Thickness = 3,
293          Style = DrawingStyle.Solid,
294          LineType = DataRowType.SingleValue
295        };
296        maxAggregator.AddWatch(row1);
297        model.AddDataRow(maxAggregator);
298
299        AvgAggregator avgAggregator = new AvgAggregator {
300          Label = "AvgAggregator",
301          Color = Color.Violet,
302          Thickness = 3,
303          Style = DrawingStyle.Solid,
304          LineType = DataRowType.SingleValue
305        };
306        avgAggregator.AddWatch(row1);
307        model.AddDataRow(avgAggregator);
308
309        double i = 0;
310
311
312        while (!_shouldStop && i <= 240) {
313          i += 0.2;
314          double newY = Math.Sin(i);
315          Console.WriteLine("working");
316          //row1.AddValue(rand.NextDouble() * 10);
317          row1.AddValue(newY * 10);
318          row2.AddValue(i * 2 - 15);
319          //System.Threading.Thread.Sleep(100);
320        }
321        Console.WriteLine("worker thread: terminating gracefully.");
322      }
323
324      public void DoWorkAvgLine() {
325        IDataRow row1 = new DataRow {
326          Color = Color.Red,
327          Thickness = 2,
328          Label = "Sinus",
329          Style = DrawingStyle.Solid,
330          ShowMarkers = false
331        };
332        model.AddDataRow(row1);
333
334        IDataRow row2 = new DataRow {
335          Color = Color.Red,
336          Thickness = 3,
337          Label = "Growing",
338          Style = DrawingStyle.Solid,
339          ShowMarkers = false
340        };
341        model.AddDataRow(row2);
342
343        AvgLineAggregator avgLineAggregator = new AvgLineAggregator {
344          Label = "AvgLineAggregator",
345          Color = Color.Violet,
346          Thickness = 3,
347          Style = DrawingStyle.Solid,
348          LineType = DataRowType.Normal,
349          ShowMarkers = false
350        };
351        avgLineAggregator.AddWatch(row1);
352        avgLineAggregator.AddWatch(row2);
353        model.AddDataRow(avgLineAggregator);
354
355        double i = 0;
356
357        while (!_shouldStop && i <= 240) {
358          i += 0.2;
359          double newY = Math.Sin(i);
360          Console.WriteLine("working");
361          //row1.AddValue(rand.NextDouble() * 10);
362          row1.AddValue(newY * 10);
363          row2.AddValue(i * 2 - 15);
364          //Thread.Sleep(100);
365        }
366        Console.WriteLine("worker thread: terminating gracefully.");
367      }
368
369      public void DoWorkFloatingAvg() {
370        IDataRow row1 = new DataRow {
371          Color = Color.Red,
372          Thickness = 2,
373          Label = "SinusHacked",
374          Style = DrawingStyle.Solid,
375          ShowMarkers = false
376        };
377        model.AddDataRow(row1);
378
379        IDataRow row2 = new DataRow {
380          Color = Color.Red,
381          Thickness = 3,
382          Label = "GrowingHacked",
383          Style = DrawingStyle.Solid,
384          ShowMarkers = false
385        };
386        model.AddDataRow(row2);
387
388        FloatingAvgAggregator avgAggregator = new FloatingAvgAggregator {
389                                                                          Thickness = 2,
390                                                                          Label = "floatingAvg",
391                                                                          Color = Color.Peru,
392                                                                          ShowMarkers = false,
393                                                                          Style = DrawingStyle.Solid
394                                                                        };
395
396        avgAggregator.AddWatch(row1);
397        model.AddDataRow(avgAggregator);
398
399        FloatingAvgAggregator avgAggregator2 = new FloatingAvgAggregator {
400          Thickness = 2,
401          Label = "floatingAvg",
402          Color = Color.Aqua,
403          ShowMarkers = false,
404          Style = DrawingStyle.Solid
405        };
406
407        avgAggregator2.AddWatch(row2);
408        model.AddDataRow(avgAggregator2);
409
410       
411        double i = 0;
412        Random rnd = new Random();
413
414        while (!_shouldStop && i <= 100) {
415          i += 0.2;
416          double newY = Math.Sin(i);
417
418          double hack = rnd.NextDouble() * i / 10;
419          row1.AddValue(newY * 10 + hack);
420
421          hack = rnd.NextDouble() * i / 10;
422          row2.AddValue(i * 2 - 15 + hack);
423          //Thread.Sleep(100);
424        }
425        Console.WriteLine("worker thread: terminating gracefully.");
426      }
427
428      public void RequestStop() {
429        _shouldStop = true;
430      }
431
432      // Volatile is used as hint to the compiler that this data
433      // member will be accessed by multiple threads.
434      private volatile bool _shouldStop;
435    }
436
437
438    [Test]
439    public void TestAggregatorMultiLine() {
440      LineChartTestForm f = new LineChartTestForm(model);
441
442      // Create the thread object. This does not start the thread.
443      Worker workerObject = new Worker(model);
444      Thread workerThread = new Thread(workerObject.DoWorkMultiLine);
445
446      // Start the worker thread.
447      workerThread.Start();
448
449      f.ShowDialog();
450      workerObject.RequestStop();
451    }
452
453    [Test]
454    public void TestAggregatorSingleLine() {
455      LineChartTestForm f = new LineChartTestForm(model);
456      model.Title = "SingleLineAggregator Tests";
457
458      // Create the thread object. This does not start the thread.
459      Worker workerObject = new Worker(model);
460      Thread workerThread = new Thread(workerObject.DoWorkSingleLine);
461
462      // Start the worker thread.
463      workerThread.Start();
464
465      f.ShowDialog();
466      workerObject.RequestStop();
467    }
468
469    [Test]
470    public void TestAggregatorAvgLine() {
471      LineChartTestForm f = new LineChartTestForm(model);
472      model.Title = "AvgLineTest";
473
474      // Create the thread object. This does not start the thread.
475      Worker workerObject = new Worker(model);
476      Thread workerThread = new Thread(workerObject.DoWorkAvgLine);
477
478      // Start the worker thread.
479      workerThread.Start();
480
481      f.ShowDialog();
482      workerObject.RequestStop();
483    }
484
485    [Test]
486    public void TestFloatingAvg() {
487      LineChartTestForm f = new LineChartTestForm(model);
488      model.Title = "FloatingAvg Test";
489      model.ViewSettings.LegendPosition = Legend.LegendPosition.Top;
490
491      // Create the thread object. This does not start the thread.
492      Worker workerObject = new Worker(model);
493      Thread workerThread = new Thread(workerObject.DoWorkFloatingAvg);
494
495      // Start the worker thread.
496      workerThread.Start();
497
498      f.ShowDialog();
499      workerObject.RequestStop();
500    }
501
502
503    [Test]
504    public void TestAutoZoomInConstructor() {
505      IDataRow row1 = new DataRow { Color = Color.Red, Thickness = 3, Style = DrawingStyle.Solid };
506
507      model.AddDataRow(row1);
508
509      row1.AddValue(10);
510      row1.AddValue(5);
511      row1.AddValue(7);
512      row1.AddValue(3);
513      row1.AddValue(10);
514      row1.AddValue(2);
515
516      LineChartTestForm f = new LineChartTestForm(model);
517      f.ShowDialog();
518    }
519
520
521    [Test]
522    public void TestSingleValueDataRows() {
523      LineChartTestForm f = new LineChartTestForm(model);
524
525      IDataRow row1 = new DataRow();
526      IDataRow row2 = new DataRow();
527      IDataRow row3 = new DataRow();
528
529      IDataRow row4 = new DataRow();
530      IDataRow row5 = new DataRow();
531      IDataRow row6 = new DataRow();
532
533      row1.Color = Color.Red;
534      row2.Color = Color.Green;
535      row3.Color = Color.Blue;
536
537      row4.Color = Color.DeepPink;
538      row5.Color = Color.Firebrick;
539      row6.Color = Color.DarkSlateGray;
540
541      row1.Thickness = 3;
542      row2.Thickness = 4;
543      row3.Thickness = 5;
544
545      row4.Thickness = 3;
546      row5.Thickness = 4;
547      row6.Thickness = 5;
548
549      row1.Label = "SingleValue";
550      row2.Label = "Gertschi";
551      row3.Label = "Maxi";
552
553      row4.Label = "Simon";
554      row5.Label = "klausmuellerwesternhagenunddierasperies";
555      row6.Label = "anyways";
556
557      row1.Style = DrawingStyle.Solid;
558      row2.Style = DrawingStyle.Solid;
559      row3.Style = DrawingStyle.Dashed;
560
561      row4.Style = DrawingStyle.Solid;
562      row5.Style = DrawingStyle.Solid;
563      row6.Style = DrawingStyle.Dashed;
564
565      row1.LineType = DataRowType.SingleValue;
566      row2.LineType = DataRowType.SingleValue;
567      row1.AddValue(12);
568
569      row2.AddValue(5);
570
571
572      row3.AddValue(2);
573      row3.AddValue(5);
574      row3.AddValue(9);
575      row3.AddValue(1);
576      row3.AddValue(3);
577
578
579      row4.AddValue(10);
580      row5.AddValue(11);
581      row6.AddValue(11);
582
583      model.AddDataRow(row1);
584      model.AddDataRow(row2);
585      model.AddDataRow(row3);
586      model.AddDataRow(row4);
587      model.AddDataRow(row5);
588      model.AddDataRow(row6);
589
590      f.ShowDialog();
591    }
592
593    [Test]
594    public void TestMainForm() {
595      MainForm f = new MainForm();
596      f.ShowDialog();
597    }
598
599
600    [Test]
601    public void TestPointLines() {
602      IDataRow row1 = new DataRow { Color = Color.Red, Thickness = 3, Style = DrawingStyle.Dashed };
603
604      row1.LineType = DataRowType.Points;
605      model.AddDataRow(row1);
606
607      row1.AddValue(10);
608      row1.AddValue(5);
609      row1.AddValue(7);
610      row1.AddValue(3);
611      row1.AddValue(10);
612      row1.AddValue(2);
613
614      LineChartTestForm f = new LineChartTestForm(model);
615      f.ShowDialog();
616    }
617
618
619  }
620}
Note: See TracBrowser for help on using the repository browser.