public override Table Execute(Table table)
        {
            if (column.Type == DataType.StringDimension || column.Type == DataType.DateDimension) throw new BadColumnForComputationException();
                double newCellContent;
                foreach (Cell cell in column.Cells)
                {
                    newCellContent = del.Invoke((double)cell.Content);
                    newRows.Add(new Cell(newCellContent));
                }
                List<Column> newColumnList = new List<Column>();
                foreach (Column col in table.Columns)
                {
                    Column newCol = new Column(col.Name,col.Type);
                    foreach (Cell cell in col.Cells)
                    {
                        newCol.AddCell(new Cell(cell.Content));
                    }
                    newColumnList.Add(newCol);
                }

                Table newTable = new Table(table.Name, table, newColumnList);
                Column newColumn = new Column("Computation",DataType.FloatFact, newRows);
                newTable.AddColumn(newColumn);
                return newTable;
        }
Exemplo n.º 2
0
 public Table(String _name, Table previous, List<Column> columns = null)
 {
     this._name = _name;
     if (columns == null) this.columns = new List<Column>();
     else this.columns = columns;
     this.previous = previous;
 }
        public override Table Execute(Table table)
        {
            if (selectedIndices != null)
            {
                selectedColumns = new List<Column>();
                foreach (int index in selectedIndices)
                {
                    selectedColumns.Add(table.Columns[index]);
                }

            }
            return new Table(table.Name, null, selectedColumns);
        }
 public override Table Execute(Table firstTable)
 {
     Table newTable = new Table(firstTable.Name, firstTable);
     if (firstTable.Columns.Count != secondTable.Columns.Count) throw new IncoherentColumnCountException();
     for (int i = 0; i < firstTable.Columns.Count; i++)
     {
         if (firstTable.Columns[i].Type != secondTable.Columns[i].Type) throw new ColumnTypeMismatchException();
         Column newColumn = new Column(firstTable.Columns[i].Name, firstTable.Columns[i].Type, new List<Cell>(firstTable.Columns[i].Cells));
         newColumn.Cells.AddRange(secondTable.Columns[i].Cells);
         newTable.AddColumn(newColumn);
     }
     return newTable;
 }
        public void ColumnsTest()
        {
            var column1 = new Mock<Column>();
            var column2 = new Mock<Column>();
            var column3 = new Mock<Column>();
            List<Column> columns = new List<Column>();
            columns.Add(column1.Object);
            columns.Add(column2.Object);
            columns.Add(column3.Object);

            Table table = new Table("Table", null, columns);

            CollectionAssert.AreEqual(columns, table.Columns);
        }
 public override Table Execute(Table table)
 {
     Table newTable = new Table(table.Name, table);
     foreach (Column column in table.Columns)
     {
         Column newColumn = new Column(column.Name, column.Type, new List<Cell>(column.Cells));
         int z = 0;
         foreach (int index in invalidRows)
         {
             if ((index-z)<newColumn.Cells.Count) newColumn.Cells.RemoveAt(index-z);
             z++;
         }
         newTable.AddColumn(newColumn);
     }
     return newTable;
 }
        public void AddColumnTest()
        {
            var column1 = new Mock<Column>();
            var column2 = new Mock<Column>();
            var column3 = new Mock<Column>();
            List<Column> columns = new List<Column>();
            columns.Add(column1.Object);
            columns.Add(column2.Object);

            Table table = new Table("Tabela", null, columns);

            List<Column> columnsCopy = new List<Column>();
            columnsCopy = columns.Select(column => column).ToList();

            columnsCopy.Add(column3.Object);
            table.AddColumn(column3.Object);

            CollectionAssert.Equals(columnsCopy, table.Columns);
        }
