public void BooleanNot() { var method = CreateMethod(block => block.Return(EmitAst.Literal(false).BooleanNot())); var result = (bool)method.Invoke(null, null); Assert.IsTrue(result); }
public void AddDoubleAndInt() { var method = CreateMethod(block => block.Return(EmitAst.Literal(5.1d).Add(4))); var result = (double)method.Invoke(null, null); Assert.IsTrue(Math.Abs(9.1d - result) < .0001d); }
public void GreaterThan() { var method = CreateMethod(block => block.Return(EmitAst.Literal(5).GreaterThan(4))); var result = (bool)method.Invoke(null, null); Assert.IsTrue(result); }
public void LessThanOrEqualWhenLess() { var method = CreateMethod(block => block.Return(EmitAst.Literal(5).LessThanOrEqual(6))); var result = (bool)method.Invoke(null, null); Assert.IsTrue(result); }
public void ShiftRight() { var method = CreateMethod(block => block.Return(EmitAst.Literal(4).ShiftRight(2))); var result = (int)method.Invoke(null, null); Assert.AreEqual(1, result); }
public void NotEqualsTrue() { var method = CreateMethod(block => block.Return(EmitAst.Literal(4).NotEqualTo(5))); var result = (bool)method.Invoke(null, null); Assert.IsTrue(result); }
public void BitwiseOr() { var method = CreateMethod(block => block.Return(EmitAst.Literal(1 | 2).BitwiseOr(4 | 8))); var result = (int)method.Invoke(null, null); Assert.AreEqual(15, result); }
public void Modulus() { var method = CreateMethod(block => block.Return(EmitAst.Literal(7).Modulus(3))); var result = (int)method.Invoke(null, null); Assert.AreEqual(1, result); }
public void Subtract() { var method = CreateMethod(block => block.Return(EmitAst.Literal(7).Subtract(3))); var result = (int)method.Invoke(null, null); Assert.AreEqual(4, result); }
public void Plus() { var method = CreateMethod(block => block.Return(EmitAst.Literal(123).Plus())); var result = (int)method.Invoke(null, null); Assert.AreEqual(result, 123); }
public void BitwiseNot() { var method = CreateMethod(block => block.Return(EmitAst.Literal(34754935).BitwiseNot())); var result = (int)method.Invoke(null, null); Assert.AreEqual(result, ~34754935); }
public void AddTwoInts() { var method = CreateMethod(block => block.Return(EmitAst.Literal(5).Add(4))); var result = (int)method.Invoke(null, null); Assert.AreEqual(9, result); }
public void CastFloatToInt() { var method = CreateMethod(block => block.Return(EmitAst.Literal(4.5F).Cast(typeof(int)))); var result = (int)method.Invoke(null, null); Assert.AreEqual(4, result); }
public void AddTwoFloats() { var method = CreateMethod(block => block.Return(EmitAst.Literal(5.1f).Add(4.2f))); var result = (float)method.Invoke(null, null); Assert.IsTrue(Math.Abs(9.3f - result) < .0001f); }
public void CastLongToInt() { var expected = 2342332342342334L; var method = CreateMethod(block => block.Return(EmitAst.Literal(2342332342342334L).Cast(typeof(int)))); var result = (int)method.Invoke(null, null); Assert.AreEqual((int)expected, result); }
public void CastIntToLong() { var expected = 234233L; var method = CreateMethod(block => block.Return(EmitAst.Literal(234233).Cast(typeof(long)))); var result = (long)method.Invoke(null, null); Assert.AreEqual(expected, result); }
public void CastIntToDouble() { var expected = 1233223523532D; var method = CreateMethod(block => block.Return(EmitAst.Literal(1233223523532).Cast(typeof(double)))); var result = (double)method.Invoke(null, null); Assert.AreEqual(expected, result); }
public void CastIntToFloat() { var expected = 123F; var method = CreateMethod(block => block.Return(EmitAst.Literal(123).Cast(typeof(float)))); var result = (float)method.Invoke(null, null); Assert.AreEqual(expected, result); }
public void CastIntToShort() { var expected = 1254323423; var method = CreateMethod(block => block.Return(EmitAst.Literal(1254323423).Cast(typeof(short)))); var result = (short)method.Invoke(null, null); Assert.AreEqual((short)expected, result); }
public void CastIntToByte() { var expected = 12543; var method = CreateMethod(block => block.Return(EmitAst.Literal(12543).Cast(typeof(byte)))); var result = (byte)method.Invoke(null, null); Assert.AreEqual((byte)expected, result); }
public void ForLoop() { var method = CreateMethod(block => { var otherVariable = block.Declare(typeof(int)); block.Express(otherVariable.Assign(EmitAst.Literal(1))); var variable = EmitAst.Declare(typeof(int)); block.Statements.Add(EmitAst.For(variable, EmitAst.LessThan(variable, EmitAst.Literal(5)), variable.AddAssign(1).Express(), otherVariable.AddAssign(1).Express())); block.Return(otherVariable); }); var result = (int)method.Invoke(null, null); Assert.AreEqual(6, result); }