상속: Microsoft.R.Host.Client.Test.Script.RHostScript
예제 #1
0
        public void VariableGrid_ConstructorTest02() {
            VisualTreeObject actual = null;
            using (var hostScript = new VariableRHostScript()) {
                using (var script = new ControlTestScript(typeof(VariableGridHost))) {
                    DoIdle(100);

                    EvaluationWrapper wrapper = null;
                    Task.Run(async () => {
                        hostScript.VariableProvider.Subscribe(
                            0,
                            "grid.test",
                            (r) => wrapper = new EvaluationWrapper(r));

                        await hostScript.EvaluateAsync("grid.test <- matrix(1:10, 2, 5)");
                    }).Wait();

                    DoIdle(2000);

                    wrapper.Should().NotBeNull();

                    UIThreadHelper.Instance.Invoke(() => {
                        var host = (VariableGridHost)script.Control;
                        host.SetEvaluation(wrapper);
                    });

                    DoIdle(1000);

                    actual = VisualTreeObject.Create(script.Control);
                }
            }
            ViewTreeDump.CompareVisualTrees(_files, actual, "VariableGrid02");
        }
예제 #2
0
        public Task InitializeAsync()
        {
            var workflow = VsAppShell.Current.GlobalServices.GetService <IRInteractiveWorkflowProvider>().GetOrCreate();

            _hostScript = new VariableRHostScript(workflow.RSessions);
            return(workflow.Connections.ConnectAsync(workflow.Connections.RecentConnections[0]));
        }
예제 #3
0
        public Task InitializeAsync()
        {
            _hostScript = new VariableRHostScript(_sessionProvider, _broker.BrokerConnector);
            var connections = VsAppShell.Current.ExportProvider.GetExportedValue <IRInteractiveWorkflowProvider>().GetOrCreate().Connections;

            return(connections.ConnectAsync(connections.RecentConnections[0]));
        }
예제 #4
0
        public async Task MatrixLargeCellTest()
        {
            var script      = "matrix.largecell <- matrix(list(as.double(1:5000), 2, 3, 4), nrow = 2, ncol = 2);";
            var expectation = new VariableExpectation()
            {
                Name = "matrix.largecell", Value = "List of 4", TypeName = "list", Class = "matrix", HasChildren = true, CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange    = new Range(0, 1);
                Range columnRange = new Range(0, 1);
                var   grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.RowHeader.Range.Should().Be(rowRange);
                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));

                grid.Grid[0, 0].Should().Be("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27...");
            }
        }
예제 #5
0
        public async Task MatrixOnlyRowNameTest()
        {
            var script      = "matrix.rowname.na <- matrix(c(1,2,3,4), nrow=2, ncol=2);rownames(matrix.rowname.na)<-c(NA, 'row2');";
            var expectation = new VariableExpectation()
            {
                Name = "matrix.rowname.na", Value = "num [1:2, 1:2] 1 2 3 4", TypeName = "double", Class = "matrix", HasChildren = true, CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange    = new Range(0, 2);
                Range columnRange = new Range(0, 2);
                var   grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[0].Should().Be("[,1]");
                grid.ColumnHeader[1].Should().Be("[,2]");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("NA");
                grid.RowHeader[1].Should().Be("row2");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].Should().Be("1");
                grid.Grid[0, 1].Should().Be("3");
                grid.Grid[1, 0].Should().Be("2");
                grid.Grid[1, 1].Should().Be("4");
            }
        }
예제 #6
0
        public async Task DataFrameLangTest()
        {
            var script      = "df.lang <- data.frame(col1=c('a','中'),col2=c('國','d'),row.names = c('マイクロソフト','row2'));";
            var expectation = new VariableExpectation()
            {
                Name = "df.lang", Value = "2 obs. of  2 variables", TypeName = "list", Class = "data.frame", HasChildren = true, CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange    = new Range(0, 2);
                Range columnRange = new Range(0, 2);
                var   grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[0].Should().Be("col1");
                grid.ColumnHeader[1].Should().Be("col2");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("マイクロソフト");
                grid.RowHeader[1].Should().Be("row2");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].Should().Be("a");
                grid.Grid[0, 1].Should().Be("國");
                grid.Grid[1, 0].Should().Be("中");
                grid.Grid[1, 1].Should().Be("d");
            }
        }
