1 | namespace HeuristicLab.Tests.Interpreter.Expressions
|
---|
2 | {
|
---|
3 | using HeuristicLab.Algorithms.PushGP.Expressions;
|
---|
4 | using HeuristicLab.Algorithms.PushGP.Stack;
|
---|
5 |
|
---|
6 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
7 |
|
---|
8 | [TestClass]
|
---|
9 | public class BooleanExpressionTests : CommonTests<bool>
|
---|
10 | {
|
---|
11 | protected override string TypeName
|
---|
12 | {
|
---|
13 | get
|
---|
14 | {
|
---|
15 | return "BOOLEAN";
|
---|
16 | }
|
---|
17 | }
|
---|
18 |
|
---|
19 | protected override IStack<bool> Stack
|
---|
20 | {
|
---|
21 | get
|
---|
22 | {
|
---|
23 | return this.interpreter.BooleanStack;
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | [TestMethod]
|
---|
28 | [TestProperty("Time", "Short")]
|
---|
29 | [TestCategory("ExpressionTest")]
|
---|
30 | [TestCategory("BooleanExpressionTest")]
|
---|
31 | public void TestAnd()
|
---|
32 | {
|
---|
33 | this.interpreter.BooleanStack.Push(true, false);
|
---|
34 | this.interpreter.Interpret(new BooleanAndExpression());
|
---|
35 |
|
---|
36 | Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
|
---|
37 |
|
---|
38 | this.TestStackCounts(booleanStack: 1);
|
---|
39 | }
|
---|
40 |
|
---|
41 | [TestMethod]
|
---|
42 | [TestProperty("Time", "Short")]
|
---|
43 | [TestCategory("ExpressionTest")]
|
---|
44 | [TestCategory("BooleanExpressionTest")]
|
---|
45 | public void TestAndWithInsufficientArguments()
|
---|
46 | {
|
---|
47 | this.TestWithInsufficientArguments("AND", 1);
|
---|
48 | }
|
---|
49 |
|
---|
50 | [TestMethod]
|
---|
51 | [TestProperty("Time", "Short")]
|
---|
52 | [TestCategory("ExpressionTest")]
|
---|
53 | [TestCategory("BooleanExpressionTest")]
|
---|
54 | public void TestOr()
|
---|
55 | {
|
---|
56 | this.interpreter.BooleanStack.Push(true, false);
|
---|
57 | this.interpreter.Interpret(new BooleanOrExpression());
|
---|
58 |
|
---|
59 | Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
|
---|
60 |
|
---|
61 | this.TestStackCounts(booleanStack: 1);
|
---|
62 | }
|
---|
63 |
|
---|
64 | [TestMethod]
|
---|
65 | [TestProperty("Time", "Short")]
|
---|
66 | [TestCategory("ExpressionTest")]
|
---|
67 | [TestCategory("BooleanExpressionTest")]
|
---|
68 | public void TestOrWithInsufficientArguments()
|
---|
69 | {
|
---|
70 | this.TestWithInsufficientArguments("OR", 1);
|
---|
71 | }
|
---|
72 |
|
---|
73 | [TestMethod]
|
---|
74 | [TestProperty("Time", "Short")]
|
---|
75 | [TestCategory("ExpressionTest")]
|
---|
76 | [TestCategory("BooleanExpressionTest")]
|
---|
77 | public void TestNot()
|
---|
78 | {
|
---|
79 | this.interpreter.BooleanStack.Push(true);
|
---|
80 | this.interpreter.Interpret(new BooleanNotExpression());
|
---|
81 |
|
---|
82 | Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
|
---|
83 |
|
---|
84 | this.TestStackCounts(booleanStack: 1);
|
---|
85 | }
|
---|
86 |
|
---|
87 | [TestMethod]
|
---|
88 | [TestProperty("Time", "Short")]
|
---|
89 | [TestCategory("ExpressionTest")]
|
---|
90 | [TestCategory("BooleanExpressionTest")]
|
---|
91 | public void TestNotWithInsufficientArguments()
|
---|
92 | {
|
---|
93 | this.TestWithInsufficientArguments("NOT");
|
---|
94 | }
|
---|
95 |
|
---|
96 | [TestMethod]
|
---|
97 | [TestProperty("Time", "Short")]
|
---|
98 | [TestCategory("ExpressionTest")]
|
---|
99 | [TestCategory("BooleanExpressionTest")]
|
---|
100 | public void TestFromFloat()
|
---|
101 | {
|
---|
102 | this.interpreter.FloatStack.Push(2.0);
|
---|
103 | this.interpreter.Interpret(new BooleanFromFloatExpression());
|
---|
104 |
|
---|
105 | Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
|
---|
106 |
|
---|
107 | this.TestStackCounts(booleanStack: 1);
|
---|
108 | }
|
---|
109 |
|
---|
110 | [TestMethod]
|
---|
111 | [TestProperty("Time", "Short")]
|
---|
112 | [TestCategory("ExpressionTest")]
|
---|
113 | [TestCategory("BooleanExpressionTest")]
|
---|
114 | public void TestFromFloatWithInsufficientArguments()
|
---|
115 | {
|
---|
116 | this.TestWithInsufficientArguments("FROMFLOAT");
|
---|
117 | }
|
---|
118 |
|
---|
119 | [TestMethod]
|
---|
120 | [TestProperty("Time", "Short")]
|
---|
121 | [TestCategory("ExpressionTest")]
|
---|
122 | [TestCategory("BooleanExpressionTest")]
|
---|
123 | public void TestFromInteger()
|
---|
124 | {
|
---|
125 | this.interpreter.IntegerStack.Push(2);
|
---|
126 | this.interpreter.Interpret(new BooleanFromIntegerExpression());
|
---|
127 |
|
---|
128 | Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
|
---|
129 |
|
---|
130 | this.TestStackCounts(booleanStack: 1);
|
---|
131 | }
|
---|
132 |
|
---|
133 | [TestMethod]
|
---|
134 | [TestProperty("Time", "Short")]
|
---|
135 | [TestCategory("ExpressionTest")]
|
---|
136 | [TestCategory("BooleanExpressionTest")]
|
---|
137 | public void TestFromIntegerWithInsufficientArguments()
|
---|
138 | {
|
---|
139 | this.TestWithInsufficientArguments("FROMINTEGER");
|
---|
140 | }
|
---|
141 |
|
---|
142 | protected override bool[] GetValues(int count)
|
---|
143 | {
|
---|
144 | var values = new bool[count];
|
---|
145 |
|
---|
146 | for (var i = 0; i < count; i++) values[i] = i % 2 == 0;
|
---|
147 |
|
---|
148 | return values;
|
---|
149 | }
|
---|
150 |
|
---|
151 | protected override void CheckOtherStacksAreEmpty()
|
---|
152 | {
|
---|
153 | this.TestStackCounts(booleanStack: null);
|
---|
154 | }
|
---|
155 | }
|
---|
156 | } |
---|