nastra commented on code in PR #19279:
URL: https://github.com/apache/iceberg/pull/19279#discussion_r4797381480


##########
core/src/test/java/org/apache/iceberg/TestSingleValueParser.java:
##########
@@ -113,6 +113,60 @@ public void testValidDefaults() throws IOException {
     }
   }
 
+  @Test
+  public void testFloatAndDoubleValues() {
+    Type floatType = Types.FloatType.get();
+    assertThat(SingleValueParser.fromJson(floatType, "0")).isEqualTo(0.0f);
+    assertThat(SingleValueParser.fromJson(floatType, "-1")).isEqualTo(-1.0f);
+    assertThat(SingleValueParser.fromJson(floatType, 
"2147483648")).isEqualTo(2147483648.0f);
+    assertThat(SingleValueParser.fromJson(floatType, "9223372036854775808"))
+        .isEqualTo(9223372036854775808.0f);
+    assertThat(SingleValueParser.fromJson(floatType, 
"16777217")).isEqualTo(16777216.0f);
+    assertThat(SingleValueParser.fromJson(floatType, 
"3.4028235e38")).isEqualTo(Float.MAX_VALUE);
+
+    Type doubleType = Types.DoubleType.get();
+    assertThat(SingleValueParser.fromJson(doubleType, "0")).isEqualTo(0.0d);
+    assertThat(SingleValueParser.fromJson(doubleType, "-1")).isEqualTo(-1.0d);
+    assertThat(SingleValueParser.fromJson(doubleType, 
"2147483648")).isEqualTo(2147483648.0d);
+    assertThat(SingleValueParser.fromJson(doubleType, "9223372036854775808"))
+        .isEqualTo(9223372036854775808.0d);
+    assertThat(SingleValueParser.fromJson(doubleType, "9007199254740993"))
+        .isEqualTo(9007199254740992.0d);
+    assertThat(SingleValueParser.fromJson(doubleType, "1" + 
"0".repeat(39))).isEqualTo(1.0e39d);
+
+    assertThat(SingleValueParser.toJson(floatType, 
SingleValueParser.fromJson(floatType, "1")))
+        .isEqualTo("1.0");
+    assertThat(SingleValueParser.toJson(doubleType, 
SingleValueParser.fromJson(doubleType, "1")))
+        .isEqualTo("1.0");
+  }
+
+  @Test
+  public void testInvalidFloatAndDouble() {
+    String[][] outOfRange = {
+      {"float", "1" + "0".repeat(39)},
+      {"float", "-1" + "0".repeat(39)},
+      {"float", "1e39"},

Review Comment:
   please also test with `3.4028236e38` for float and something similar for 
Double that is just above Double.MAX_VALUE.
   
   Also use `@ParameterizedTest` for this class. That way we can remove the for 
loops and it will be clearer which value is affected when the test ever fails



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to