예제 #7
0
        public async Task PromiseTest()
        {
            var script      = "e <- (function(x, y, z) base::environment())(1,,3)";
            var expectation = new VariableExpectation()
            {
                Name = "e", Value = "<environment:", TypeName = "environment", Class = "environment", HasChildren = true, CanShowDetail = false
            };

            var x_expectation = new VariableExpectation()
            {
                Name = "x", Value = "1", TypeName = "<promise>", Class = "<promise>", HasChildren = false, CanShowDetail = false
            };
            var y_expectation = new VariableExpectation()
            {
                Name = "z", Value = "3", TypeName = "<promise>", Class = "<promise>", HasChildren = false, CanShowDetail = false
            };

            var evaluation = (VariableViewModel)await _hostScript.EvaluateAndAssert(
                script,
                expectation,
                VariableRHostScript.AssertEvaluationWrapper_ValueStartWith);

            var children = await evaluation.GetChildrenAsync();

            children.Count.Should().Be(2);
            VariableRHostScript.AssertEvaluationWrapper(children[0], x_expectation);
            VariableRHostScript.AssertEvaluationWrapper(children[1], y_expectation);
        }
예제 #8
0
        public async Task DataFrameTest()
        {
            var script      = "df.test <- data.frame(101:103, c('\"a', 'b', 'c'))";
            var expectation = new VariableExpectation()
            {
                Name = "df.test", Value = "3 obs. of  2 variables", TypeName = "list", Class = "data.frame", HasChildren = true, CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange    = new Range(0, 3);
                Range columnRange = new Range(0, 2);
                var   grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[0].Should().Be("X101.103");
                grid.ColumnHeader[1].Should().Be("c....a....b....c..");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("1");
                grid.RowHeader[1].Should().Be("2");
                grid.RowHeader[2].Should().Be("3");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].Should().Be("101");
                grid.Grid[0, 1].Should().Be("\"a");
                grid.Grid[1, 0].Should().Be("102");
                grid.Grid[1, 1].Should().Be("b");
                grid.Grid[2, 0].Should().Be("103");
                grid.Grid[2, 1].Should().Be("c");

                // single column
                columnRange = new Range(1, 1);
                grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[1].Should().Be("c....a....b....c..");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("1");
                grid.RowHeader[1].Should().Be("2");
                grid.RowHeader[2].Should().Be("3");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 1].Should().Be("\"a");
                grid.Grid[1, 1].Should().Be("b");
                grid.Grid[2, 1].Should().Be("c");
            }
        }
예제 #9
0
        private static async Task RunTest(object[,] testData)
        {
            using (var hostScript = new VariableRHostScript()) {
                int testCount = testData.GetLength(0);

                for (int i = 0; i < testCount; i++)
                {
                    await hostScript.EvaluateAndAssert(
                        (string)testData[i, 0],
                        (VariableExpectation)testData[i, 1],
                        VariableRHostScript.AssertEvaluationWrapper);
                }
            }
        }
        public async Task ValuesTest(string script, string expectedName, string expectedValue, string expectedTypeName, string expectedClass, bool expectedHasChildren, bool expectedCanShowDetail) {
            var expected = new VariableExpectation {
                Name = expectedName,
                Value = expectedValue,
                TypeName = expectedTypeName,
                Class = expectedClass,
                HasChildren = expectedHasChildren,
                CanShowDetail = expectedCanShowDetail
            };

            using (var hostScript = new VariableRHostScript()) {
                await hostScript.EvaluateAndAssert(script, expected, VariableRHostScript.AssertEvaluationWrapper);
            }
        }
예제 #11
0
        public async Task ValuesTest(string script, string expectedName, string expectedValue, string expectedTypeName, string expectedClass, bool expectedHasChildren, bool expectedCanShowDetail)
        {
            var expected = new VariableExpectation {
                Name          = expectedName,
                Value         = expectedValue,
                TypeName      = expectedTypeName,
                Class         = expectedClass,
                HasChildren   = expectedHasChildren,
                CanShowDetail = expectedCanShowDetail
            };

            using (var hostScript = new VariableRHostScript()) {
                await hostScript.EvaluateAndAssert(script, expected, VariableRHostScript.AssertEvaluationWrapper);
            }
        }
