Exemplo n.º 1
0
        public void TestTableAddRemoveAndSetColumn()
        {
            Table table = MakeTableWithOneColumnOfTwoIntArrays(10);

            Array  nonEqualLengthIntArray = ColumnTests.MakeIntArray(10);
            Field  field1 = new Field.Builder().Name("f1").DataType(Int32Type.Default).Build();
            Column nonEqualLengthColumn = new Column(field1, new[] { nonEqualLengthIntArray });

            Assert.Throws <ArgumentException>(() => table.InsertColumn(-1, nonEqualLengthColumn));
            Assert.Throws <ArgumentException>(() => table.InsertColumn(1, nonEqualLengthColumn));

            Array  equalLengthIntArray = ColumnTests.MakeIntArray(20);
            Field  field2            = new Field.Builder().Name("f2").DataType(Int32Type.Default).Build();
            Column equalLengthColumn = new Column(field2, new[] { equalLengthIntArray });
            Column existingColumn    = table.Column(0);

            Table newTable = table.InsertColumn(0, equalLengthColumn);

            Assert.Equal(2, newTable.ColumnCount);
            Assert.True(newTable.Column(0) == equalLengthColumn);
            Assert.True(newTable.Column(1) == existingColumn);

            newTable = newTable.RemoveColumn(1);
            Assert.Equal(1, newTable.ColumnCount);
            Assert.True(newTable.Column(0) == equalLengthColumn);

            newTable = table.SetColumn(0, existingColumn);
            Assert.True(newTable.Column(0) == existingColumn);
        }
Exemplo n.º 2
0
        public static Table MakeTableWithOneColumnOfTwoIntArrays(int lengthOfEachArray)
        {
            Array intArray     = ColumnTests.MakeIntArray(lengthOfEachArray);
            Array intArrayCopy = ColumnTests.MakeIntArray(lengthOfEachArray);

            Field  field = new Field.Builder().Name("f0").DataType(Int32Type.Default).Build();
            Schema s0    = new Schema.Builder().Field(field).Build();

            Column column = new Column(field, new List <Array> {
                intArray, intArrayCopy
            });
            Table table = new Table(s0, new List <Column> {
                column
            });

            return(table);
        }