public void CsvComparisonErrorsMissingTest()
        {
            var expectedCsv = CsvTable.Parse("SimpleExpected.csv");
            var actualCsv   = CsvTable.Parse("SimpleActualMissing.csv");
            var comparison  = new CsvComparison(expectedCsv, actualCsv, Tolerance.Parse("2%;0.001"));
            var expected    = comparison.ExpectedTable;

            Assert.AreEqual(2, expected.RowCount, "Expected RowCount");
            var actual = comparison.ActualTable;

            Assert.AreEqual(1, actual.RowCount, "Actual RowCount");
            Assert.AreEqual(4, comparison.ErrorCount(), "Error Count = 2");
            var query    = comparison.Query();
            var errorRow = query[0] as Collection <object>;

            Assert.AreEqual("B1", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Missing", QueryValue(errorRow, "Issue"));
            errorRow = query[1] as Collection <object>;
            Assert.AreEqual("B2", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Missing", QueryValue(errorRow, "Issue"));
            errorRow = query[2] as Collection <object>;
            Assert.AreEqual("A3", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Missing", QueryValue(errorRow, "Issue"));
            errorRow = query[3] as Collection <object>;
            Assert.AreEqual("B3", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Missing", QueryValue(errorRow, "Issue"));
        }
        public void CsvComparisonErrorsSurplusTest()
        {
            var expectedCsv = CsvTable.Parse("SimpleExpected.csv");
            var actualCsv   = CsvTable.Parse("SimpleActualSurplus.csv");
            var comparison  = new CsvComparison(expectedCsv, actualCsv, Tolerance.Parse("2%;0.001"));

            Assert.AreEqual(3, comparison.ErrorCount(), "Error Count = 3");
            var query    = comparison.Query();
            var errorRow = query[0] as Collection <object>;

            Assert.AreEqual("C1", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Surplus", QueryValue(errorRow, "Issue"));
            errorRow = query[1] as Collection <object>;
            Assert.AreEqual("C2", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Surplus", QueryValue(errorRow, "Issue"));
            errorRow = query[2] as Collection <object>;
            Assert.AreEqual("A4", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("Surplus", QueryValue(errorRow, "Issue"));
        }
        public void CsvTableLoadQueryTableTest()
        {
            var timeSeries = CsvTable.Parse("String01_TestData.csv");

            Assert.AreEqual(7, timeSeries.ColumnCount, "ColumnCount OK");
            var collection = timeSeries.Query();

            Assert.AreEqual(62, collection.Count, "Query column count");
            var header = collection[0] as Collection <object>;

            Assert.IsNotNull(header, "Query Header not null ");
            Assert.AreEqual(7, header.Count, "Query header count");
            Assert.AreEqual("Hi7,Hi8", timeSeries.Data[60][1], "Item with comma got across OK");

            var tableCollection = timeSeries.DoTable(null);

            Assert.AreEqual(63, tableCollection.Count);
            Assert.AreEqual(7, tableCollection[0].Count, "Table column count");
            Assert.AreEqual("report:Timestamp", tableCollection[0][0], "Table Timestamp header");
            Assert.AreEqual("report:Hi8", tableCollection[62][3], "Table last row column 3");

            Assert.AreEqual(2, timeSeries.HeaderIndex("ExpectedQuality"), "HeaderIndex existing");
            try
            {
                timeSeries.HeaderIndex("Nonexisting");
                Assert.Fail("No exception raised for non-existing HeaderIndex");
            }
            catch (ArgumentException)
            {
            }

            var tempFileName = Path.GetTempFileName();

            timeSeries.SaveTo(tempFileName);
            var timeSeries2 = CsvTable.Parse(tempFileName);

            Assert.AreEqual(7, timeSeries2.ColumnCount, "Number of columns in saved and loaded CSV");
            Assert.AreEqual("Hi7,Hi8", timeSeries2.Data[60][1], "Item with comma got back OK");
            Assert.AreEqual(62, timeSeries2.Data.Count, "Number of rows in saved and loaded CSV");
            File.Delete(tempFileName);
        }
        public void CsvComparisonErrorsStreamDataTest()
        {
            var baseCsv = CsvTable.Parse("StreamData1.csv");

            Console.WriteLine($"Base: columns={baseCsv.ColumnCount}; rows={baseCsv.RowCount}");
            var newCsv = CsvTable.Parse("StreamData2.csv");

            Console.WriteLine($"New: columns={newCsv.ColumnCount}; rows={newCsv.RowCount}");
            var comparison = new CsvComparison(baseCsv, newCsv, Tolerance.Parse("2%;0.001"));

            Assert.AreEqual(1, comparison.ErrorCount(), "Error Count = 1");
            var query    = comparison.Query();
            var errorRow = query[0] as Collection <object>;

            Assert.AreEqual("H2", QueryValue(errorRow, "Cell"));
            Assert.AreEqual("2", QueryValue(errorRow, "Row No"));
            Assert.AreEqual("Total Liquid Mole Fraction", QueryValue(errorRow, "Row Name"));
            Assert.AreEqual("8 (H)", QueryValue(errorRow, "Column No"));
            Assert.AreEqual("A11", QueryValue(errorRow, "Column Name"));
            Assert.AreEqual("0.01 != 0", QueryValue(errorRow, "Value"));
            Assert.AreEqual("0.01", QueryValue(errorRow, "Delta"));
            Assert.IsTrue(string.IsNullOrEmpty(QueryValue(errorRow, "Delta %").ToString()));
        }