예제 #12
0
        public async Task TruncateGrandChildrenTest()
        {
            using (var hostScript = new VariableRHostScript()) {
                await hostScript.EvaluateAsync("x.truncate.children<-1:100");

                var children = await hostScript.GlobalEnvrionment.GetChildrenAsync();

                var child = children.First(c => c.Name == "x.truncate.children");

                var grandChildren = await child.GetChildrenAsync();

                grandChildren.Count.Should().Be(21);   // truncate 20 + ellipsis
                grandChildren[20].Value.Should().Be(Resources.VariableExplorer_Truncated);
            }
        }
예제 #13
0
        public async Task DoesNotExist()
        {
            // This is the equivalent of what we get when we fetch a variable
            // for a data grid after that variable is no longer available (rm or reset).
            var script = "idonotexist";

            using (var hostScript = new VariableRHostScript()) {
                var evaluationResult = await hostScript.EvaluateAsync(script);

                evaluationResult.Name.Should().BeNull();
                evaluationResult.Expression.Should().Be("idonotexist");

                var model = new VariableViewModel(evaluationResult, null);
                model.TypeName.Should().BeNull();
                model.Value.Should().BeNull();
            }
        }
예제 #14
0
        public async Task DataFrameManyColumnTest()
        {
            var script      = "df.manycolumn<-data.frame(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30);";
            var expectation = new VariableExpectation()
            {
                Name = "df.manycolumn", Value = "1 obs. of  30 variables", TypeName = "list", Class = "data.frame", HasChildren = true, CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                var children = await evaluation.GetChildrenAsync();

                children.Count.Should().BeGreaterOrEqualTo(30);
            }
        }
예제 #15
0
        public async Task Matrix10x100Test()
        {
            var script      = "matrix.10x100 <-matrix(1:1000, 10, 100)";
            var expectation = new VariableExpectation()
            {
                Name          = "matrix.10x100",
                Value         = "int [1:10, 1:100] 1 2 3 4 5 6 7 8 9 10 ...",
                TypeName      = "integer",
                Class         = "matrix",
                HasChildren   = true,
                CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange    = new Range(0, 2);
                Range columnRange = new Range(1, 3);
                var   grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[1].Should().Be("[,2]");
                grid.ColumnHeader[2].Should().Be("[,3]");
                grid.ColumnHeader[3].Should().Be("[,4]");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("[1,]");
                grid.RowHeader[1].Should().Be("[2,]");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 1].Should().Be("11");
                grid.Grid[0, 2].Should().Be("21");
                grid.Grid[0, 3].Should().Be("31");
                grid.Grid[1, 1].Should().Be("12");
                grid.Grid[1, 2].Should().Be("22");
                grid.Grid[1, 3].Should().Be("32");
            }
        }
예제 #16
0
        public async Task MatrixNamedTest()
        {
            var script      = "matrix.named <- matrix(1:10, 2, 5, dimnames = list(r = c('r1', 'r2'), c = c('a', 'b', 'c', 'd', 'e')))";
            var expectation = new VariableExpectation()
            {
                Name = "matrix.named", Value = "int [1:2, 1:5] 1 2 3 4 5 6 7 8 9 10", TypeName = "integer", Class = "matrix", HasChildren = true, CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange    = new Range(0, 2);
                Range columnRange = new Range(2, 3);
                var   grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[2].Should().Be("c");
                grid.ColumnHeader[3].Should().Be("d");
                grid.ColumnHeader[4].Should().Be("e");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("r1");
                grid.RowHeader[1].Should().Be("r2");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 2].Should().Be("5");
                grid.Grid[0, 3].Should().Be("7");
                grid.Grid[0, 4].Should().Be("9");
                grid.Grid[1, 2].Should().Be("6");
                grid.Grid[1, 3].Should().Be("8");
                grid.Grid[1, 4].Should().Be("10");
            }
        }
