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