void VerifyGridEquals(HaystackGrid grid, HaystackDictionary meta, object[] cols, HaystackValue[][] rows) { // meta Assert.IsTrue(grid.Meta.Equals(meta)); // cols Assert.AreEqual(grid.ColumnCount, cols.Length / 2); for (int i = 0; i < grid.ColumnCount; ++i) { Assert.AreEqual(grid.Column(i).Name, cols[i * 2 + 0]); Assert.IsTrue(grid.Column(i).Meta.Equals(cols[i * 2 + 1])); } // rows Assert.AreEqual(grid.RowCount, rows.Length); for (int ri = 0; ri < rows.Length; ++ri) { var expected = rows[ri]; var actual = grid.Row(ri); for (int ci = 0; ci < expected.Length; ++ci) { Assert.AreEqual(expected[ci], actual[grid.Column(ci).Name]); } } }
HaystackColumn VerifyCol(HaystackGrid g, int i, string n) { var col = g.Column(i); Assert.IsTrue(g.Column(i).Equals(g.Column(n))); Assert.AreEqual(col.Name, n); return(col); }
public void WriteGrid(HaystackGrid grid) { // meta WriteValue("ver:\"").WriteValue(_version).WriteValue(".0\"").WriteMeta(grid.Meta).WriteNewline(); // cols if (grid.ColumnCount == 0) { // technically this shoudl be illegal, but // for robustness handle it here throw new ArgumentException("Grid has no cols", "grid"); } else { for (int i = 0; i < grid.ColumnCount; ++i) { if (i > 0) { WriteValue(','); } WriteColumn(grid.Column(i)); } } WriteNewline(); // rows for (int i = 0; i < grid.RowCount; ++i) { WriteRow(grid, grid.Row(i)); WriteNewline(); } }
public void TestEmpty() { var grid = new HaystackGrid(); Assert.AreEqual(grid.Meta, new HaystackDictionary()); Assert.AreEqual(grid.RowCount, 0); Assert.IsTrue(grid.IsEmpty()); Assert.IsFalse(grid.HasColumn("foo")); Assert.ThrowsException <HaystackUnknownNameException>(() => grid.Column("foo")); }