public ComputationOfTwoColumnsCommand(Column column, Column column2, Del del) { this.column = column; this.column2 = column2; newRows = new List<Cell>(); this.del = del; }
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; }
public FilterCommand(Column column,Del del) { invalidRows = new List<int>(); foreach (Cell cell in column.Cells) { if (!del.Invoke(cell.Content)) invalidRows.Add(column.Cells.IndexOf(cell)); } }
public void CellsTest() { var cell1 = new Mock<Cell>(); var cell2 = new Mock<Cell>(); List<Cell> cells = new List<Cell>(); cells.Add(cell1.Object); cells.Add(cell2.Object); Column column = new Column("Kolumna", DataType.IntegerFact, cells); Assert.AreEqual(cells,column.Cells); }
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 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 AddCellTest() { var cell1 = new Mock<Cell>(); var cell2 = new Mock<Cell>(); var cell3 = new Mock<Cell>(); List<Cell> cells = new List<Cell>(); cells.Add(cell1.Object); cells.Add(cell2.Object); cells.Add(cell3.Object); Column column = new Column("Kolumna", DataType.IntegerFact, cells); List<Cell> cellsCopy = new List<Cell>(); cellsCopy = cells.Select(cell => cell).ToList(); cellsCopy.Add(cell3.Object); column.AddCell(cell3.Object); CollectionAssert.AreEqual(cellsCopy, column.Cells); }
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 ComputationOfOneColumnCommand(Column column, Del del) { this.column = column; newRows = new List<Cell>(); this.del = del; }
public virtual bool RemoveColumn(Column column) { return columns.Remove(column); }
public virtual void AddColumn(Column column) { this.columns.Add(column); }
public void NameTest() { Column column = new Column("Nazwa", DataType.StringDimension); Assert.AreEqual("Nazwa", column.Name); }
public void TypeTest() { Column column = new Column("Nazwa", DataType.StringDimension); Assert.AreEqual(DataType.StringDimension, column.Type); column = new Column("Nazwa", DataType.IntegerFact); Assert.AreEqual(DataType.IntegerFact, column.Type); }
public void ToStringTest() { //kolumna integerów string name = "Nazwa"; List<Cell> cells = new List<Cell>(); var cell1 = new Mock<Cell>(); var cell2 = new Mock<Cell>(); var cell3 = new Mock<Cell>(); var cell4 = new Mock<Cell>(); cell1.Setup(foo => foo.ToString()).Returns("5"); cell2.Setup(foo => foo.ToString()).Returns("6"); cell3.Setup(foo => foo.ToString()).Returns("7"); cell4.Setup(foo => foo.ToString()).Returns("1"); cells.Add(cell1.Object); cells.Add(cell2.Object); cells.Add(cell3.Object); cells.Add(cell4.Object); Column target = new Column(name, DataType.IntegerFact, cells); string expected = name + "\n5 6 7 1 "; string actual; actual = target.ToString(); Assert.AreEqual(expected, actual); //kolumna stringów cell1.Setup(foo => foo.ToString()).Returns("pięć"); cell2.Setup(foo => foo.ToString()).Returns("sześć"); cell3.Setup(foo => foo.ToString()).Returns("siedem"); cell4.Setup(foo => foo.ToString()).Returns("jeden"); cells = new List<Cell>(); cells.Add(cell1.Object); cells.Add(cell2.Object); cells.Add(cell3.Object); cells.Add(cell4.Object); target = new Column(name, DataType.StringDimension, cells); expected = name + "\npięć sześć siedem jeden "; actual = target.ToString(); Assert.AreEqual(expected, actual); }