コード例 #1
0
ファイル: CodeTests.cs プロジェクト: bamyazi/cloaca
 public void RepeatedArithmeticOperators()
 {
     // Making sure that we're properly parsing and generating all of these when there's multiples of the operator.
     runBasicTest(
         "x = 100\n" +
         "a = x + 2 + 3\n" +
         "b = x - 2 - 3\n" +
         "c = x * 2 * 3\n" +
         "d = x / 4 / 2\n" +
         "e = x % 9 % 3\n" +
         "f = x // 2 // 3\n" +
         "g = x ** 2 ** 3\n" +
         "h = x & 3 & 2\n" +
         "i = x | 13 | 1 \n" +
         "j = x ^ 2 ^ 1\n" +
         "k = x >> 2 >> 3\n" +
         "l = x << 2 << 3\n"
         , new VariableMultimap(new TupleList <string, object>
     {
         { "a", PyInteger.Create(100 + 2 + 3) },
         { "b", PyInteger.Create(100 - 2 - 3) },
         { "c", PyInteger.Create(100 * 2 * 3) },
         { "d", PyFloat.Create(100.0 / 4.0 / 2.0) },
         { "e", PyInteger.Create(100 % 9 % 3) },
         { "f", PyInteger.Create(100 / 2 / 3) },
         { "g", PyInteger.Create((BigInteger)Math.Pow(100.0, 8.0)) },           // 2 ** 3 gets evaluated first and becomes 8. This is what CPython does too!
         { "h", PyInteger.Create(100 & 3 & 2) },
         { "i", PyInteger.Create(100 | 13 | 1) },
         { "j", PyInteger.Create(100 ^ 2 ^ 1) },
         { "k", PyInteger.Create(100 >> 2 >> 3) },
         { "l", PyInteger.Create(100 << 2 << 3) }
     }), 1);
 }
コード例 #2
0
ファイル: CodeTests.cs プロジェクト: bamyazi/cloaca
 public void SimpleFloatMath()
 {
     runBasicTest("a = 10.0 * (2.0 + 4.0) / 3.0\n", new VariableMultimap(new TupleList <string, object>
     {
         { "a", PyFloat.Create(20.0) }
     }), 1);
 }
コード例 #3
0
ファイル: CodeTests.cs プロジェクト: bamyazi/cloaca
 public void ComprehensiveArithmeticOperators()
 {
     runBasicTest(
         "x = 10\n" +
         "a = x + 2\n" +
         "b = x - 2\n" +
         "c = x * 2\n" +
         "d = x / 2\n" +
         "e = x % 9\n" +
         "f = x // 3\n" +
         "g = x ** 2\n" +
         "h = x & 2\n" +
         "i = x | 14\n" +
         "j = x ^ 2\n" +
         "k = x >> 2\n" +
         "l = x << 2\n"
         , new VariableMultimap(new TupleList <string, object>
     {
         { "a", PyInteger.Create(12) },
         { "b", PyInteger.Create(8) },
         { "c", PyInteger.Create(20) },
         { "d", PyFloat.Create(5.0) },
         { "e", PyInteger.Create(1) },
         { "f", PyInteger.Create(3) },
         { "g", PyInteger.Create(100) },
         { "h", PyInteger.Create(2) },
         { "i", PyInteger.Create(14) },
         { "j", PyInteger.Create(8) },
         { "k", PyInteger.Create(2) },
         { "l", PyInteger.Create(40) }
     }), 1);
 }
コード例 #4
0
ファイル: CodeTests.cs プロジェクト: rockobonaparte/cloaca
 public async Task SimpleIntMath()
 {
     await runBasicTest("a = 10 * (2 + 4) / 3\n", new VariableMultimap(new TupleList <string, object>
     {
         { "a", PyFloat.Create(20.0) }
     }), 1);
 }
コード例 #5
0
ファイル: CodeTests.cs プロジェクト: bamyazi/cloaca
 public void AssignmentOperators()
 {
     // https://www.w3schools.com/python/python_operators.asp
     // +=	x += 3	x = x + 3
     // -=	x -= 3	x = x - 3
     // *=	x *= 3	x = x * 3
     // /=	x /= 3	x = x / 3
     // %=	x %= 3	x = x % 3
     // //=	x //= 3	x = x // 3
     // **=	x **= 3	x = x ** 3
     // &=	x &= 3	x = x & 3
     // |=	x |= 3	x = x | 3
     // ^=	x ^= 3	x = x ^ 3
     // >>=	x >>= 3	x = x >> 3
     // <<=	x <<= 3	x = x << 3
     runBasicTest(
         "a = 10\n" +
         "b = 10\n" +
         "c = 10\n" +
         "d = 10\n" +
         "e = 10\n" +
         "f = 10\n" +
         "g = 10\n" +
         "h = 10\n" +
         "i = 10\n" +
         "j = 10\n" +
         "k = 10\n" +
         "l = 10\n" +
         "a += 2\n" +
         "b -= 2\n" +
         "c *= 2\n" +
         "d /= 2\n" +
         "e %= 9\n" +
         "f //= 3\n" +
         "g **= 2\n" +
         "h &= 2\n" +
         "i |= 14\n" +
         "j ^= 2\n" +
         "k >>= 2\n" +
         "l <<= 2\n"
         , new VariableMultimap(new TupleList <string, object>
     {
         { "a", PyInteger.Create(12) },
         { "b", PyInteger.Create(8) },
         { "c", PyInteger.Create(20) },
         { "d", PyFloat.Create(5.0) },
         { "e", PyInteger.Create(1) },
         { "f", PyInteger.Create(3) },
         { "g", PyInteger.Create(100) },
         { "h", PyInteger.Create(2) },
         { "i", PyInteger.Create(14) },
         { "j", PyInteger.Create(8) },
         { "k", PyInteger.Create(2) },
         { "l", PyInteger.Create(40) }
     }), 1);
 }
コード例 #6
0
        public static object CreateNumber(IParseTree context)
        {
            string rawText = context.GetText();

            if (DecimalPointNumberRegex.Match(rawText).Success)
            {
                return(PyFloat.Create(Decimal.Parse(rawText)));
            }
            return(PyInteger.Create(BigInteger.Parse(context.GetText())));
        }
コード例 #7
0
ファイル: CodeTests.cs プロジェクト: bamyazi/cloaca
 public void BasicWait()
 {
     runBasicTest(
         "a = 10 * (2 + 4) / 3\n" +
         "wait\n" +
         "b = a + 3\n", new VariableMultimap(new TupleList <string, object>
     {
         { "a", PyFloat.Create(20.0) },
         { "b", PyFloat.Create(23.0) }
     }), 2);
 }
コード例 #8
0
 public async Task NumericStringConversions()
 {
     await runBasicTest(
         "a_string = '1'\n" +
         "as_int = int(a_string)\n" +
         "as_float = float(a_string)\n" +
         "as_bool = bool(a_string)\n" +
         "int_str = str(1)\n" +
         "float_str = str(1.0)\n" +
         "bool_str = str(True)\n",
         new VariableMultimap(new TupleList <string, object>
     {
         { "as_int", PyInteger.Create(1) },
         { "as_float", PyFloat.Create(1.0) },
         { "as_bool", PyBool.True },
         { "int_str", PyString.Create("1") },
         { "float_str", PyString.Create("1.0") },
         { "bool_str", PyString.Create("True") },
     }), 1);
 }