Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/BooleanExpressionTests.cs @ 16958

Last change on this file since 16958 was 14908, checked in by pkimmesw, 8 years ago

#2665 Removed "this" qualifier

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