Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2895_PushGP_GenealogyAnalysis/HeuristicLab.Tests/Interpreter/Expressions/BooleanExpressionTests.cs @ 16752

Last change on this file since 16752 was 15771, checked in by bburlacu, 7 years ago

#2895: Add solution skeleton for PushGP with genealogy analysis.

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