Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Tests/Interpreter/Expressions/BooleanExpressionTests.cs @ 14906

Last change on this file since 14906 was 14834, checked in by pkimmesw, 8 years ago

#2665 LexicaseSelector, Performance improvements, UI Fixes, Debugger only shows used stacks, fixed Debugger stepping, Added vector expressions, ERCOptions,

File size: 4.1 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 this.interpreter.BooleanStack;
22      }
23    }
24
25    [TestMethod]
26    [TestProperty("Time", "Short")]
27    [TestCategory("ExpressionTest")]
28    [TestCategory("BooleanExpressionTest")]
29    public void TestAnd() {
30      this.interpreter.BooleanStack.Push(true, false);
31      this.interpreter.Run(new BooleanAndExpression());
32
33      Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
34
35      this.TestStackCounts(booleanStack: 1);
36    }
37
38    [TestMethod]
39    [TestProperty("Time", "Short")]
40    [TestCategory("ExpressionTest")]
41    [TestCategory("BooleanExpressionTest")]
42    public void TestAndWithInsufficientArguments() {
43      this.TestWithInsufficientArguments("AND", 1);
44    }
45
46    [TestMethod]
47    [TestProperty("Time", "Short")]
48    [TestCategory("ExpressionTest")]
49    [TestCategory("BooleanExpressionTest")]
50    public void TestOr() {
51      this.interpreter.BooleanStack.Push(true, false);
52      this.interpreter.Run(new BooleanOrExpression());
53
54      Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
55
56      this.TestStackCounts(booleanStack: 1);
57    }
58
59    [TestMethod]
60    [TestProperty("Time", "Short")]
61    [TestCategory("ExpressionTest")]
62    [TestCategory("BooleanExpressionTest")]
63    public void TestOrWithInsufficientArguments() {
64      this.TestWithInsufficientArguments("OR", 1);
65    }
66
67    [TestMethod]
68    [TestProperty("Time", "Short")]
69    [TestCategory("ExpressionTest")]
70    [TestCategory("BooleanExpressionTest")]
71    public void TestNot() {
72      this.interpreter.BooleanStack.Push(true);
73      this.interpreter.Run(new BooleanNotExpression());
74
75      Assert.AreEqual(false, this.interpreter.BooleanStack.Top);
76
77      this.TestStackCounts(booleanStack: 1);
78    }
79
80    [TestMethod]
81    [TestProperty("Time", "Short")]
82    [TestCategory("ExpressionTest")]
83    [TestCategory("BooleanExpressionTest")]
84    public void TestNotWithInsufficientArguments() {
85      this.TestWithInsufficientArguments("NOT");
86    }
87
88    [TestMethod]
89    [TestProperty("Time", "Short")]
90    [TestCategory("ExpressionTest")]
91    [TestCategory("BooleanExpressionTest")]
92    public void TestFromFloat() {
93      this.interpreter.FloatStack.Push(2.0);
94      this.interpreter.Run(new BooleanFromFloatExpression());
95
96      Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
97
98      this.TestStackCounts(booleanStack: 1);
99    }
100
101    [TestMethod]
102    [TestProperty("Time", "Short")]
103    [TestCategory("ExpressionTest")]
104    [TestCategory("BooleanExpressionTest")]
105    public void TestFromFloatWithInsufficientArguments() {
106      this.TestWithInsufficientArguments("FROMFLOAT");
107    }
108
109    [TestMethod]
110    [TestProperty("Time", "Short")]
111    [TestCategory("ExpressionTest")]
112    [TestCategory("BooleanExpressionTest")]
113    public void TestFromInteger() {
114      this.interpreter.IntegerStack.Push(2);
115      this.interpreter.Run(new BooleanFromIntegerExpression());
116
117      Assert.AreEqual(true, this.interpreter.BooleanStack.Top);
118
119      this.TestStackCounts(booleanStack: 1);
120    }
121
122    [TestMethod]
123    [TestProperty("Time", "Short")]
124    [TestCategory("ExpressionTest")]
125    [TestCategory("BooleanExpressionTest")]
126    public void TestFromIntegerWithInsufficientArguments() {
127      this.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      this.TestStackCounts(booleanStack: null);
140    }
141  }
142}
Note: See TracBrowser for help on using the repository browser.