[15771] | 1 | using System.Linq;
|
---|
| 2 | using HeuristicLab.Problems.ProgramSynthesis;
|
---|
| 3 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
[15017] | 4 |
|
---|
[15771] | 5 | namespace HeuristicLab.Tests.Interpreter.Expressions {
|
---|
[15017] | 6 | [TestClass]
|
---|
| 7 | public class CharExpressionTests : CommonTests<char> {
|
---|
| 8 | protected override string TypeName { get { return "CHAR"; } }
|
---|
| 9 |
|
---|
| 10 | protected override IPushStack<char> Stack { get { return interpreter.CharStack; } }
|
---|
| 11 |
|
---|
| 12 | protected override char[] GetValues(int count) {
|
---|
| 13 | return Enumerable
|
---|
| 14 | .Range(0, count)
|
---|
| 15 | .Select(_ => interpreter.Configuration.ErcOptions.CharErcOptions.GetErcValue(interpreter.Random))
|
---|
| 16 | .ToArray();
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | protected override void CheckOtherStacksAreEmpty() {
|
---|
| 20 | TestStackCounts(charStack: null);
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | [TestMethod]
|
---|
| 24 | [TestProperty("Time", "Short")]
|
---|
| 25 | [TestCategory("ExpressionTest")]
|
---|
| 26 | [TestCategory("CharExpressionTest")]
|
---|
| 27 | public void TestIsWhitespace() {
|
---|
| 28 | interpreter.CharStack.Push(' ', '_');
|
---|
| 29 | interpreter.Run(new CharIsWhitespaceExpression());
|
---|
| 30 | interpreter.Run(new CharIsWhitespaceExpression());
|
---|
| 31 |
|
---|
| 32 | Assert.IsTrue(interpreter.BooleanStack[0]);
|
---|
| 33 | Assert.IsFalse(interpreter.BooleanStack[1]);
|
---|
| 34 | TestStackCounts(booleanStack: 2);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | [TestMethod]
|
---|
| 38 | [TestProperty("Time", "Short")]
|
---|
| 39 | [TestCategory("ExpressionTest")]
|
---|
| 40 | [TestCategory("CharExpressionTest")]
|
---|
| 41 | public void TestIsLetter() {
|
---|
| 42 | interpreter.CharStack.Push('a', '_');
|
---|
| 43 | interpreter.Run(new CharIsLetterExpression());
|
---|
| 44 | interpreter.Run(new CharIsLetterExpression());
|
---|
| 45 |
|
---|
| 46 | Assert.IsTrue(interpreter.BooleanStack[0]);
|
---|
| 47 | Assert.IsFalse(interpreter.BooleanStack[1]);
|
---|
| 48 | TestStackCounts(booleanStack: 2);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | [TestMethod]
|
---|
| 52 | [TestProperty("Time", "Short")]
|
---|
| 53 | [TestCategory("ExpressionTest")]
|
---|
| 54 | [TestCategory("CharExpressionTest")]
|
---|
| 55 | public void TestIsDigit() {
|
---|
| 56 | interpreter.CharStack.Push('1', 'a');
|
---|
| 57 | interpreter.Run(new CharIsDigitExpression());
|
---|
| 58 | interpreter.Run(new CharIsDigitExpression());
|
---|
| 59 |
|
---|
| 60 | Assert.IsTrue(interpreter.BooleanStack[0]);
|
---|
| 61 | Assert.IsFalse(interpreter.BooleanStack[1]);
|
---|
| 62 | TestStackCounts(booleanStack: 2);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | [TestMethod]
|
---|
| 66 | [TestProperty("Time", "Short")]
|
---|
| 67 | [TestCategory("ExpressionTest")]
|
---|
| 68 | [TestCategory("CharExpressionTest")]
|
---|
| 69 | public void TestFromInteger() {
|
---|
| 70 | interpreter.IntegerStack.Push(1, -1, 129);
|
---|
| 71 | interpreter.Run(new CharFromIntegerExpression());
|
---|
| 72 | interpreter.Run(new CharFromIntegerExpression());
|
---|
| 73 | interpreter.Run(new CharFromIntegerExpression());
|
---|
| 74 |
|
---|
| 75 | Assert.AreEqual(0x01, interpreter.CharStack[0]);
|
---|
| 76 | Assert.AreEqual(0x01, interpreter.CharStack[1]);
|
---|
| 77 | Assert.AreEqual(0x01, interpreter.CharStack[2]);
|
---|
| 78 | TestStackCounts(charStack: 3);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | [TestMethod]
|
---|
| 82 | [TestProperty("Time", "Short")]
|
---|
| 83 | [TestCategory("ExpressionTest")]
|
---|
| 84 | [TestCategory("CharExpressionTest")]
|
---|
| 85 | public void TestFromFloat() {
|
---|
| 86 | interpreter.FloatStack.Push(1.5, -1.5, 129.5);
|
---|
| 87 | interpreter.Run(new CharFromFloatExpression());
|
---|
| 88 | interpreter.Run(new CharFromFloatExpression());
|
---|
| 89 | interpreter.Run(new CharFromFloatExpression());
|
---|
| 90 |
|
---|
| 91 | Assert.AreEqual(0x01, interpreter.CharStack[0]);
|
---|
| 92 | Assert.AreEqual(0x01, interpreter.CharStack[1]);
|
---|
| 93 | Assert.AreEqual(0x01, interpreter.CharStack[2]);
|
---|
| 94 | TestStackCounts(charStack: 3);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | [TestMethod]
|
---|
| 98 | [TestProperty("Time", "Short")]
|
---|
| 99 | [TestCategory("ExpressionTest")]
|
---|
| 100 | [TestCategory("CharExpressionTest")]
|
---|
| 101 | public void TestAllFromString() {
|
---|
| 102 | interpreter.StringStack.Push("test");
|
---|
| 103 | interpreter.Run(new CharAllFromStringExpression());
|
---|
| 104 |
|
---|
| 105 | Assert.AreEqual('t', interpreter.CharStack[0]);
|
---|
| 106 | Assert.AreEqual('e', interpreter.CharStack[1]);
|
---|
| 107 | Assert.AreEqual('s', interpreter.CharStack[2]);
|
---|
| 108 | Assert.AreEqual('t', interpreter.CharStack[3]);
|
---|
| 109 | TestStackCounts(charStack: 4);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | }
|
---|