Exemplo n.º 8
0
        static void Main(string[] args)
        {
            // ------------------------ FIRST TABLE --------------------------------------
            Cell c1 = new Cell(2011);
            Cell c2 = new Cell(2012);
            Cell c3 = new Cell(2013);

            Cell s1 = new Cell("Kraków");
            Cell s2 = new Cell("Kraków");
            Cell s3 = new Cell("Gdańsk");
            Cell s4 = new Cell("Gdańsk");
            Cell s5 = new Cell("Wrocław");
            Cell s6 = new Cell("Poznań");
            Cell s7 = new Cell("Wawa");
            Cell s8 = new Cell("Gdańsk");
            Cell s9 = new Cell("Rzym");

            Cell l1 = new Cell((int)15);
            Cell l2 = new Cell((int)20);
            Cell l3 = new Cell((int)20);
            Cell l4 = new Cell((int)30);
            Cell l5 = new Cell((int)40);
            Cell l6 = new Cell((int)50);
            Cell l7 = new Cell((int)60);
            Cell l8 = new Cell((int)80);
            Cell l9 = new Cell((int)11);

            Cell p1 = new Cell(2);

            Column c = new Column("Rok", DataType.StringDimension);
            c.AddCell(c1);
            c.AddCell(c1);
            c.AddCell(c2);
            c.AddCell(c3);
            c.AddCell(c2);
            c.AddCell(c3);
            c.AddCell(c1);
            c.AddCell(c1);

            Column s = new Column("Miasto", DataType.StringDimension);
            s.AddCell(s1);
            s.AddCell(s2);
            s.AddCell(s3);
            s.AddCell(s4);
            s.AddCell(s5);
            s.AddCell(s6);
            s.AddCell(s7);
            s.AddCell(s8);

            Column l = new Column("Sprzedaż", DataType.FloatFact);
            l.AddCell(l1);
            l.AddCell(l2);
            l.AddCell(l3);
            l.AddCell(l4);
            l.AddCell(l5);
            l.AddCell(l6);
            l.AddCell(l7);
            l.AddCell(l8);

            Column p = new Column("Coś", DataType.IntegerFact);
            p.AddCell(p1);
            p.AddCell(p1);
            p.AddCell(p1);
            p.AddCell(p1);
            p.AddCell(p1);
            p.AddCell(p1);
            p.AddCell(p1);
            p.AddCell(p1);

            List<Column> mylist = new List<Column>();
            //mylist.Add(c);
            mylist.Add(s);
            mylist.Add(l);
            mylist.Add(p);

            Table first_table = new Table("Dane1", null, mylist);
            //Console.WriteLine(first_table);
            first_table.print();

            // ------------------------ SECOND TABLE --------------------------------------

            Cell s11 = new Cell("Berlin");
            Cell s21 = new Cell("Kolonia");
            Cell s31 = new Cell("Hamburg");

            Cell l11 = new Cell(70.5);
            Cell l21 = new Cell(65);
            Cell l31 = new Cell((double)15);

            Column ss = new Column("Miasto", DataType.StringDimension);
            ss.AddCell(s11);
            ss.AddCell(s21);
            ss.AddCell(s31);

            Column ll = new Column("Sprzedaż", DataType.FloatFact);
            ll.AddCell(l11);
            ll.AddCell(l21);
            ll.AddCell(l31);

            Column pp = new Column("Coś", DataType.IntegerFact);
            pp.AddCell(p1);
            pp.AddCell(p1);
            pp.AddCell(p1);

            List<Column> mylist1 = new List<Column>();
            mylist1.Add(ss);
            mylist1.Add(ll);
            mylist1.Add(pp);

            Table second_table = new Table("Dane2", null, mylist1);

            // ------------------------ TABLE --------------------------------------------
            mylist = new List<Column>();
            mylist.Add(c);
            mylist.Add(s);
            mylist.Add(l);
            mylist.Add(p);
            Table second = new Table("Tabeleczka", null, mylist);
            //Console.WriteLine(second);
            second.print();

            // ------------------------ GROUP COMMAND -----------------------------------
            Dictionary<Column, Aggregation> dict = new Dictionary<Column, Aggregation>();
            dict.Add(l, new AverageAggregation());
            dict.Add(p, new SumAggregation());
            Command cmd = new GroupCommand(new List<Column> { s }, dict);
            first_table.Execute(cmd).print();
            //Console.WriteLine(first_table.Execute(cmd));
            dict[l] = new CountAggregation();
            //Console.WriteLine(first_table.Execute(cmd));
            first_table.Execute(cmd).print();

            dict = new Dictionary<Column, Aggregation>();
            dict.Add(l, new AverageAggregation());
            dict.Add(p, new SumAggregation());
            cmd = new GroupCommand(new List<Column> { c, s }, dict);
            //Console.WriteLine(second.Execute(cmd));
            second.Execute(cmd).print();

            //------------------------- OTHER COMMANDS -----------------------------------

            first_table.Execute(new SelectCommand(new List<int> { 0 })).print();
            first_table.Execute(new SelectCommand(new List<int> { 1 })).print();

            first_table.Execute(new FilterCommand(first_table.Columns[1], cellContent => (double)cellContent > 20)).print();

            first_table.Execute(new ComputationOfTwoColumnsCommand(first_table.Columns[1], first_table.Columns[2], (cellContent, cell2Content) => (double)cellContent + (double)cell2Content)).print();

            Table result = first_table.Execute(new ComputationOfOneColumnCommand(first_table.Columns[1], cellContent => (double)cellContent * 2));
            Table modified = new Table(result.Name, first_table, result.Columns);
            modified.print();
            modified.Undo().print();

            first_table.Execute(new VerticalJoinCommand(second_table)).print();

            // ------------------------ AGGREGATION TESTS ---------------------------------------
            List<Cell> cells = new List<Cell>();
            cells.Add(l11);
            cells.Add(l21);
            cells.Add(l31);

            Console.WriteLine((double)(new SumAggregation()).GetAggregatedValue(cells));
            Console.WriteLine((double)(new MaxAggregation()).GetAggregatedValue(cells));
            Console.WriteLine((int)(new CountAggregation()).GetAggregatedValue(cells));
            Console.WriteLine((double)(new MinAggregation()).GetAggregatedValue(cells));
            Console.WriteLine((double)(new AverageAggregation()).GetAggregatedValue(cells));

            Console.ReadKey();
        }
        public void ExecuteTest()
        {
            var command = new Mock<Command>();
            var result = new Mock<Table>();

            command.Setup(foo => foo.Execute(It.IsAny<Table>())).Returns(result.Object);

            Table table = new Table("Nazwa", null);
            Table table2 = table.Execute(command.Object);

            Assert.AreEqual(table2, result.Object);
        }
