-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix, document, and test ColumnType.compare and Table.compareRows (#21)
* Fix document and test ColumnType.compare and Table.compareRows * Fix sonar comment * More explicit test name
- Loading branch information
Showing
3 changed files
with
77 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core/src/test/java/tech/tablesaw/api/TableCompareRowsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package tech.tablesaw.api; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import tech.tablesaw.io.csv.CsvReadOptions; | ||
|
||
class TableCompareRowsTest { | ||
|
||
private static final String SOURCE_FILE_NAME = "../data/missing_values.csv"; | ||
private static Table testTable; | ||
|
||
@BeforeAll | ||
static void readTables() { | ||
testTable = Table.read().usingOptions(CsvReadOptions | ||
.builder(new File(SOURCE_FILE_NAME)) | ||
.missingValueIndicator("-")); | ||
} | ||
|
||
@Test | ||
void testCompareRowsIdentical() { | ||
for(int i = 0; i < testTable.rowCount(); i++) { | ||
assertTrue(Table.compareRows(i, testTable, testTable), "Row " + i + " is not equal to itself"); | ||
} | ||
} | ||
|
||
@Test | ||
void testCompareRowsDifferent() { | ||
Table differentTable = testTable.copy().sortDescendingOn("Sales"); | ||
for(int i = 0; i < testTable.rowCount(); i++) { | ||
assertFalse(Table.compareRows(i, testTable, differentTable), "Row " + i + " is equal to a different row"); | ||
} | ||
} | ||
|
||
@Test | ||
void testCompareRowsDifferentColumns() { | ||
Table differentTable = testTable.copy().removeColumns("Sales"); | ||
for(int i = 0; i < testTable.rowCount(); i++) { | ||
assertFalse(Table.compareRows(i, testTable, differentTable), "Row " + i + " is equal to a row with less columns"); | ||
} | ||
} | ||
|
||
@Test | ||
void testCompareRowsOutOfBound() { | ||
Table differentTable = testTable.copy().dropRows(0); | ||
int lastRowNumber = testTable.rowCount() - 1; | ||
assertThrows(IndexOutOfBoundsException.class, | ||
() -> Table.compareRows(lastRowNumber, testTable, differentTable), | ||
"Row outside range does not throw exception"); | ||
} | ||
|
||
} |