public virtual void test_nextBatch2() { using (CsvIterator csvFile = CsvIterator.of(CharSource.wrap(CSV1), true)) { ImmutableList <string> headers = csvFile.headers(); assertEquals(headers.size(), 2); assertEquals(headers.get(0), "h1"); assertEquals(headers.get(1), "h2"); IList <CsvRow> a = csvFile.nextBatch(3); assertEquals(a.Count, 2); CsvRow row0 = a[0]; assertEquals(row0.headers(), headers); assertEquals(row0.fieldCount(), 2); assertEquals(row0.field(0), "r11"); assertEquals(row0.field(1), "r12"); CsvRow row1 = a[1]; assertEquals(row1.headers(), headers); assertEquals(row1.fieldCount(), 2); assertEquals(row1.field(0), "r21"); assertEquals(row1.field(1), "r22"); IList <CsvRow> d = csvFile.nextBatch(2); assertEquals(d.Count, 0); assertEquals(csvFile.hasNext(), false); assertEquals(csvFile.hasNext(), false); } }
//------------------------------------------------------------------------- public virtual void nextBatch_predicate() { using (CsvIterator csvFile = CsvIterator.of(CharSource.wrap(CSV5GROUPED), true)) { ImmutableList <string> headers = csvFile.headers(); assertEquals(headers.size(), 2); assertEquals(headers.get(0), "id"); assertEquals(headers.get(1), "value"); int batches = 0; int total = 0; while (csvFile.hasNext()) { CsvRow first = csvFile.peek(); string id = first.getValue("id"); IList <CsvRow> batch = csvFile.nextBatch(row => row.getValue("id").Equals(id)); assertEquals(batch.Select(row => row.getValue("id")).Distinct().Count(), 1); batches++; total += batch.Count; } assertEquals(batches, 3); assertEquals(total, 6); } }