Exemplo n.º 10
0
 public void UndoTest()
 {
     Table table1 = new Table("table1", null);
     Table table2 = new Table("table2", table1);
     Assert.AreEqual(table1, table2.Undo());
 }
Exemplo n.º 11
0
        public void ToStringTest()
        {
            var column1 = new Mock<Column>();
            var column2 = new Mock<Column>();
            var column3 = new Mock<Column>();
            column1.Setup(foo => foo.ToString()).Returns("c1");
            column2.Setup(foo => foo.ToString()).Returns("c2");
            column3.Setup(foo => foo.ToString()).Returns("c3");

            List<Column> columns = new List<Column>();

            columns.Add(column1.Object);
            columns.Add(column2.Object);
            columns.Add(column3.Object);

            string tableString = "Nazwa\n";
            foreach (Column column in columns)
            {
                tableString += column.ToString();
                tableString += "\n";
            }

            Table table = new Table("Nazwa", null, columns);
            Assert.AreEqual(table.ToString(), tableString);
        }
Exemplo n.º 12
0
 public void NormalizeTest()
 {
     string _name = string.Empty; // TODO: Initialize to an appropriate value
     Table previous = null; // TODO: Initialize to an appropriate value
     List<Column> columns = null; // TODO: Initialize to an appropriate value
     Table target = new Table(_name, previous, columns); // TODO: Initialize to an appropriate value
     Table expected = null; // TODO: Initialize to an appropriate value
     Table actual;
     actual = target.Normalize();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Exemplo n.º 13
0
 public void NameTest()
 {
     Table table = new Table("Nazwa", null);
     Assert.AreEqual("Nazwa", table.Name);
 }
Exemplo n.º 14
0
 public Table()
 {
     this._name = "";
     this.columns = new List<Column>();
     this.previous = null;
 }
 public VerticalJoinCommand(Table table)
 {
     secondTable = table;
 }
Exemplo n.º 16
0
 public abstract Table Execute(Table table);