예제 #17
0
        public async Task MatrixOnlyColumnNameTest()
        {
            var script      = "matrix.colname.na <- matrix(1:6, nrow=2, ncol=3);colnames(matrix.colname.na)<-c('col1',NA,'col3');";
            var expectation = new VariableExpectation()
            {
                Name = "matrix.colname.na", Value = "int [1:2, 1:3] 1 2 3 4 5 6", TypeName = "integer", Class = "matrix", HasChildren = true, CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange    = new Range(0, 2);
                Range columnRange = new Range(0, 3);
                var   grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[0].Should().Be("col1");
                grid.ColumnHeader[1].Should().Be("NA");
                grid.ColumnHeader[2].Should().Be("col3");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("[1,]");
                grid.RowHeader[1].Should().Be("[2,]");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].Should().Be("1");
                grid.Grid[0, 1].Should().Be("3");
                grid.Grid[0, 2].Should().Be("5");
                grid.Grid[1, 0].Should().Be("2");
                grid.Grid[1, 1].Should().Be("4");
                grid.Grid[1, 2].Should().Be("6");
            }
        }
예제 #18
0
        public async Task MatrixNATest()
        {
            var script      = "matrix.na.header <- matrix(c(1, 2, 3, 4, NA, NaN, 7, 8, 9, 10), 2, 5, dimnames = list(r = c('r1', NA), c = c('a', 'b', NA, 'd', NA)))";
            var expectation = new VariableExpectation()
            {
                Name = "matrix.na.header", Value = "num [1:2, 1:5] 1 2 3 4 NA NaN 7 8 9 10", TypeName = "double", Class = "matrix", HasChildren = true, CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange    = new Range(0, 2);
                Range columnRange = new Range(2, 3);
                var   grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[2].Should().Be("NA");
                grid.ColumnHeader[3].Should().Be("d");
                grid.ColumnHeader[4].Should().Be("NA");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("r1");
                grid.RowHeader[1].Should().Be("NA");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 2].Should().Be("NA");
                grid.Grid[0, 3].Should().Be("7");
                grid.Grid[0, 4].Should().Be("9");
                grid.Grid[1, 2].Should().Be("NaN");
                grid.Grid[1, 3].Should().Be("8");
                grid.Grid[1, 4].Should().Be("10");
            }
        }
        public async Task MatrixNATest() {
            var script = "matrix.na.header <- matrix(c(1, 2, 3, 4, NA, NaN, 7, 8, 9, 10), 2, 5, dimnames = list(r = c('r1', NA), c = c('a', 'b', NA, 'd', NA)))";
            var expectation = new VariableExpectation() { Name = "matrix.na.header", Value = "num [1:2, 1:5] 1 2 3 4 NA NaN 7 8 9 10", TypeName = "double", Class = "matrix", HasChildren = true, CanShowDetail = true };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange = new Range(0, 2);
                Range columnRange = new Range(2, 3);
                var grid = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.ShouldBeEquivalentTo(columnRange);
                grid.ColumnHeader[2].ShouldBeEquivalentTo("NA");
                grid.ColumnHeader[3].ShouldBeEquivalentTo("d");
                grid.ColumnHeader[4].ShouldBeEquivalentTo("NA");

                grid.RowHeader.Range.ShouldBeEquivalentTo(rowRange);
                grid.RowHeader[0].ShouldBeEquivalentTo("r1");
                grid.RowHeader[1].ShouldBeEquivalentTo("NA");

                grid.Grid.Range.ShouldBeEquivalentTo(new GridRange(rowRange, columnRange));
                grid.Grid[0, 2].ShouldBeEquivalentTo("NA");
                grid.Grid[0, 3].ShouldBeEquivalentTo("7");
                grid.Grid[0, 4].ShouldBeEquivalentTo("9");
                grid.Grid[1, 2].ShouldBeEquivalentTo("NaN");
                grid.Grid[1, 3].ShouldBeEquivalentTo("8");
                grid.Grid[1, 4].ShouldBeEquivalentTo("10");
            }
        }
        public async Task MatrixOneRowColumnTest() {
            var script1 = "matrix.singlerow <- matrix(1:3, nrow =1);";
            var expectation1 = new VariableExpectation() { Name = "matrix.singlerow", Value = "int [1, 1:3] 1 2 3", TypeName = "integer", Class = "matrix", HasChildren = true, CanShowDetail = true };

            var script2 = "matrix.singlecolumn <- matrix(1:3, ncol=1);";
            var expectation2 = new VariableExpectation() { Name = "matrix.singlecolumn", Value = "int [1:3, 1] 1 2 3", TypeName = "integer", Class = "matrix", HasChildren = true, CanShowDetail = true };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script1,
                    expectation1,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange = new Range(0, 1);
                Range columnRange = new Range(0, 3);
                var grid = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.ShouldBeEquivalentTo(columnRange);
                grid.ColumnHeader[0].ShouldBeEquivalentTo("[,1]");
                grid.ColumnHeader[1].ShouldBeEquivalentTo("[,2]");
                grid.ColumnHeader[2].ShouldBeEquivalentTo("[,3]");

                grid.RowHeader.Range.ShouldBeEquivalentTo(rowRange);
                grid.RowHeader[0].ShouldBeEquivalentTo("[1,]");

                grid.Grid.Range.ShouldBeEquivalentTo(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].ShouldBeEquivalentTo("1");
                grid.Grid[0, 1].ShouldBeEquivalentTo("2");
                grid.Grid[0, 2].ShouldBeEquivalentTo("3");


                evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script2,
                    expectation2,
                    VariableRHostScript.AssertEvaluationWrapper);

                rowRange = new Range(0, 3);
                columnRange = new Range(0, 1);
                grid = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.ShouldBeEquivalentTo(columnRange);
                grid.ColumnHeader[0].ShouldBeEquivalentTo("[,1]");

                grid.RowHeader.Range.ShouldBeEquivalentTo(rowRange);
                grid.RowHeader[0].ShouldBeEquivalentTo("[1,]");
                grid.RowHeader[1].ShouldBeEquivalentTo("[2,]");
                grid.RowHeader[2].ShouldBeEquivalentTo("[3,]");

                grid.Grid.Range.ShouldBeEquivalentTo(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].ShouldBeEquivalentTo("1");
                grid.Grid[1, 0].ShouldBeEquivalentTo("2");
                grid.Grid[2, 0].ShouldBeEquivalentTo("3");
            }
        }
        public async Task MatrixOnlyRowNameTest() {
            var script = "matrix.rowname.na <- matrix(c(1,2,3,4), nrow=2, ncol=2);rownames(matrix.rowname.na)<-c(NA, 'row2');";
            var expectation = new VariableExpectation() { Name = "matrix.rowname.na", Value = "num [1:2, 1:2] 1 2 3 4", TypeName = "double", Class = "matrix", HasChildren = true, CanShowDetail = true };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange = new Range(0, 2);
                Range columnRange = new Range(0, 2);
                var grid = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.ShouldBeEquivalentTo(columnRange);
                grid.ColumnHeader[0].ShouldBeEquivalentTo("[,1]");
                grid.ColumnHeader[1].ShouldBeEquivalentTo("[,2]");

                grid.RowHeader.Range.ShouldBeEquivalentTo(rowRange);
                grid.RowHeader[0].ShouldBeEquivalentTo("NA");
                grid.RowHeader[1].ShouldBeEquivalentTo("row2");

                grid.Grid.Range.ShouldBeEquivalentTo(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].ShouldBeEquivalentTo("1");
                grid.Grid[0, 1].ShouldBeEquivalentTo("3");
                grid.Grid[1, 0].ShouldBeEquivalentTo("2");
                grid.Grid[1, 1].ShouldBeEquivalentTo("4");
            }
        }
        public async Task MatrixOnlyColumnNameTest() {
            var script = "matrix.colname.na <- matrix(1:6, nrow=2, ncol=3);colnames(matrix.colname.na)<-c('col1',NA,'col3');";
            var expectation = new VariableExpectation() { Name = "matrix.colname.na", Value = "int [1:2, 1:3] 1 2 3 4 5 6", TypeName = "integer", Class = "matrix", HasChildren = true, CanShowDetail = true };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange = new Range(0, 2);
                Range columnRange = new Range(0, 3);
                var grid = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.ShouldBeEquivalentTo(columnRange);
                grid.ColumnHeader[0].ShouldBeEquivalentTo("col1");
                grid.ColumnHeader[1].ShouldBeEquivalentTo("NA");
                grid.ColumnHeader[2].ShouldBeEquivalentTo("col3");

                grid.RowHeader.Range.ShouldBeEquivalentTo(rowRange);
                grid.RowHeader[0].ShouldBeEquivalentTo("[1,]");
                grid.RowHeader[1].ShouldBeEquivalentTo("[2,]");

                grid.Grid.Range.ShouldBeEquivalentTo(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].ShouldBeEquivalentTo("1");
                grid.Grid[0, 1].ShouldBeEquivalentTo("3");
                grid.Grid[0, 2].ShouldBeEquivalentTo("5");
                grid.Grid[1, 0].ShouldBeEquivalentTo("2");
                grid.Grid[1, 1].ShouldBeEquivalentTo("4");
                grid.Grid[1, 2].ShouldBeEquivalentTo("6");
            }
        }
