AMashenkov commented on a change in pull request #243: URL: https://github.com/apache/ignite-3/pull/243#discussion_r684220039
########## File path: modules/table/src/test/java/org/apache/ignite/internal/table/type/NumericTypesSerializerTest.java ########## @@ -0,0 +1,257 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.table.type; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.math.RoundingMode; +import java.util.Arrays; +import java.util.List; +import java.util.Random; +import java.util.UUID; +import org.apache.ignite.internal.schema.Column; +import org.apache.ignite.internal.schema.InvalidTypeException; +import org.apache.ignite.internal.schema.NativeTypes; +import org.apache.ignite.internal.schema.SchemaDescriptor; +import org.apache.ignite.internal.schema.marshaller.TupleMarshaller; +import org.apache.ignite.internal.schema.row.Row; +import org.apache.ignite.internal.table.TupleBuilderImpl; +import org.apache.ignite.internal.table.TupleMarshallerImpl; +import org.apache.ignite.internal.table.impl.DummySchemaManagerImpl; +import org.apache.ignite.internal.util.Pair; +import org.apache.ignite.table.Tuple; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** */ +public class NumericTypesSerializerTest { + /** Random. */ + private Random rnd = new Random(); + + /** Schema descriptor. */ + private SchemaDescriptor schema; + + /** + * @return List of BigInteger pairs for test. + */ + private static List<Pair<BigInteger, BigInteger>> numbers() { + return Arrays.asList( + new Pair<>(BigInteger.valueOf(10L), BigInteger.valueOf(10)), + new Pair<>(BigInteger.valueOf(-10L), BigInteger.valueOf(-10)), + new Pair<>(new BigInteger("10"), BigInteger.valueOf(10)), + new Pair<>(new BigInteger("1000").divide(BigInteger.TEN), BigInteger.valueOf(10).multiply(BigInteger.TEN)), + new Pair<>(new BigInteger("999999999"), BigInteger.valueOf(999999999L)), + new Pair<>(new BigInteger("+999999999"), BigInteger.valueOf(999999999L)), + new Pair<>(new BigInteger("-999999999"), BigInteger.valueOf(-999999999L)) + ); + } + + /** + * @return List of string decimal representations for test. + */ + private static String[] stringDecimalRepresentation() { + return new String[]{"0", "0.00", "123", "-123", "1.23E3", "1.23E+3", "12.3E+7", "12.0", "12.3", "0.00123", + "-1.23E-12", "1234.5E-4", "0E+7", "-0", "123456789.0123", "123456789.1", "123456789.112312315413", + "123456789.0123", "123.123456789", "123456789.3210"}; + } + + @BeforeEach + public void setup() { + long seed = System.currentTimeMillis(); + + rnd = new Random(seed); + } + + /** + * + */ + @ParameterizedTest + @MethodSource("numbers") + public void testNumber(Pair<BigInteger, BigInteger> pair) { + schema = new SchemaDescriptor( + UUID.randomUUID(), + 42, + new Column[] {new Column("key", NativeTypes.INT64, false)}, + new Column[] { + new Column("number1", NativeTypes.numberOf(19), false), + new Column("number2", NativeTypes.numberOf(10), false) + } + ); + + final TupleBuilderImpl tup = new TupleBuilderImpl(schema); + + tup.set("key", rnd.nextLong()); + tup.set("number1", pair.getFirst()); + tup.set("number2", pair.getSecond()); + + Tuple keyTuple = new TupleBuilderImpl(schema).set("key", rnd.nextLong()).build(); + + TupleMarshaller marshaller = new TupleMarshallerImpl(new DummySchemaManagerImpl(schema)); + + final Row row = marshaller.marshal(keyTuple, tup.build()); Review comment: Let's check if rows will have same binary representation. -- 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]
