1
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2
|
using ServerApp.Predictor;
|
3
|
//
|
4
|
// Author: Roman Kalivoda
|
5
|
//
|
6
|
|
7
|
using System;
|
8
|
using System.Collections.Generic;
|
9
|
using System.Linq;
|
10
|
using System.Text;
|
11
|
using System.Threading.Tasks;
|
12
|
using ServerApp.WeatherPredictionParser;
|
13
|
using ServerApp.Parser.Parsers;
|
14
|
using ServerApp.Parser.InputData;
|
15
|
using ServerApp.Connection.XMLProtocolHandler;
|
16
|
using ServerApp.DataDownload;
|
17
|
using log4net.Config;
|
18
|
|
19
|
namespace ServerApp.Predictor.Tests
|
20
|
{
|
21
|
[TestClass()]
|
22
|
public class PredictionControllerTests
|
23
|
{
|
24
|
static PredictionController instance;
|
25
|
|
26
|
[AssemblyInitialize()]
|
27
|
public static void ClassInit(TestContext context)
|
28
|
{
|
29
|
// setup logging service
|
30
|
XmlConfigurator.Configure();
|
31
|
System.IO.Directory.CreateDirectory(@".\data");
|
32
|
DataDownloader dd = new DataDownloader(@".\data\dd\", "http://openstore.zcu.cz/", "OD_ZCU_{type}_{month}_{year}_{format}.zip", "http://wttr.in/Plzen,czechia?format=j1");
|
33
|
instance = new PredictionController(new JsonParser(dd, new CsvDataLoader()), new DataParser(dd));
|
34
|
|
35
|
dd.DownloadData(DataType.JIS, DataFormat.CSV, new DataDownload.Date(1, 2019), new DataDownload.Date(12, 2020));
|
36
|
dd.DownloadData(DataType.STROJE, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020));
|
37
|
dd.DownloadData(DataType.POCASI, DataFormat.CSV, new DataDownload.Date(1, 2017), new DataDownload.Date(12, 2020));
|
38
|
instance.Train();
|
39
|
}
|
40
|
|
41
|
[TestMethod()]
|
42
|
public void PredictSingleTimeWeatherTest()
|
43
|
{
|
44
|
Request request = new Request()
|
45
|
{
|
46
|
useEndDate = false,
|
47
|
useWeather = false,
|
48
|
start = new Connection.XMLProtocolHandler.Date()
|
49
|
{
|
50
|
day = DateTime.Now.Day,
|
51
|
month = DateTime.Now.Month,
|
52
|
year = DateTime.Now.Year,
|
53
|
hour = 10
|
54
|
}
|
55
|
};
|
56
|
Response actual = instance.Predict(request);
|
57
|
CollectionAssert.AllItemsAreInstancesOfType(actual.predicitons, typeof(Prediction));
|
58
|
Assert.AreEqual(1, actual.predicitons.Length);
|
59
|
}
|
60
|
|
61
|
[TestMethod()]
|
62
|
public void PredictStartEndWithinSingleDayTest()
|
63
|
{
|
64
|
Request request = new Request
|
65
|
{
|
66
|
useWeather = false,
|
67
|
temperature = -0,
|
68
|
wind = -0,
|
69
|
rain = -0,
|
70
|
weather = WeatherCondition.Sunny,
|
71
|
useEndDate = true,
|
72
|
start = new Connection.XMLProtocolHandler.Date
|
73
|
{
|
74
|
day = 11,
|
75
|
month = 6,
|
76
|
year = 2021,
|
77
|
hour = 7
|
78
|
},
|
79
|
end = new Connection.XMLProtocolHandler.Date
|
80
|
{
|
81
|
day = 11,
|
82
|
month = 6,
|
83
|
year = 2021,
|
84
|
hour = 12
|
85
|
}
|
86
|
};
|
87
|
Response actual = instance.Predict(request);
|
88
|
Assert.IsTrue(Math.Abs(actual.predicitons[0].dateTime.hour - request.start.hour) <= instance.Configuration.TimeResolution);
|
89
|
Assert.IsTrue(Math.Abs(actual.predicitons[actual.predicitons.Length - 1].dateTime.hour - request.end.hour) <= instance.Configuration.TimeResolution);
|
90
|
}
|
91
|
|
92
|
[TestMethod()]
|
93
|
public void PredictStartEndEqualTest()
|
94
|
{
|
95
|
Request request = new Request
|
96
|
{
|
97
|
useWeather = false,
|
98
|
temperature = -0,
|
99
|
wind = -0,
|
100
|
rain = -0,
|
101
|
weather = WeatherCondition.Sunny,
|
102
|
useEndDate = true,
|
103
|
start = new Connection.XMLProtocolHandler.Date
|
104
|
{
|
105
|
day = 11,
|
106
|
month = 6,
|
107
|
year = 2021,
|
108
|
hour = 7
|
109
|
},
|
110
|
end = new Connection.XMLProtocolHandler.Date
|
111
|
{
|
112
|
day = 11,
|
113
|
month = 6,
|
114
|
year = 2021,
|
115
|
hour = 7
|
116
|
}
|
117
|
};
|
118
|
Response actual = instance.Predict(request);
|
119
|
Assert.IsTrue(actual.predicitons.Length == 1);
|
120
|
}
|
121
|
|
122
|
[TestMethod()]
|
123
|
public void RollbackTest()
|
124
|
{
|
125
|
instance.Train();
|
126
|
int actual = instance.Rollback();
|
127
|
Assert.AreEqual(0, actual);
|
128
|
}
|
129
|
}
|
130
|
}
|