Skip to content

Commit

Permalink
testParseOfSampleFeedStatus()
Browse files Browse the repository at this point in the history
  • Loading branch information
DamonHD committed May 28, 2024
1 parent c8bf00d commit 9c1936b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 6 additions & 2 deletions javasrc/org/hd/d/statsHouse/feedHits/data/FeedStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public record FeedStatus(int hits, int bytes, String colTypes, List<Integer> col
* The colTypes element count must match cols.
* <p>
* The record is trim()med of excess leading and trailing whitespace before parsing.
* <p>
* Content validation is deferred to the constructor.
*/
public static FeedStatus parseRecord(final String line)
{
Expand All @@ -84,8 +86,10 @@ public static FeedStatus parseRecord(final String line)
final String colTypes = rawFields[2];
final String[] colTypeArray = colTypes.split(":");
final int nCols = colTypeArray.length;
// Reparse to capture index field in one go.
final String[] rawFields2 = trimmed.split(" ", 3 + nCols + 1);
// Reparse to capture index field in final slot.
final int expectedFieldCount = 3 + nCols + 1;
final String[] rawFields2 = trimmed.split(" ", expectedFieldCount);
if(rawFields2.length != expectedFieldCount) { throw new IllegalArgumentException("too few cols"); }
final List<Integer> colArray = new ArrayList<>(nCols);
for(int c = 0; c < nCols; ++c) { colArray.add(Integer.parseInt(rawFields[3 + c], 10)); }
final String index = rawFields2[rawFields2.length -1];
Expand Down
16 changes: 15 additions & 1 deletion test/javasrc/localtest/feedHits/TestDataRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,24 @@
*/
public final class TestDataRead extends TestCase
{
public static final String sample_FeedStatus_ALL_record =
"12857 71404021 200:304:406:429:SH 2987 1993 359 7476 5129 ALL";

/**Test construction of a FeedStatus record, eg that it does not throw. */
public static void testConstructionOfSampleFeedStatus()
{
//12857 71404021 200:304:406:429:SH 2987 1993 359 7476 5129 ALL
new FeedStatus(12857, 71404021, "200:304:406:429:SH", List.of(2987, 1993, 359, 7476, 5129), "ALL");
}

/**Test parse of a FeedStatus record, eg that it does not throw. */
public static void testParseOfSampleFeedStatus()
{
final FeedStatus fs = FeedStatus.parseRecord(sample_FeedStatus_ALL_record);
assertNotNull(fs);
assertEquals(12857, fs.hits());
assertEquals(71404021, fs.bytes());
assertEquals("200:304:406:429:SH", fs.colTypes());
// TODO
assertEquals("ALL", fs.index());
}
}

0 comments on commit 9c1936b

Please sign in to comment.