예제 #23
0
        public async Task MatrixOneRowColumnTest()
        {
            var script1      = "matrix.singlerow <- matrix(1:3, nrow=1);";
            var expectation1 = new VariableExpectation()
            {
                Name          = "matrix.singlerow",
                Value         = "int [1, 1:3] 1 2 3",
                TypeName      = "integer",
                Class         = "matrix",
                HasChildren   = true,
                CanShowDetail = true
            };

            var script2      = "matrix.singlecolumn <- matrix(1:3, ncol=1);";
            var expectation2 = new VariableExpectation()
            {
                Name          = "matrix.singlecolumn",
                Value         = "int [1:3, 1] 1 2 3",
                TypeName      = "integer",
                Class         = "matrix",
                HasChildren   = true,
                CanShowDetail = true
            };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script1,
                    expectation1,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange    = new Range(0, 1);
                Range columnRange = new Range(0, 3);
                var   grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[0].Should().Be("[,1]");
                grid.ColumnHeader[1].Should().Be("[,2]");
                grid.ColumnHeader[2].Should().Be("[,3]");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("[1,]");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].Should().Be("1");
                grid.Grid[0, 1].Should().Be("2");
                grid.Grid[0, 2].Should().Be("3");


                evaluation = (VariableViewModel)await hostScript.EvaluateAndAssert(
                    script2,
                    expectation2,
                    VariableRHostScript.AssertEvaluationWrapper);

                rowRange    = new Range(0, 3);
                columnRange = new Range(0, 1);
                grid        = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.Should().Be(columnRange);
                grid.ColumnHeader[0].Should().Be("[,1]");

                grid.RowHeader.Range.Should().Be(rowRange);
                grid.RowHeader[0].Should().Be("[1,]");
                grid.RowHeader[1].Should().Be("[2,]");
                grid.RowHeader[2].Should().Be("[3,]");

                grid.Grid.Range.Should().Be(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].Should().Be("1");
                grid.Grid[1, 0].Should().Be("2");
                grid.Grid[2, 0].Should().Be("3");
            }
        }
        public async Task PromiseTest() {
            var script = "e <- (function(x, y, z) base::environment())(1,,3)";
            var expectation = new VariableExpectation() { Name = "e", Value = "<environment:", TypeName = "environment", Class = "environment", HasChildren = true, CanShowDetail = false };

            var x_expectation = new VariableExpectation() { Name = "x", Value = "1", TypeName = "<promise>", Class = "<promise>", HasChildren = false, CanShowDetail = false };
            var y_expectation = new VariableExpectation() { Name = "z", Value = "3", TypeName = "<promise>", Class = "<promise>", HasChildren = false, CanShowDetail = false };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper_ValueStartWith);

                var children = await evaluation.GetChildrenAsync();

                children.Count.ShouldBeEquivalentTo(2);
                VariableRHostScript.AssertEvaluationWrapper(children[0], x_expectation);
                VariableRHostScript.AssertEvaluationWrapper(children[1], y_expectation);
            }
        }
