-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Expression_Tests.cs
95 lines (89 loc) · 2.83 KB
/
Expression_Tests.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
namespace Common.BasicHelper.Math;
[TestClass()]
public class Expression_Tests
{
[TestMethod()]
public void Test_Expression()
{
var expr = (39 / 3) + (16 * 5) - ((24 * 24) + 5 + 7);
var tree = new Expression()
{
Type = CalculationType.Add,
Left = new()
{
Type = CalculationType.Division,
Left = Expression.FromValue(39),
Right = Expression.FromValue(3)
},
Right = new()
{
Type = CalculationType.Substraction,
Left = new()
{
Type = CalculationType.Multiply,
Left = Expression.FromValue(16),
Right = Expression.FromValue(5),
},
Right = new()
{
Type = CalculationType.Add,
Left = new()
{
Type = CalculationType.Power,
Left = Expression.FromValue(24),
Right = Expression.FromValue(2)
},
Right = new()
{
Type = CalculationType.Add,
Left = Expression.FromValue(5),
Right = Expression.FromValue(7)
}
}
}
};
Assert.AreEqual(expr, tree.Result);
}
[TestMethod()]
public void Test_ToString()
{
var expr = "(39 / 3) + (16 * 5) - ((24 ** 2) + 5 + 7)";
var tree = new Expression()
{
Type = CalculationType.Add,
Left = new()
{
Type = CalculationType.Division,
Left = Expression.FromValue(39),
Right = Expression.FromValue(3)
},
Right = new()
{
Type = CalculationType.Substraction,
Left = new()
{
Type = CalculationType.Multiply,
Left = Expression.FromValue(16),
Right = Expression.FromValue(5),
},
Right = new()
{
Type = CalculationType.Add,
Left = new()
{
Type = CalculationType.Power,
Left = Expression.FromValue(24),
Right = Expression.FromValue(2)
},
Right = new()
{
Type = CalculationType.Add,
Left = Expression.FromValue(5),
Right = Expression.FromValue(7)
}
}
}
};
Assert.AreEqual(expr, tree.ToString());
}
}