[ 
https://issues.apache.org/jira/browse/TINKERPOP-3166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18010771#comment-18010771
 ] 

ASF GitHub Bot commented on TINKERPOP-3166:
-------------------------------------------

andreachild commented on code in PR #3153:
URL: https://github.com/apache/tinkerpop/pull/3153#discussion_r2241263977


##########
gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/util/NumberHelperTest.java:
##########
@@ -709,4 +710,84 @@ public void shouldCoerceToConvertToFloatIfCanFit() {
         final Double value = 42.0;
         assertEquals(Float.valueOf(42.0f), NumberHelper.coerceTo(value, 
Float.class));
     }
+
+
+    @Test
+    public void shouldCastToReturnSameInstanceForSameClass() {
+        final Integer value = 42;
+        assertEquals(value, NumberHelper.castTo(value, N.int_));
+    }
+
+    @Test
+    public void shouldCastToConvertToByte() {
+        final Integer value = 42;
+        assertEquals(Byte.valueOf((byte) 42), NumberHelper.castTo(value, 
N.byte_));
+    }
+
+    @Test
+    public void shouldCastToConvertToShort() {
+        final Integer value = 42;
+        assertEquals(Short.valueOf((short) 42), NumberHelper.castTo(value, 
N.short_));
+    }
+
+    @Test
+    public void shouldCastToConvertToLong() {
+        final Integer value = 42;
+        assertEquals(Long.valueOf(42L), NumberHelper.castTo(value, N.long_));
+    }
+
+    @Test
+    public void shouldCastToConvertToFloat() {
+        final Integer value = 42;
+        assertEquals(Float.valueOf(42.0f), NumberHelper.castTo(value, 
N.float_));
+    }
+
+    @Test
+    public void shouldCastToConvertToDouble() {
+        final Integer value = 42;
+        assertEquals(Double.valueOf(42.0), NumberHelper.castTo(value, 
N.double_));
+    }
+
+    @Test
+    public void shouldCastToConvertToBigInteger() {
+        final Integer value = 42;
+        assertEquals(BigInteger.valueOf(42), NumberHelper.castTo(value, 
N.bigInt));
+    }
+
+    @Test
+    public void shouldCastToConvertDoubleToBigInteger() {
+        final Double value = new Double("1000000000000000000000");
+        assertEquals(new BigInteger("1000000000000000000000"), 
NumberHelper.castTo(value, N.bigInt));
+    }
+
+    @Test
+    public void shouldCastToConvertToBigDecimal() {
+        final Integer value = 42;
+        assertEquals(BigDecimal.valueOf(42), NumberHelper.castTo(value, 
N.bigDecimal));
+    }
+

Review Comment:
   Suggest to add these test cases:
   
   ```
   @Test
   public void shouldCastDoubleInfinityToFloatInfinity() {
       assertEquals(Float.POSITIVE_INFINITY, 
NumberHelper.castTo(Double.POSITIVE_INFINITY, N.float_));
       assertEquals(Float.NEGATIVE_INFINITY, 
NumberHelper.castTo(Double.NEGATIVE_INFINITY, N.float_));
   }
   
   @Test
   public void shouldCastFloatInfinityToDoubleInfinity() {
       assertEquals(Double.POSITIVE_INFINITY, 
NumberHelper.castTo(Float.POSITIVE_INFINITY, N.double_));
       assertEquals(Double.NEGATIVE_INFINITY, 
NumberHelper.castTo(Float.NEGATIVE_INFINITY, N.double_));
   }
   
   @Test
   public void shouldCastFloatNaNToDoubleNaN() {
       assertEquals(Double.NaN, NumberHelper.castTo(Float.NaN, N.double_));
   }
   
   @Test
   public void shouldCastDoubleNaNToFloatNaN() {
       assertEquals(Float.NaN, NumberHelper.castTo(Double.NaN, N.float_));
   }
   ```





> Add number conversion step asNumber()
> -------------------------------------
>
>                 Key: TINKERPOP-3166
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-3166
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: language
>    Affects Versions: 3.8.0
>            Reporter: Yang Xia
>            Priority: Major
>
> Given the addition of the {{asString()}} and {{asDate()}} steps in the 3.7 
> line, it should also be helpful to add an {{asNumber()}} step that does 
> numerical casting/conversions.
> The current idea is for the {{asNumber()}} step to convert the incoming 
> traverser to the nearest parsable type (e.g. int or double) if no argument is 
> provided, or to the desired numerical type, based on a number token 
> ({{{}N{}}}) provided. Like the {{asDate()}} step, it will not be scoped (for 
> now, scopes can be added in the future).
> Some conjured examples:
> {code:java}
> gremlin> g.inject(5).asNumber()
> ==> 5    // parses to int
> gremlin> g.inject(5.123f).asNumber()
> ==> 5.123 
> gremlin> g.inject(5.43).asNumber(N.int) 
> ==> 5 {code}
> More details can be found in the [proposal 
> doc|https://github.com/apache/tinkerpop/blob/master/docs/src/dev/future/proposal-asnumber-step-6.asciidoc].
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to