public void TestIobExceptionOnInvalidIndex() { IWorkbook wb = new HSSFWorkbook(); ISheet sheet = new SheetBuilder(wb, numericCells).Build(); CellRangeAddress rangeAddress = CellRangeAddress.ValueOf("A2:E2"); IChartDataSource <double> numDataSource = DataSources.FromNumericCellRange(sheet, rangeAddress); IndexOutOfRangeException exception = null; try { numDataSource.GetPointAt(-1); } catch (IndexOutOfRangeException e) { exception = e; } Assert.IsNotNull(exception); exception = null; try { numDataSource.GetPointAt(numDataSource.PointCount); } catch (IndexOutOfRangeException e) { exception = e; } Assert.IsNotNull(exception); }
private void AssertDataSourceIsEqualToArray <T>(IChartDataSource <T> ds, T[] array) { Assert.AreEqual(ds.PointCount, array.Length); for (int i = 0; i < array.Length; ++i) { Assert.AreEqual(ds.GetPointAt(i), array[i]); } }
public void TestMixedCellDataSource() { IWorkbook wb = new HSSFWorkbook(); ISheet sheet = new SheetBuilder(wb, mixedCells).Build(); CellRangeAddress mixedCellRange = CellRangeAddress.ValueOf("A1:F1"); IChartDataSource <String> strDataSource = DataSources.FromStringCellRange(sheet, mixedCellRange); IChartDataSource <double> numDataSource = DataSources.FromNumericCellRange(sheet, mixedCellRange); for (int i = 0; i < mixedCells[0].Length; ++i) { if (i % 2 == 0) { Assert.IsNull(strDataSource.GetPointAt(i)); Assert.AreEqual(((double)mixedCells[0][i]), numDataSource.GetPointAt(i), 0.00001); } else { Assert.IsNaN(numDataSource.GetPointAt(i)); Assert.AreEqual(mixedCells[0][i], strDataSource.GetPointAt(i)); } } }
public void TestStringCellDataSource() { IWorkbook wb = new HSSFWorkbook(); ISheet sheet = new SheetBuilder(wb, stringCells).Build(); CellRangeAddress numCellRange = CellRangeAddress.ValueOf("A2:E2"); IChartDataSource <String> numDataSource = DataSources.FromStringCellRange(sheet, numCellRange); Assert.IsTrue(numDataSource.IsReference); Assert.IsFalse(numDataSource.IsNumeric); Assert.AreEqual(numericCells[0].Length, numDataSource.PointCount); for (int i = 0; i < stringCells[1].Length; ++i) { Assert.AreEqual(stringCells[1][i], numDataSource.GetPointAt(i)); } }
public void TestNumericCellDataSource() { IWorkbook wb = new HSSFWorkbook(); ISheet sheet = new SheetBuilder(wb, numericCells).Build(); CellRangeAddress numCellRange = CellRangeAddress.ValueOf("A2:E2"); IChartDataSource <double> numDataSource = DataSources.FromNumericCellRange(sheet, numCellRange); Assert.IsTrue(numDataSource.IsReference); Assert.IsTrue(numDataSource.IsNumeric); Assert.AreEqual(numericCells[0].Length, numDataSource.PointCount); for (int i = 0; i < numericCells[0].Length; ++i) { Assert.AreEqual(((double)numericCells[0][i]) * 2, numDataSource.GetPointAt(i), 0.00001); } }
private static void FillNumCache <T>(CT_NumData cache, IChartDataSource <T> dataSource) { int pointCount = dataSource.PointCount; cache.AddNewPtCount().val = (uint)pointCount; for (int index = 0; index < pointCount; ++index) { double d = Convert.ToDouble((object)dataSource.GetPointAt(index)); if (!double.IsNaN(d)) { CT_NumVal ctNumVal = cache.AddNewPt(); ctNumVal.idx = (uint)index; ctNumVal.v = d.ToString(); } } }
private static void FillStringCache <T>(CT_StrData cache, IChartDataSource <T> dataSource) { int pointCount = dataSource.PointCount; cache.AddNewPtCount().val = (uint)pointCount; for (int index = 0; index < pointCount; ++index) { object pointAt = (object)dataSource.GetPointAt(index); if (pointAt != null) { CT_StrVal ctStrVal = cache.AddNewPt(); ctStrVal.idx = (uint)index; ctStrVal.v = pointAt.ToString(); } } }
private static void FillNumCache <T>(CT_NumData cache, IChartDataSource <T> dataSource) { int numOfPoints = dataSource.PointCount; cache.AddNewPtCount().val = (uint)(numOfPoints); for (int i = 0; i < numOfPoints; ++i) { double value = Convert.ToDouble(dataSource.GetPointAt(i)); if (!double.IsNaN(value)) { CT_NumVal ctNumVal = cache.AddNewPt(); ctNumVal.idx = (uint)(i); ctNumVal.v = (value.ToString()); } } }
private static void FillStringCache <T>(CT_StrData cache, IChartDataSource <T> dataSource) { int numOfPoints = dataSource.PointCount; cache.AddNewPtCount().val = (uint)(numOfPoints); for (int i = 0; i < numOfPoints; ++i) { object value = dataSource.GetPointAt(i); if (value != null) { CT_StrVal ctStrVal = cache.AddNewPt(); ctStrVal.idx = (uint)(i); ctStrVal.v = (value.ToString()); } } }