-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathID3Tests.cs
More file actions
75 lines (69 loc) · 2.73 KB
/
Copy pathID3Tests.cs
File metadata and controls
75 lines (69 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Collections.Generic;
using AlgorithmsAndDataStructures.DataStructures.DecisionTree;
using Xunit;
namespace AlgorithmsAndDataStructures.Tests.DataStructures.DecisionTree;
public class Id3Tests
{
[Fact]
public void Base()
{
var sut = new Id3();
var example1 = new Dictionary<string, string>
{
{ "outlook", "sunny" },
{ "humidity", "high" },
{ "windy", "false" },
{ "class", "N" }
};
var example2 = new Dictionary<string, string>
{
{ "outlook", "overcast" },
{ "humidity", "high" },
{ "windy", "false" },
{ "class", "P" }
};
var example3 = new Dictionary<string, string>
{
{ "outlook", "rain" },
{ "humidity", "high" },
{ "windy", "false" },
{ "class", "P" }
};
var example4 = new Dictionary<string, string>
{
{ "outlook", "sunny" },
{ "humidity", "normal" },
{ "windy", "false" },
{ "class", "P" }
};
var example5 = new Dictionary<string, string>
{
{ "outlook", "rain" },
{ "humidity", "high" },
{ "windy", "true" },
{ "class", "N" }
};
var example6 = new Dictionary<string, string>
{
{ "outlook", "rain" },
{ "humidity", "normal" },
{ "windy", "true" },
{ "class", "N" }
};
var examples = new[] { example1, example2, example3, example4, example5, example6 };
var attributes = new Dictionary<string, List<string>>();
attributes.Add("outlook", new List<string> { "sunny", "rain", "overcast" });
attributes.Add("humidity", new List<string> { "high", "normal" });
attributes.Add("windy", new List<string> { "true", "false" });
var decisionTree = sut.CreateDecisionTree(examples, "class", attributes);
Assert.Equal("windy", decisionTree.TestAttributeName);
Assert.Equal("true", decisionTree.Children[0].BranchForValue);
Assert.Equal("N", decisionTree.Children[0].TargetAttribute.Value);
Assert.Equal("false", decisionTree.Children[1].BranchForValue);
Assert.Equal("outlook", decisionTree.Children[1].TestAttributeName);
Assert.Equal("sunny", decisionTree.Children[1].Children[0].BranchForValue);
Assert.Equal("rain", decisionTree.Children[1].Children[1].BranchForValue);
Assert.Equal("P", decisionTree.Children[1].Children[1].TargetAttribute.Value);
Assert.Equal("overcast", decisionTree.Children[1].Children[2].BranchForValue);
}
}