1 |
0d31f7e0
|
Roman Kalivoda
|
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 System.Text.RegularExpressions;
|
13 |
|
|
|
14 |
|
|
namespace ServerApp.Predictor.Tests
|
15 |
|
|
{
|
16 |
|
|
[TestClass()]
|
17 |
|
|
public class NaiveBayesClassifierTests
|
18 |
|
|
{
|
19 |
|
|
static IPredictor predictor;
|
20 |
|
|
|
21 |
|
|
static readonly List<ModelInput> trainInput = new()
|
22 |
|
|
{
|
23 |
|
|
new ModelInput
|
24 |
|
|
{
|
25 |
|
|
Label = "10%",
|
26 |
|
|
Temp = 12,
|
27 |
|
|
Hour = 7,
|
28 |
|
|
Rain = 10,
|
29 |
|
|
Time = DateTime.Now,
|
30 |
|
|
Wind = 10
|
31 |
|
|
},
|
32 |
|
|
new ModelInput
|
33 |
|
|
{
|
34 |
|
|
Label = "100%",
|
35 |
|
|
Temp = 32,
|
36 |
|
|
Hour = 7,
|
37 |
|
|
Rain = 0,
|
38 |
|
|
Time = DateTime.Now,
|
39 |
|
|
Wind = 70
|
40 |
|
|
},
|
41 |
|
|
new ModelInput
|
42 |
|
|
{
|
43 |
|
|
Label = "90%",
|
44 |
|
|
Temp = 32,
|
45 |
|
|
Hour = 15,
|
46 |
|
|
Rain = 20,
|
47 |
|
|
Time = DateTime.Now,
|
48 |
|
|
Wind = 50
|
49 |
|
|
},
|
50 |
|
|
new ModelInput
|
51 |
|
|
{
|
52 |
|
|
Label = "70%",
|
53 |
|
|
Temp = 32,
|
54 |
|
|
Hour = 18,
|
55 |
|
|
Rain = 0,
|
56 |
|
|
Time = DateTime.Now,
|
57 |
|
|
Wind = 70
|
58 |
|
|
},
|
59 |
|
|
new ModelInput
|
60 |
|
|
{
|
61 |
|
|
Label = "30%",
|
62 |
|
|
Temp = 6,
|
63 |
|
|
Hour = 10,
|
64 |
|
|
Rain = 70,
|
65 |
|
|
Time = DateTime.Now,
|
66 |
|
|
Wind = 30
|
67 |
|
|
}
|
68 |
|
|
};
|
69 |
|
|
|
70 |
|
|
[ClassInitialize()]
|
71 |
|
|
public static void SetUpClass(TestContext context)
|
72 |
|
|
{
|
73 |
|
|
predictor = new NaiveBayesClassifier();
|
74 |
|
|
predictor.Fit(trainInput);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
[TestMethod()]
|
78 |
|
|
public void PredictTest()
|
79 |
|
|
{
|
80 |
|
|
string actual = predictor.Predict(new ModelInput
|
81 |
|
|
{
|
82 |
|
|
Temp = 19,
|
83 |
|
|
Hour = 17,
|
84 |
|
|
Rain = 20,
|
85 |
|
|
Time = DateTime.Now,
|
86 |
|
|
Wind = 7
|
87 |
|
|
});
|
88 |
|
|
StringAssert.Matches(actual, new Regex(@"\d0%"));
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
}
|