예제 #25
0
 public EvaluationWrapperTest(IServiceContainer services) : base(new VariableRHostScript(services), services)
 {
     _hostScript = GetScript <VariableRHostScript>();
     _dataSource = new GridDataSource(_hostScript.Session);
 }
        public async Task MatrixNamedTest() {
            var script = "matrix.named <- matrix(1:10, 2, 5, dimnames = list(r = c('r1', 'r2'), c = c('a', 'b', 'c', 'd', 'e')))";
            var expectation = new VariableExpectation() { Name = "matrix.named", Value = "int [1:2, 1:5] 1 2 3 4 5 6 7 8 9 10", TypeName = "integer", Class = "matrix", HasChildren = true, CanShowDetail = true };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange = new Range(0, 2);
                Range columnRange = new Range(2, 3);
                var grid = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.ShouldBeEquivalentTo(columnRange);
                grid.ColumnHeader[2].ShouldBeEquivalentTo("c");
                grid.ColumnHeader[3].ShouldBeEquivalentTo("d");
                grid.ColumnHeader[4].ShouldBeEquivalentTo("e");

                grid.RowHeader.Range.ShouldBeEquivalentTo(rowRange);
                grid.RowHeader[0].ShouldBeEquivalentTo("r1");
                grid.RowHeader[1].ShouldBeEquivalentTo("r2");

                grid.Grid.Range.ShouldBeEquivalentTo(new GridRange(rowRange, columnRange));
                grid.Grid[0, 2].ShouldBeEquivalentTo("5");
                grid.Grid[0, 3].ShouldBeEquivalentTo("7");
                grid.Grid[0, 4].ShouldBeEquivalentTo("9");
                grid.Grid[1, 2].ShouldBeEquivalentTo("6");
                grid.Grid[1, 3].ShouldBeEquivalentTo("8");
                grid.Grid[1, 4].ShouldBeEquivalentTo("10");
            }
        }
        public async Task MatrixLargeCellTest() {
            var script = "matrix.largecell <- matrix(list(as.double(1:5000), 2, 3, 4), nrow = 2, ncol = 2);";
            var expectation = new VariableExpectation() { Name = "matrix.largecell", Value = "List of 4", TypeName = "list", Class = "matrix", HasChildren = true, CanShowDetail = true };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange = new Range(0, 1);
                Range columnRange = new Range(0, 1);
                var grid = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.ShouldBeEquivalentTo(columnRange);
                grid.RowHeader.Range.ShouldBeEquivalentTo(rowRange);
                grid.Grid.Range.ShouldBeEquivalentTo(new GridRange(rowRange, columnRange));

                grid.Grid[0, 0].ShouldBeEquivalentTo("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27...");
            }
        }
        public async Task DataFrameTest() {
            var script = "df.test <- data.frame(101:103, c('a', 'b', 'c'))";
            var expectation = new VariableExpectation() { Name = "df.test", Value = "3 obs. of  2 variables", TypeName = "list", Class = "data.frame", HasChildren = true, CanShowDetail = true };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange = new Range(0, 3);
                Range columnRange = new Range(0, 2);
                var grid = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.ShouldBeEquivalentTo(columnRange);
                grid.ColumnHeader[0].ShouldBeEquivalentTo("X101.103");
                grid.ColumnHeader[1].ShouldBeEquivalentTo("c..a....b....c..");

                grid.RowHeader.Range.ShouldBeEquivalentTo(rowRange);
                grid.RowHeader[0].ShouldBeEquivalentTo("1");
                grid.RowHeader[1].ShouldBeEquivalentTo("2");
                grid.RowHeader[2].ShouldBeEquivalentTo("3");

                grid.Grid.Range.ShouldBeEquivalentTo(new GridRange(rowRange, columnRange));
                grid.Grid[0, 0].ShouldBeEquivalentTo("101");
                grid.Grid[0, 1].ShouldBeEquivalentTo("a");
                grid.Grid[1, 0].ShouldBeEquivalentTo("102");
                grid.Grid[1, 1].ShouldBeEquivalentTo("b");
                grid.Grid[2, 0].ShouldBeEquivalentTo("103");
                grid.Grid[2, 1].ShouldBeEquivalentTo("c");
            }
        }
        public async Task Matrix10x100Test() {
            var script = "matrix.10x100 <-matrix(1:1000, 10, 100)";
            var expectation = new VariableExpectation() { Name = "matrix.10x100", Value = "int [1:10, 1:100] 1 2 3 4 5 6 7 8 9 10 ...", TypeName = "integer", Class = "matrix", HasChildren = true, CanShowDetail = true };

            using (var hostScript = new VariableRHostScript()) {
                var evaluation = (EvaluationWrapper)await hostScript.EvaluateAndAssert(
                    script,
                    expectation,
                    VariableRHostScript.AssertEvaluationWrapper);

                Range rowRange = new Range(0, 2);
                Range columnRange = new Range(1, 3);
                var grid = await GridDataSource.GetGridDataAsync(evaluation.Expression, new GridRange(rowRange, columnRange));

                grid.ColumnHeader.Range.ShouldBeEquivalentTo(columnRange);
                grid.ColumnHeader[1].ShouldBeEquivalentTo("[,2]");
                grid.ColumnHeader[2].ShouldBeEquivalentTo("[,3]");
                grid.ColumnHeader[3].ShouldBeEquivalentTo("[,4]");

                grid.RowHeader.Range.ShouldBeEquivalentTo(rowRange);
                grid.RowHeader[0].ShouldBeEquivalentTo("[1,]");
                grid.RowHeader[1].ShouldBeEquivalentTo("[2,]");

                grid.Grid.Range.ShouldBeEquivalentTo(new GridRange(rowRange, columnRange));
                grid.Grid[0, 1].ShouldBeEquivalentTo("11");
                grid.Grid[0, 2].ShouldBeEquivalentTo("21");
                grid.Grid[0, 3].ShouldBeEquivalentTo("31");
                grid.Grid[1, 1].ShouldBeEquivalentTo("12");
                grid.Grid[1, 2].ShouldBeEquivalentTo("22");
                grid.Grid[1, 3].ShouldBeEquivalentTo("32");
            }
        }
