Projekt

Obecné

Profil

Stáhnout (4.44 KB) Statistiky
| Větev: | Tag: | Revize:
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
        }
39

    
40
        [TestMethod()]
41
        public void PredictSingleTimeWeatherTest()
42
        {
43
            Request request = new Request()
44
            {
45
                useEndDate = false,
46
                useWeather = false,
47
                start = new Connection.XMLProtocolHandler.Date()
48
                {
49
                    day = DateTime.Now.Day,
50
                    month = DateTime.Now.Month,
51
                    year = DateTime.Now.Year,
52
                    hour = 10
53
                }
54
            };
55
            Response actual = instance.Predict(request);
56
            CollectionAssert.AllItemsAreInstancesOfType(actual.predicitons, typeof(Prediction));
57
            Assert.AreEqual(1, actual.predicitons.Length);
58
        }
59

    
60
        [TestMethod()]
61
        public void PredictStartEndWithinSingleDayTest()
62
        {
63
            Request request = new Request
64
            {
65
                useWeather = false,
66
                temperature = -0,
67
                wind = -0,
68
                rain = -0,
69
                weather = WeatherCondition.Sunny,
70
                useEndDate = true,
71
                start = new Connection.XMLProtocolHandler.Date
72
                {
73
                    day = 11,
74
                    month = 6,
75
                    year = 2021,
76
                    hour = 7
77
                },
78
                end = new Connection.XMLProtocolHandler.Date
79
                {
80
                    day = 11,
81
                    month = 6,
82
                    year = 2021,
83
                    hour = 12
84
                }
85
            };
86
            Response actual = instance.Predict(request);
87
            Assert.IsTrue(Math.Abs(actual.predicitons[0].dateTime.hour - request.start.hour) <= instance.Configuration.TimeResolution);
88
            Assert.IsTrue(Math.Abs(actual.predicitons[actual.predicitons.Length - 1].dateTime.hour - request.end.hour) <= instance.Configuration.TimeResolution);
89
        }
90

    
91
        [TestMethod()]
92
        public void PredictStartEndEqualTest()
93
        {
94
            Request request = new Request
95
            {
96
                useWeather = false,
97
                temperature = -0,
98
                wind = -0,
99
                rain = -0,
100
                weather = WeatherCondition.Sunny,
101
                useEndDate = true,
102
                start = new Connection.XMLProtocolHandler.Date
103
                {
104
                    day = 11,
105
                    month = 6,
106
                    year = 2021,
107
                    hour = 7
108
                },
109
                end = new Connection.XMLProtocolHandler.Date
110
                {
111
                    day = 11,
112
                    month = 6,
113
                    year = 2021,
114
                    hour = 7
115
                }
116
            };
117
            Response actual = instance.Predict(request);
118
            Assert.IsTrue(actual.predicitons.Length == 1);
119
        }
120

    
121
        [TestMethod()]
122
        public void RollbackTest()
123
        {
124
            instance.Train();
125
            int actual = instance.Rollback();
126
            Assert.AreEqual(0, actual);
127
        }
128
    }
129
}
    (1-1/1)