Projekt

Obecné

Profil

Stáhnout (15.8 KB) Statistiky
| Větev: | Tag: | Revize:
1 8a243ab2 A-Konig
using Microsoft.VisualStudio.TestTools.UnitTesting;
2
using System;
3
using ServerApp.Parser.Parsers;
4
using System.Collections.Generic;
5
using ServerApp.Parser.OutputInfo;
6
using Moq;
7
using ServerApp.Parser.InputData;
8
9 847434c6 Roman Kalivoda
namespace ServerAppFunctionalTests.ParserTests
10 8a243ab2 A-Konig
{
11
    /// <summary>
12
    /// Summary description for WeatherParserTesting
13
    /// </summary>
14
    [TestClass]
15
    public class WeatherParserTesting
16
    {
17
18
        #region Weather parser
19
20
        #region Parse days
21
        [TestMethod]
22
        public void ParseWeatherDayOne()
23
        {
24
            string path = "";
25
            List<WeatherInstance> data = new List<WeatherInstance>();
26
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
27
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 7, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
28
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 10, 3, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
29
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 12, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
30
31
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
32
            dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
33
34
            WeatherParser target = new WeatherParser(dl.Object);
35
            PrivateObject obj = new PrivateObject(target);
36
37
            List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
38
39
            Assert.AreEqual(1, retVal.Count);
40
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 8, 50, 1.25, 10_000, 18 - 7), retVal[0]);
41
        }
42
43
        [TestMethod]
44
        public void ParseWeatherDayOneFiltering()
45
        {
46
            string path = "";
47
            List<WeatherInstance> data = new List<WeatherInstance>();
48
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
49
50
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 7, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
51
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 10, 3, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
52
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 12, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
53
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 13, 0, 0), 12, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
54
55
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
56
57
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
58
            dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
59
60
            WeatherParser target = new WeatherParser(dl.Object);
61
            PrivateObject obj = new PrivateObject(target);
62
63
            List<ActivityInfo> jis = new List<ActivityInfo>();
64
            List<ActivityInfo> pc = new List<ActivityInfo>();
65
66
            List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsDays", path, new DateTime(2000, 1, 1, 9, 0, 0), new DateTime(2000, 1, 1, 15, 0, 0));
67
68
            Assert.AreEqual(1, retVal.Count);
69
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 9.75, 25, 1.75, 10_000, 18 - 7), retVal[0]);
70
        }
71
72
        [TestMethod]
73
        public void ParseWeatherDayTwo()
74
        {
75
            string path = "";
76
            List<WeatherInstance> data = new List<WeatherInstance>();
77
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
78
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
79
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 3, 3, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
80
81
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 12, 0, 0), 5, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
82
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
83
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
84
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
85
86
87
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
88
            dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
89
90
            WeatherParser target = new WeatherParser(dl.Object);
91
            PrivateObject obj = new PrivateObject(target);
92
93
            List<ActivityInfo> jis = new List<ActivityInfo>();
94
            List<ActivityInfo> pc = new List<ActivityInfo>();
95
96
            List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsDays", path, new DateTime(2000, 1, 1), new DateTime(2001, 1, 1));
97
98
            Assert.AreEqual(2, retVal.Count);
99
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 6, 100, 1, 10_000, 18 - 7), retVal[0]);
100
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 7, 0, 0), 10, 25, 2, 10_000, 18 - 7), retVal[1]);
101
        }
102
103
        [TestMethod]
104
        public void ParseWeatherDayTwoFiltering()
105
        {
106
            string path = "";
107
            List<WeatherInstance> data = new List<WeatherInstance>();
108
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
109
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
110
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 3, 3, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
111
112
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 12, 0, 0), 5, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
113
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
114
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
115
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
116
117
118
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
119
            dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
120
121
            WeatherParser target = new WeatherParser(dl.Object);
122
            PrivateObject obj = new PrivateObject(target);
123
124
            List<ActivityInfo> jis = new List<ActivityInfo>();
125
            List<ActivityInfo> pc = new List<ActivityInfo>();
126
127
            List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsDays", path, new DateTime(2000, 1, 1, 8, 0, 0), new DateTime(2000, 1, 1, 11, 0, 0));
128
129
            Assert.AreEqual(1, retVal.Count);
130
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 6, 100, 1, 10_000, 18 - 7), retVal[0]);
131
            //Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 7, 0, 0), 10, 25, 2, 10_000, 18 - 7), retVal[1]);
132
        }
133
        #endregion
134
135
        #region Parse hours
136
        [TestMethod]
137
        public void ParseWeatherHourOne()
