Skip to content

Commit

Permalink
fix: generator constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
pradomota committed Apr 16, 2024
1 parent b141aae commit e86d525
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions app/src/main/java/io/confluent/avro/random/generator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,25 @@ private static Generator getGenerator(String schema, String schemaFile) throws I
return getGenerator(schema, schemaFile, Optional.empty(), Optional.empty());
}

private static Generator getGenerator(String schema, String schemaFile, Optional<Double> malformedNotInformedRate, Optional<Double> malformedColumnRate) throws IOException {
private static Generator getGenerator(String schema, String schemaFile, Optional<Double> notInformedColumnRate, Optional<Double> malformedColumnRate) throws IOException {
if (schema != null) {
return new Generator.Builder().schemaString(schema)
.malformedColumnRate(malformedColumnRate)
.notInformedColumnRate(notInformedColumnRate)
.build();
} else if (!schemaFile.equals("-")) {
return new Generator.Builder()
.schemaFile(new File(schemaFile), malformedNotInformedRate.isPresent())
.schemaFile(new File(schemaFile), notInformedColumnRate.isPresent())
.malformedColumnRate(malformedColumnRate)
.notInformedColumnRate(notInformedColumnRate)
.build();
} else {
System.err.println("Reading schema from stdin...");
return new Generator.Builder().schemaStream(System.in).malformedColumnRate(malformedColumnRate).build();
return new Generator.Builder()
.schemaStream(System.in)
.malformedColumnRate(malformedColumnRate)
.notInformedColumnRate(notInformedColumnRate)
.build();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ record = (GenericRecord) generator.generate();
}
}

assertEquals("Wrong string distribution", 0.45, ((double) stringResults.size()) / 100, 0.1);
assertEquals("Wrong int distribution", 0.45, ((double) intResults.size()) / 100, 0.1);
assertEquals("Wrong not informed distribution", 0.1, ((double) notInformedResults.size()) / 100, 0.1);
assertEquals("Wrong string distribution", 0.45, ((double) stringResults.size()) / 100, 0.2);
assertEquals("Wrong int distribution", 0.45, ((double) intResults.size()) / 100, 0.2);
assertEquals("Wrong not informed distribution", 0.1, ((double) notInformedResults.size()) / 100, 0.2);
assertNotEquals("Empty not informed values", notInformedResults.size(), 0);
}

Expand Down

0 comments on commit e86d525

Please sign in to comment.