예제 #30
0
 public EvaluationWrapperTest(IServiceContainer services) : base(new VariableRHostScript(services), services)
 {
     _hostScript = GetScript <VariableRHostScript>();
 }
예제 #31
0
 public VariableGridTest(TestFilesFixture files) {
     _files = files;
     _hostScript = new VariableRHostScript(SessionProvider);
 }
예제 #32
0
        private async Task PrepareControl(VariableRHostScript hostScript, ControlTestScript script, string expression) {
            DoIdle(100);

            var result = await hostScript.EvaluateAsync(expression);
            VariableViewModel wrapper = new VariableViewModel(result, VsAppShell.Current.ExportProvider.GetExportedValue<IObjectDetailsViewerAggregator>());

            DoIdle(2000);

            wrapper.Should().NotBeNull();

            UIThreadHelper.Instance.Invoke(() => {
                var host = (VariableGridHost)script.Control;
                host.SetEvaluation(wrapper);
            });

            DoIdle(1000);
        }
        private static async Task RunTest(object[,] testData) {
            using (var hostScript = new VariableRHostScript()) {
                int testCount = testData.GetLength(0);

                for (int i = 0; i < testCount; i++) {
                    await hostScript.EvaluateAndAssert(
                        (string)testData[i, 0],
                        (VariableExpectation)testData[i, 1],
                        VariableRHostScript.AssertEvaluationWrapper);
                }
            }
        }
예제 #34
0
 public Task InitializeAsync() {
     var workflow = VsAppShell.Current.ExportProvider.GetExportedValue<IRInteractiveWorkflowProvider>().GetOrCreate();
     _hostScript = new VariableRHostScript(workflow.RSessions);
     return workflow.Connections.ConnectAsync(workflow.Connections.RecentConnections[0]);
 }
        public async Task TruncateGrandChildrenTest() {
            using (var hostScript = new VariableRHostScript()) {
                await hostScript.EvaluateAsync("x.truncate.children<-1:100");
                var children = await hostScript.GlobalEnvrionment.GetChildrenAsync();
                var child = children.First(c => c.Name == "x.truncate.children");

                var grandChildren = await child.GetChildrenAsync();

                grandChildren.Count.ShouldBeEquivalentTo(21);   // truncate 20 + ellipsis
                grandChildren[20].Value.ShouldBeEquivalentTo(Resources.VariableExplorer_Truncated);
            }
        }