Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2665 Full Push 3.0 instruction set and tests; Added first benchmark test (count odds) for random walk tests;

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