예제 #1
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...");
            }
        }
예제 #2
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
            };

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

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

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

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

            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");
        }
예제 #3
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
            };

            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 _hostScript.Session.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");
        }
예제 #4
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
            };

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

            var rowRange    = new Range(0, 2);
            var columnRange = new Range(0, 2);
            var grid        = await _hostScript.Session.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("[1,]");
            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");
        }
예제 #5
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
            };

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

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

            grid.ColumnHeader.Range.Should().Be(columnRange);
            grid.ColumnHeader[0].Should().Be("col1");
            grid.ColumnHeader[1].Should().Be("[,2]");
            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");
        }
예제 #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
            };

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

            var rowRange    = new Range(0, 2);
            var columnRange = new Range(0, 2);
            var grid        = await _hostScript.Session.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 static void AssertEvaluationWrapper_ValueStartWith(IRSessionDataObject rdo, VariableExpectation expectation) {
     var v = (VariableViewModel)rdo;
     v.Name.ShouldBeEquivalentTo(expectation.Name);
     v.Value.Should().StartWith(expectation.Value);
     v.Class.ShouldBeEquivalentTo(expectation.Class);
     v.TypeName.ShouldBeEquivalentTo(expectation.TypeName);
     v.HasChildren.ShouldBeEquivalentTo(expectation.HasChildren);
 }
예제 #9
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");
            }
        }
예제 #10
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
            };

            await _hostScript.EvaluateAndAssert(script, expected, 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);
            }
        }
예제 #12
0
        /// <summary>
        /// evaluate R script and assert if the expectation is not found in global environment
        /// </summary>
        public async Task<IRSessionDataObject> EvaluateAndAssert(
            string rScript,
            VariableExpectation expectation,
            Action<IRSessionDataObject, VariableExpectation> assertAction) {

            await EvaluateAsync(rScript);

            var children = await _globalEnv.GetChildrenAsync();

            // must contain one and only expectation in result
            var evaluation = children.First(v => v.Name == expectation.Name);
            assertAction(evaluation, expectation);

            return evaluation;
        }
예제 #13
0
        /// <summary>
        /// evaluate R script and assert if the expectation is not found in global environment
        /// </summary>
        public async Task <IRSessionDataObject> EvaluateAndAssert(
            string rScript,
            VariableExpectation expectation,
            Action <IRSessionDataObject, VariableExpectation> assertAction)
        {
            await EvaluateAsync(rScript);

            var children = await _globalEnv.GetChildrenAsync();

            // must contain one and only expectation in result
            var evaluation = children.First(v => v.Name == expectation.Name);

            assertAction(evaluation, expectation);

            return(evaluation);
        }
예제 #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
            };
            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 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
            };

            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");
        }
예제 #17
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 };

            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");
        }
예제 #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 };

            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("[,1]");
            grid.ColumnHeader[3].Should().Be("d");
            grid.ColumnHeader[4].Should().Be("[,3]");

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

            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");
        }
예제 #19
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
            };

            var evaluation = (VariableViewModel)await _hostScript.EvaluateAndAssert(
                script1,
                expectation1,
                VariableRHostScript.AssertEvaluationWrapper);

            var rowRange    = new Range(0, 1);
            var columnRange = new Range(0, 3);
            var grid        = await _hostScript.Session.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 _hostScript.Session.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");
        }
예제 #20
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
            };

            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");
        }
예제 #21
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 };

            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("[1,]");
            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");
        }
예제 #22
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);
        }
예제 #23
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 };

            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...");
        }
예제 #24
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 };

            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");
        }
예제 #25
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 };

            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");
        }
예제 #26
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 };

            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("[,2]");
            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");
        }
예제 #27
0
        public static void AssertEvaluationWrapper(IRSessionDataObject rdo, VariableExpectation expectation)
        {
            var v = (VariableViewModel)rdo;

            v.ShouldBeEquivalentTo(expectation, o => o.ExcludingMissingMembers());
        }
예제 #28
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 };
            var evaluation = (VariableViewModel)await _hostScript.EvaluateAndAssert(
                script,
                expectation,
                VariableRHostScript.AssertEvaluationWrapper);

            var children = await evaluation.GetChildrenAsync();
            children.Count.Should().BeGreaterOrEqualTo(30);
        }
예제 #29
0
 public static void AssertEvaluationWrapper(IRSessionDataObject rdo, VariableExpectation expectation) {
     var v = (EvaluationWrapper)rdo;
     v.ShouldBeEquivalentTo(expectation, o => o.ExcludingMissingMembers());
 }
예제 #30
0
        public static void AssertEvaluationWrapper_ValueStartWith(IRSessionDataObject rdo, VariableExpectation expectation)
        {
            var v = (VariableViewModel)rdo;

            v.Name.ShouldBeEquivalentTo(expectation.Name);
            v.Value.Should().StartWith(expectation.Value);
            v.Class.ShouldBeEquivalentTo(expectation.Class);
            v.TypeName.ShouldBeEquivalentTo(expectation.TypeName);
            v.HasChildren.ShouldBeEquivalentTo(expectation.HasChildren);
        }