138
        {
139
            string path = "";
140
            List<WeatherInstance> data = new List<WeatherInstance>();
141
142
            // day 1
143
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
144
145
146
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
147
            dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
148
149
            WeatherParser target = new WeatherParser(dl.Object);
150
            PrivateObject obj = new PrivateObject(target);
151
152
            List<ActivityInfo> jis = new List<ActivityInfo>();
153
            List<ActivityInfo> pc = new List<ActivityInfo>();
154
155
            List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 8, 0, 0), new DateTime(2001, 1, 1, 11, 0, 0));
156
157
            Assert.AreEqual(1, retVal.Count);
158
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 5, 100, 0, (double)0, 2), retVal[0]);
159
        }
160
161
        [TestMethod]
162
        public void ParseWeatherHourMultiple()
163
        {
164
            string path = "";
165
            List<WeatherInstance> data = new List<WeatherInstance>();
166
167
            // day 1
168
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
169
170
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
171
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 3, 3, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
172
173
            // day 2
174
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 12, 0, 0), 5, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Sunny) / 1000));
175
176
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
177
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
178
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 15, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
179
180
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
181
182
183
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
184
            dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
185
186
            WeatherParser target = new WeatherParser(dl.Object);
187
            PrivateObject obj = new PrivateObject(target);
188
189
            List<ActivityInfo> jis = new List<ActivityInfo>();
190
            List<ActivityInfo> pc = new List<ActivityInfo>();
191
192
            List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 8, 0, 0), new DateTime(2001, 1, 1, 11, 0, 0));
193
194
            Assert.AreEqual(5, retVal.Count);
195
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 7, 0, 0), 5, 100, 0, (double)0, 2), retVal[0]);
196
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 9, 0, 0), 6.5, 100, 1.5, 10_000, 2), retVal[1]);
197
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 11, 0, 0), 5, 0, 2, 60_000, 2), retVal[2]);
198
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 13, 0, 0), 10, 25, 2, 10_000, 2), retVal[3]);
199
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 15, 0, 0), 15, 40, 2, 10_000, 2), retVal[4]);
200
        }
201
202
203
        [TestMethod]
204
        public void ParseWeatherHourFiltering()
205
        {
206
            string path = "";
207
            List<WeatherInstance> data = new List<WeatherInstance>();
208
209
            // day 1
210
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
211
212
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
213
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 10, 0, 0), 3, 3, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
214
215
            // day 2
216
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 12, 0, 0), 5, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Sunny) / 1000));
217
218
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
219
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
220
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 13, 15, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
221
222
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
223
224
225
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
226
            dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
227
228
            WeatherParser target = new WeatherParser(dl.Object);
229
            PrivateObject obj = new PrivateObject(target);
230
231
            List<ActivityInfo> jis = new List<ActivityInfo>();
232
            List<ActivityInfo> pc = new List<ActivityInfo>();
233
234
            List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 9, 0, 0), new DateTime(2000, 2, 1, 13, 0, 0));
235
236
            Assert.AreEqual(3, retVal.Count);
237
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 1, 1, 9, 0, 0), 6.5, 100, 1.5, 10_000, 2), retVal[0]);
238
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 11, 0, 0), 5, 0, 2, 60_000, 2), retVal[1]);
239
            Assert.AreEqual(new WeatherInfo(new DateTime(2000, 2, 1, 13, 0, 0), 10, 33, 2, 10_000, 2), retVal[2]);
240
        }
241
242
        [TestMethod]
243
        public void ParseWeatherHourNone()
244
        {
245
            string path = "";
246
            List<WeatherInstance> data = new List<WeatherInstance>();
247
248
            // day 1
249
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 8, 0, 0), 5, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
250
            data.Add(new WeatherInstance(new DateTime(2000, 1, 1, 9, 0, 0), 10, 0, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Dark) / 1000));
251
252
            // day 2
253
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 16, 0, 0), 10, 2, 0, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
254
            data.Add(new WeatherInstance(new DateTime(2000, 2, 1, 17, 0, 0), 15, 2, 1, ValueToConditions.TransferConditionsToLux(WeatherConditions.Overcast) / 1000));
255
256
257
            Mock<IDataLoader> dl = new Mock<IDataLoader>();
258
            dl.Setup(m => m.LoadWeatherFile(path)).Returns(data);
259
260
            WeatherParser target = new WeatherParser(dl.Object);
261
            PrivateObject obj = new PrivateObject(target);
262
263
            List<ActivityInfo> jis = new List<ActivityInfo>();
264
            List<ActivityInfo> pc = new List<ActivityInfo>();
265
266
            List<WeatherInfo> retVal = (List<WeatherInfo>)obj.Invoke("ProcessOneWeatherFileAsIntervals", path, 2, new DateTime(2000, 1, 1, 10, 0, 0), new DateTime(2000, 2, 1, 15, 0, 0));
267
268
            Assert.AreEqual(0, retVal.Count);
269
        }
270
        #endregion
271
272
        #endregion
273
    }
274
}