public async Task PyListReadInt32()
        {
            var list   = PyList.Create();
            var stored = PyInteger.Create(1);

            PyListClass.append(list, stored);

            var read = await SubscriptHelper.LoadSubscript(interpreter, context, list, 0);

            Assert.That(read, Is.EqualTo(stored));
        }
        public async Task PyListWriteInt32()
        {
            var list   = PyList.Create();
            var stored = PyInteger.Create(1);

            PyListClass.append(list, stored);

            await SubscriptHelper.StoreSubscript(interpreter, context, list, 0, PyInteger.Create(2));

            Assert.That(list.list[0], Is.EqualTo(PyInteger.Create(2)));
        }
Exemplo n.º 3
0
 public async Task UnpackMultiassign()
 {
     await runBasicTest(
         "a, b = c = [1, 2]\n", new VariableMultimap(new TupleList <string, object>
     {
         { "a", PyInteger.Create(1) },
         { "b", PyInteger.Create(2) },
         { "c", PyList.Create(new List <object>()
             {
                 PyInteger.Create(1), PyInteger.Create(2)
             }) },
     }), 1);
 }
Exemplo n.º 4
0
        public async Task BasicCopyInlineList()
        {
            string program =
                "b = [x for x in [1, 2, 3]]\n";

            var list = PyList.Create();

            list.list.Add(PyInteger.Create(1));
            list.list.Add(PyInteger.Create(2));
            list.list.Add(PyInteger.Create(3));

            await runBasicTest(program,
                               new VariableMultimap(new TupleList <string, object>
            {
                { "b", list }
            }), 1);
        }
Exemplo n.º 5
0
        public async Task ListCompMath()
        {
            string program =
                "a = [1, 2, 3]\n" +
                "b = [2*x+1 for x in a]\n";

            var b = PyList.Create();

            b.list.Add(PyInteger.Create(2 * 1 + 1));
            b.list.Add(PyInteger.Create(2 * 2 + 1));
            b.list.Add(PyInteger.Create(2 * 3 + 1));

            await runBasicTest(program,
                               new VariableMultimap(new TupleList <string, object>
            {
                { "b", b }
            }), 1);
        }
Exemplo n.º 6
0
        public async Task LenFunction()
        {
            var dictin = PyDict.Create();

            dictin.InternalDict[PyString.Create("1")] = PyInteger.Create(1);
            dictin.InternalDict[PyString.Create("2")] = PyInteger.Create(2);

            await runBasicTest(
                "listout = len(listin)\n" +
                "dictout = len(dictin)\n" +
                "tupleout = len(tuplein)\n" +
                "strout = len(strin)\n" +
                "rangeout = len(rangein)\n" +
                "arrayout = len(arrayin)\n" +
                "enumerableout = len(enumerablein)\n" +
                "dotnetstrout = len(dotnetstrin)\n",     // I think this should be IEnumerable but I'm not taking chances
                new Dictionary <string, object>()
            {
                { "listin", PyList.Create(new List <object>()
                    {
                        PyInteger.Create(1)
                    }) },
                { "dictin", dictin },
                { "tuplein", PyTuple.Create(new object[] { 1, 2, 3 }) },
                { "strin", PyString.Create("1234") },
                { "rangein", PyRange.Create(5, 0, 1) },
                { "arrayin", new int[] { 1, 2, 3, 4, 5, 6 } },
                { "enumerablein", new List <int>()
                  {
                      1, 2, 3, 4, 5, 6, 7
                  } },
                { "dotnetstrin", "12345678" },
            }, new VariableMultimap(new TupleList <string, object>
            {
                { "listout", PyInteger.Create(1) },
                { "dictout", PyInteger.Create(2) },
                { "tupleout", PyInteger.Create(3) },
                { "strout", PyInteger.Create(4) },
                { "rangeout", PyInteger.Create(5) },
                { "arrayout", PyInteger.Create(6) },
                { "enumerableout", PyInteger.Create(7) },
                { "dotnetstrout", PyInteger.Create(8) },
            }), 1);
        }
Exemplo n.º 7
0
        public async Task DoubleComprehension()
        {
            string program =
                "a = [['Hello', 'World!'], ['Lets', 'Eat!']]\n" +
                "b = [word for words in a for word in words]\n";

            var b = PyList.Create();

            b.list.Add(PyString.Create("Hello"));
            b.list.Add(PyString.Create("World!"));
            b.list.Add(PyString.Create("Lets"));
            b.list.Add(PyString.Create("Eat!"));

            await runBasicTest(program,
                               new VariableMultimap(new TupleList <string, object>
            {
                { "b", b }
            }), 1);
        }
Exemplo n.º 8
0
        public async Task AdvancedDoubleComprehension()
        {
            string program =
                "double_list = [[1, 2], [3], [4, 5]]\n" +
                "b = [x + 1 for sublist in double_list if len(sublist) > 1 for x in sublist]\n";

            var b = PyList.Create();

            b.list.Add(PyInteger.Create(2));
            b.list.Add(PyInteger.Create(3));
            b.list.Add(PyInteger.Create(5));
            b.list.Add(PyInteger.Create(6));

            await runBasicTest(program,
                               new VariableMultimap(new TupleList <string, object>
            {
                { "b", b }
            }), 1);
        }
Exemplo n.º 9
0
 public static PyList readlines(PyIOBase self, PyInteger size)
 {
     return(PyList.Create());
 }