Exemplo n.º 1
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");
        }
Exemplo n.º 2
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...");
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 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);

            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");
        }
Exemplo n.º 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);

            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");
        }
Exemplo n.º 6
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");
        }
Exemplo n.º 7
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");
        }
Exemplo n.º 8
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");
        }
Exemplo n.º 9
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");
        }
Exemplo n.º 10
0
        public bool Contains(Range other) {
            if (Count == 0) return false;

            return (other.Start <= this.Start) && (other._end >= this._end);
        }