1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
---|
2 |
|
---|
3 | namespace HeuristicLab.Tests.HeuristicLabAlgorithmsPushGP.Expressions
|
---|
4 | {
|
---|
5 | [TestClass]
|
---|
6 | public class IntegerExpressionTests : InterpreterTest
|
---|
7 | {
|
---|
8 | [TestMethod]
|
---|
9 | public void TestAdd()
|
---|
10 | {
|
---|
11 | var code = "5 5 INTEGER.+";
|
---|
12 |
|
---|
13 | interpreter.Interprete(code);
|
---|
14 |
|
---|
15 | Assert.AreEqual(10, interpreter.IntegerStack.Top);
|
---|
16 | Assert.IsTrue(interpreter.CodeStack.IsEmpty);
|
---|
17 | Assert.IsTrue(interpreter.ExecStack.IsEmpty);
|
---|
18 | Assert.IsTrue(interpreter.NameStack.IsEmpty);
|
---|
19 | Assert.IsTrue(interpreter.BooleanStack.IsEmpty);
|
---|
20 | Assert.IsTrue(interpreter.FloatStack.IsEmpty);
|
---|
21 | }
|
---|
22 |
|
---|
23 | [TestMethod]
|
---|
24 | public void TestAddOverflow()
|
---|
25 | {
|
---|
26 | var code = $"1 {long.MaxValue} INTEGER.+";
|
---|
27 |
|
---|
28 | interpreter.Interprete(code);
|
---|
29 |
|
---|
30 | Assert.AreEqual(long.MinValue, interpreter.IntegerStack.Top);
|
---|
31 | Assert.IsTrue(interpreter.CodeStack.IsEmpty);
|
---|
32 | Assert.IsTrue(interpreter.ExecStack.IsEmpty);
|
---|
33 | Assert.IsTrue(interpreter.NameStack.IsEmpty);
|
---|
34 | Assert.IsTrue(interpreter.BooleanStack.IsEmpty);
|
---|
35 | Assert.IsTrue(interpreter.FloatStack.IsEmpty);
|
---|
36 | }
|
---|
37 |
|
---|
38 | [TestMethod]
|
---|
39 | public void TestSubtract()
|
---|
40 | {
|
---|
41 | var code = "10 5 INTEGER.-";
|
---|
42 |
|
---|
43 | interpreter.Interprete(code);
|
---|
44 |
|
---|
45 | Assert.AreEqual(5, interpreter.IntegerStack.Top);
|
---|
46 | Assert.IsTrue(interpreter.CodeStack.IsEmpty);
|
---|
47 | Assert.IsTrue(interpreter.ExecStack.IsEmpty);
|
---|
48 | Assert.IsTrue(interpreter.NameStack.IsEmpty);
|
---|
49 | Assert.IsTrue(interpreter.BooleanStack.IsEmpty);
|
---|
50 | Assert.IsTrue(interpreter.FloatStack.IsEmpty);
|
---|
51 | }
|
---|
52 |
|
---|
53 | [TestMethod]
|
---|
54 | public void TestSubtractOverflow()
|
---|
55 | {
|
---|
56 | var code = $"{long.MinValue} 1 INTEGER.-";
|
---|
57 |
|
---|
58 | interpreter.Interprete(code);
|
---|
59 |
|
---|
60 | Assert.AreEqual(long.MaxValue, interpreter.IntegerStack.Top);
|
---|
61 | Assert.IsTrue(interpreter.CodeStack.IsEmpty);
|
---|
62 | Assert.IsTrue(interpreter.ExecStack.IsEmpty);
|
---|
63 | Assert.IsTrue(interpreter.NameStack.IsEmpty);
|
---|
64 | Assert.IsTrue(interpreter.BooleanStack.IsEmpty);
|
---|
65 | Assert.IsTrue(interpreter.FloatStack.IsEmpty);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|