1 | using System;
|
---|
2 | using System.Drawing;
|
---|
3 | using System.Threading;
|
---|
4 | using NUnit.Framework;
|
---|
5 |
|
---|
6 | namespace 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 |
|
---|
80 | row1.Color = Color.Red;
|
---|
81 | row1.Thickness = 3;
|
---|
82 | row1.Style = DrawingStyle.Solid;
|
---|
83 | row1.Label = "Die Rote";
|
---|
84 |
|
---|
85 | row2.Color = Color.Green;
|
---|
86 | row2.Thickness = 3;
|
---|
87 | row2.Style = DrawingStyle.Solid;
|
---|
88 | row2.Label = "Die Grüne";
|
---|
89 |
|
---|
90 | model.AddDataRow(row1);
|
---|
91 | model.AddDataRow(row2);
|
---|
92 |
|
---|
93 | Random rand = new Random(42);
|
---|
94 |
|
---|
95 | for (int i = 0; i < 10; i++) {
|
---|
96 | row1.AddValue(rand.NextDouble()*10);
|
---|
97 | row2.AddValue(rand.NextDouble()*10);
|
---|
98 | }
|
---|
99 |
|
---|
100 | f.ShowDialog();
|
---|
101 | }
|
---|
102 |
|
---|
103 | [Test]
|
---|
104 | public void TestAggregator() {
|
---|
105 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
106 |
|
---|
107 | IDataRow row1 = new DataRow();
|
---|
108 | row1.Label = "row";
|
---|
109 | row1.Color = Color.Red;
|
---|
110 | row1.Thickness = 3;
|
---|
111 | row1.Style = DrawingStyle.Solid;
|
---|
112 |
|
---|
113 | model.AddDataRow(row1);
|
---|
114 |
|
---|
115 |
|
---|
116 | IAggregator aggregator = new MinAggregator();
|
---|
117 | aggregator.Label = "MinAggregator";
|
---|
118 | aggregator.Color = Color.Pink;
|
---|
119 | aggregator.Thickness = 5;
|
---|
120 | aggregator.Style = DrawingStyle.Solid;
|
---|
121 | aggregator.AddValue(2);
|
---|
122 | aggregator.LineType = DataRowType.SingleValue;
|
---|
123 |
|
---|
124 | IDataRow lineTest = new DataRow("testline");
|
---|
125 | lineTest.Color = Color.DarkSalmon;
|
---|
126 | lineTest.Thickness = 2;
|
---|
127 | lineTest.Style = DrawingStyle.Dashed;
|
---|
128 | lineTest.LineType = DataRowType.SingleValue;
|
---|
129 | model.AddDataRow(lineTest);
|
---|
130 | lineTest.AddValue(9);
|
---|
131 | lineTest.AddValue(2);
|
---|
132 | lineTest.AddValue(3);
|
---|
133 | lineTest.AddValue(4);
|
---|
134 |
|
---|
135 | aggregator.AddWatch(row1);
|
---|
136 |
|
---|
137 | model.AddDataRow(aggregator);
|
---|
138 |
|
---|
139 |
|
---|
140 | row1.AddValue(10);
|
---|
141 | row1.AddValue(5);
|
---|
142 | row1.AddValue(7);
|
---|
143 | row1.AddValue(3);
|
---|
144 | row1.AddValue(10);
|
---|
145 | row1.AddValue(2);
|
---|
146 |
|
---|
147 | f.ShowDialog();
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | public class Worker {
|
---|
152 | // This method will be called when the thread is started.
|
---|
153 | private ChartDataRowsModel model;
|
---|
154 | public Worker(ChartDataRowsModel model) {
|
---|
155 | this.model = model;
|
---|
156 | }
|
---|
157 |
|
---|
158 | public void DoWork() {
|
---|
159 |
|
---|
160 | IDataRow row1 = new DataRow();
|
---|
161 | row1.Color = Color.Red;
|
---|
162 | row1.Thickness = 2;
|
---|
163 | row1.Label = "Simon";
|
---|
164 | row1.Style = DrawingStyle.Solid;
|
---|
165 | model.AddDataRow(row1);
|
---|
166 |
|
---|
167 | IDataRow row2 = new DataRow();
|
---|
168 | row2.Color = Color.Red;
|
---|
169 | row2.Thickness = 3;
|
---|
170 | row2.Label = "Simon";
|
---|
171 | row2.Style = DrawingStyle.Solid;
|
---|
172 | model.AddDataRow(row2);
|
---|
173 |
|
---|
174 |
|
---|
175 | IAggregator aggregator = new MinAggregator();
|
---|
176 | aggregator.Label = "MinAggregator";
|
---|
177 | aggregator.Color = Color.Pink;
|
---|
178 | aggregator.Thickness = 3;
|
---|
179 | aggregator.Style = DrawingStyle.Solid;
|
---|
180 | aggregator.LineType = DataRowType.SingleValue;
|
---|
181 | aggregator.AddWatch(row1);
|
---|
182 | model.AddDataRow(aggregator);
|
---|
183 |
|
---|
184 | IAggregator maxAggregator = new MaxAggregator();
|
---|
185 | maxAggregator.Label = "MaxAggregator";
|
---|
186 | maxAggregator.Color = Color.DeepSkyBlue;
|
---|
187 | maxAggregator.Thickness = 3;
|
---|
188 | maxAggregator.Style = DrawingStyle.Solid;
|
---|
189 | maxAggregator.LineType = DataRowType.SingleValue;
|
---|
190 | maxAggregator.AddWatch(row1);
|
---|
191 | model.AddDataRow(maxAggregator);
|
---|
192 |
|
---|
193 |
|
---|
194 | IAggregator avgAggregator = new AvgAggregator();
|
---|
195 | avgAggregator.Label = "AvgAggregator";
|
---|
196 | avgAggregator.Color = Color.Violet;
|
---|
197 | avgAggregator.Thickness = 3;
|
---|
198 | avgAggregator.Style = DrawingStyle.Solid;
|
---|
199 | avgAggregator.LineType = DataRowType.SingleValue;
|
---|
200 | avgAggregator.AddWatch(row1);
|
---|
201 | model.AddDataRow(avgAggregator);
|
---|
202 |
|
---|
203 | IAggregator multiAvgAggregator = new AvgAggregator();
|
---|
204 | multiAvgAggregator.Label = "MultiAvgAggregator";
|
---|
205 | multiAvgAggregator.Color = Color.DarkOliveGreen;
|
---|
206 | multiAvgAggregator.Thickness = 3;
|
---|
207 | multiAvgAggregator.Style = DrawingStyle.Solid;
|
---|
208 | multiAvgAggregator.LineType = DataRowType.SingleValue;
|
---|
209 | multiAvgAggregator.AddWatch(row1);
|
---|
210 | multiAvgAggregator.AddWatch(row2);
|
---|
211 | model.AddDataRow(multiAvgAggregator);
|
---|
212 |
|
---|
213 | IAggregator multiMaxAggregator = new MaxAggregator();
|
---|
214 | multiMaxAggregator.Label = "MultiMaxAggregator";
|
---|
215 | multiMaxAggregator.Color = Color.DarkKhaki;
|
---|
216 | multiMaxAggregator.Thickness = 3;
|
---|
217 | multiMaxAggregator.Style = DrawingStyle.Solid;
|
---|
218 | multiMaxAggregator.LineType = DataRowType.SingleValue;
|
---|
219 | multiMaxAggregator.AddWatch(row1);
|
---|
220 | multiMaxAggregator.AddWatch(row2);
|
---|
221 | model.AddDataRow(multiMaxAggregator);
|
---|
222 |
|
---|
223 | IAggregator multiMinAggregator = new MinAggregator();
|
---|
224 | multiMinAggregator.Label = "MultiMinAggregator";
|
---|
225 | multiMinAggregator.Color = Color.DarkRed;
|
---|
226 | multiMinAggregator.Thickness = 3;
|
---|
227 | multiMinAggregator.Style = DrawingStyle.Solid;
|
---|
228 | multiMinAggregator.LineType = DataRowType.SingleValue;
|
---|
229 | multiMinAggregator.AddWatch(row1);
|
---|
230 | multiMinAggregator.AddWatch(row2);
|
---|
231 | model.AddDataRow(multiMinAggregator);
|
---|
232 |
|
---|
233 | IAggregator multiLineAvgAggregator = new AvgLineAggregator();
|
---|
234 | multiLineAvgAggregator.Label = "MultiLineAvgAggregator";
|
---|
235 | multiLineAvgAggregator.Color = Color.Red;
|
---|
236 | multiLineAvgAggregator.Thickness = 4;
|
---|
237 | multiLineAvgAggregator.Style = DrawingStyle.Solid;
|
---|
238 | multiLineAvgAggregator.LineType = DataRowType.Normal;
|
---|
239 | multiLineAvgAggregator.AddWatch(row1);
|
---|
240 | multiLineAvgAggregator.AddWatch(row2);
|
---|
241 | multiLineAvgAggregator.AddValue(0);
|
---|
242 | model.AddDataRow(multiLineAvgAggregator);
|
---|
243 |
|
---|
244 | double i = 0;
|
---|
245 | double newY;
|
---|
246 |
|
---|
247 | Random rand = new Random();
|
---|
248 | while (!_shouldStop && i <= 24) {
|
---|
249 | i += 0.2;
|
---|
250 | newY = Math.Sin(i);
|
---|
251 | System.Console.WriteLine("working");
|
---|
252 | //row1.AddValue(rand.NextDouble() * 10);
|
---|
253 | row1.AddValue(newY * 10);
|
---|
254 | row2.AddValue(i*2-15);
|
---|
255 | System.Threading.Thread.Sleep(100);
|
---|
256 | }
|
---|
257 | Console.WriteLine("worker thread: terminating gracefully.");
|
---|
258 | }
|
---|
259 | public void RequestStop() {
|
---|
260 | _shouldStop = true;
|
---|
261 | }
|
---|
262 | // Volatile is used as hint to the compiler that this data
|
---|
263 | // member will be accessed by multiple threads.
|
---|
264 | private volatile bool _shouldStop;
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | [Test]
|
---|
269 | public void TestAggregator2() {
|
---|
270 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
271 |
|
---|
272 | // Create the thread object. This does not start the thread.
|
---|
273 | Worker workerObject = new Worker(model);
|
---|
274 | Thread workerThread = new Thread(workerObject.DoWork);
|
---|
275 |
|
---|
276 | // Start the worker thread.
|
---|
277 | workerThread.Start();
|
---|
278 |
|
---|
279 | f.ShowDialog();
|
---|
280 | workerObject.RequestStop();
|
---|
281 | }
|
---|
282 |
|
---|
283 |
|
---|
284 |
|
---|
285 | [Test]
|
---|
286 | public void TestAutoZoomInConstructor() {
|
---|
287 | IDataRow row1 = new DataRow();
|
---|
288 |
|
---|
289 | row1.Color = Color.Red;
|
---|
290 | row1.Thickness = 3;
|
---|
291 | row1.Style = DrawingStyle.Solid;
|
---|
292 |
|
---|
293 | model.AddDataRow(row1);
|
---|
294 |
|
---|
295 | row1.AddValue(10);
|
---|
296 | row1.AddValue(5);
|
---|
297 | row1.AddValue(7);
|
---|
298 | row1.AddValue(3);
|
---|
299 | row1.AddValue(10);
|
---|
300 | row1.AddValue(2);
|
---|
301 |
|
---|
302 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
303 | f.ShowDialog();
|
---|
304 | }
|
---|
305 |
|
---|
306 |
|
---|
307 | [Test]
|
---|
308 | public void TestSingleValueDataRows() {
|
---|
309 | LineChartTestForm f = new LineChartTestForm(model);
|
---|
310 |
|
---|
311 | IDataRow row1 = new DataRow();
|
---|
312 | IDataRow row2 = new DataRow();
|
---|
313 | IDataRow row3 = new DataRow();
|
---|
314 |
|
---|
315 | IDataRow row4 = new DataRow();
|
---|
316 | IDataRow row5 = new DataRow();
|
---|
317 | IDataRow row6 = new DataRow();
|
---|
318 |
|
---|
319 | row1.Color = Color.Red;
|
---|
320 | row2.Color = Color.Green;
|
---|
321 | row3.Color = Color.Blue;
|
---|
322 |
|
---|
323 | row4.Color = Color.DeepPink;
|
---|
324 | row5.Color = Color.Firebrick;
|
---|
325 | row6.Color = Color.DarkSlateGray;
|
---|
326 |
|
---|
327 | row1.Thickness = 3;
|
---|
328 | row2.Thickness = 4;
|
---|
329 | row3.Thickness = 5;
|
---|
330 |
|
---|
331 | row4.Thickness = 3;
|
---|
332 | row5.Thickness = 4;
|
---|
333 | row6.Thickness = 5;
|
---|
334 |
|
---|
335 | row1.Label = "SingleValue";
|
---|
336 | row2.Label = "Gertschi";
|
---|
337 | row3.Label = "Maxi";
|
---|
338 |
|
---|
339 | row4.Label = "Simon";
|
---|
340 | row5.Label = "klausmuellerwesternhagenunddierasperies";
|
---|
341 | row6.Label = "anyways";
|
---|
342 |
|
---|
343 | row1.Style = DrawingStyle.Solid;
|
---|
344 | row2.Style = DrawingStyle.Solid;
|
---|
345 | row3.Style = DrawingStyle.Dashed;
|
---|
346 |
|
---|
347 | row4.Style = DrawingStyle.Solid;
|
---|
348 | row5.Style = DrawingStyle.Solid;
|
---|
349 | row6.Style = DrawingStyle.Dashed;
|
---|
350 |
|
---|
351 | row1.LineType = DataRowType.SingleValue;
|
---|
352 | row2.LineType = DataRowType.SingleValue;
|
---|
353 | row1.AddValue(12);
|
---|
354 |
|
---|
355 | row2.AddValue(5);
|
---|
356 |
|
---|
357 |
|
---|
358 | row3.AddValue(2);
|
---|
359 | row3.AddValue(5);
|
---|
360 | row3.AddValue(9);
|
---|
361 | row3.AddValue(1);
|
---|
362 | row3.AddValue(3);
|
---|
363 |
|
---|
364 |
|
---|
365 | row4.AddValue(10);
|
---|
366 | row5.AddValue(11);
|
---|
367 | row6.AddValue(11);
|
---|
368 |
|
---|
369 | model.AddDataRow(row1);
|
---|
370 | model.AddDataRow(row2);
|
---|
371 | model.AddDataRow(row3);
|
---|
372 | model.AddDataRow(row4);
|
---|
373 | model.AddDataRow(row5);
|
---|
374 | model.AddDataRow(row6);
|
---|
375 |
|
---|
376 | f.ShowDialog();
|
---|
377 | }
|
---|
378 |
|
---|
379 |
|
---|
380 |
|
---|
381 | [Test]
|
---|
382 | public void TestMainForm() {
|
---|
383 | MainForm f = new MainForm();
|
---|
384 | f.ShowDialog();
|
---|
385 | }
|
---|
386 | }
|
---|
387 | }
|
---|