Java Code Examples for java.math.BigInteger#TEN

The following examples show how to use java.math.BigInteger#TEN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmptyNavigableMap.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class)
public void testSubMapRanges(String description, NavigableMap navigableMap) {
    Object first = isDescending(navigableMap) ? BigInteger.TEN : BigInteger.ZERO;
    Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;

    NavigableMap subMap = navigableMap.subMap(first, true, last, true);

    // same subset
    subMap.subMap(first, true, last, true);

    // slightly smaller
    NavigableMap ns = subMap.subMap(first, false, last, false);
    // slight exapansion
    assertThrows(() -> {
        ns.subMap(first, true, last, true);
    },
        IllegalArgumentException.class,
        description + ": Expansion should not be allowed");

    // much smaller
    subMap.subMap(first, false, BigInteger.ONE, false);
}
 
Example 2
Source File: TransactionDecoderTest.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDecoding() throws Exception {
    BigInteger nonce = BigInteger.ZERO;
    BigInteger gasPrice = BigInteger.ONE;
    BigInteger gasLimit = BigInteger.TEN;
    String to = "0x0add5355";
    BigInteger value = BigInteger.valueOf(Long.MAX_VALUE);
    RawTransaction rawTransaction = RawTransaction.createEtherTransaction(
            nonce, gasPrice, gasLimit, to, value);
    byte[] encodedMessage = TransactionEncoder.encode(rawTransaction);
    String hexMessage = Numeric.toHexString(encodedMessage);

    RawTransaction result = TransactionDecoder.decode(hexMessage);
    assertNotNull(result);
    assertEquals(nonce, result.getNonce());
    assertEquals(gasPrice, result.getGasPrice());
    assertEquals(gasLimit, result.getGasLimit());
    assertEquals(to, result.getTo());
    assertEquals(value, result.getValue());
    assertEquals("", result.getData());
}
 
Example 3
Source File: TransactionDecoderTest.java    From web3sdk with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecoding() throws Exception {
    BigInteger gasPrice = BigInteger.ONE;
    BigInteger gasLimit = BigInteger.TEN;
    String to = "0x0add5355";
    BigInteger value = BigInteger.valueOf(Long.MAX_VALUE);
    BigInteger randomid = new BigInteger("500");
    BigInteger blockLimit = new BigInteger("501");
    RawTransaction rawTransaction =
            RawTransaction.createContractTransaction(
                    randomid, gasPrice, gasLimit, blockLimit, value, "0x0000000000");
    byte[] encodedMessage = TransactionEncoder.encode(rawTransaction);
    String hexMessage = Numeric.toHexString(encodedMessage);

    RawTransaction result = TransactionDecoder.decode(hexMessage);
    assertNotNull(result);
    assertEquals(blockLimit, result.getBlockLimit());
    assertEquals(gasPrice, result.getGasPrice());
    assertEquals(gasLimit, result.getGasLimit());
    assertEquals("0x", result.getTo());
    assertEquals(value, result.getValue());
    assertEquals("0000000000", result.getData());
}
 
Example 4
Source File: EmptyNavigableMap.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class)
public void testSubMapRanges(String description, NavigableMap navigableMap) {
    Object first = isDescending(navigableMap) ? BigInteger.TEN : BigInteger.ZERO;
    Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;

    NavigableMap subMap = navigableMap.subMap(first, true, last, true);

    // same subset
    subMap.subMap(first, true, last, true);

    // slightly smaller
    NavigableMap ns = subMap.subMap(first, false, last, false);
    // slight expansion
    assertThrowsIAE(() -> {
        ns.subMap(first, true, last, true);
    },
        description + ": Expansion should not be allowed");

    // much smaller
    subMap.subMap(first, false, BigInteger.ONE, false);
}
 
Example 5
Source File: BigIntSerializer.java    From flink with Apache License 2.0 6 votes vote down vote up
public static void writeBigInteger(BigInteger record, DataOutputView target) throws IOException {
	// null value support
	if (record == null) {
		target.writeInt(0);
		return;
	}
	// fast paths for 0, 1, 10
	// only reference equality is checked because equals would be too expensive
	else if (record == BigInteger.ZERO) {
		target.writeInt(1);
		return;
	}
	else if (record == BigInteger.ONE) {
		target.writeInt(2);
		return;
	}
	else if (record == BigInteger.TEN) {
		target.writeInt(3);
		return;
	}
	// default
	final byte[] bytes = record.toByteArray();
	// the length we write is offset by four, because null and short-paths for ZERO, ONE, and TEN
	target.writeInt(bytes.length + 4);
	target.write(bytes);
}
 
Example 6
Source File: EmptyNavigableMap.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider = "NavigableMap<?,?>", dataProviderClass = EmptyNavigableMap.class)
public void testSubMapRanges(String description, NavigableMap navigableMap) {
    Object first = isDescending(navigableMap) ? BigInteger.TEN : BigInteger.ZERO;
    Object last = (BigInteger.ZERO == first) ? BigInteger.TEN : BigInteger.ZERO;

    NavigableMap subMap = navigableMap.subMap(first, true, last, true);

    // same subset
    subMap.subMap(first, true, last, true);

    // slightly smaller
    NavigableMap ns = subMap.subMap(first, false, last, false);
    // slight exapansion
    assertThrows(() -> {
        ns.subMap(first, true, last, true);
    },
        IllegalArgumentException.class,
        description + ": Expansion should not be allowed");

    // much smaller
    subMap.subMap(first, false, BigInteger.ONE, false);
}
 
Example 7
Source File: TransactionDecoderTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDecodingSignedChainId() throws Exception {
    BigInteger nonce = BigInteger.ZERO;
    BigInteger gasPrice = BigInteger.ONE;
    BigInteger gasLimit = BigInteger.TEN;
    String to = "0x0add5355";
    BigInteger value = BigInteger.valueOf(Long.MAX_VALUE);
    Integer chainId = 1;
    RawTransaction rawTransaction = RawTransaction.createEtherTransaction(
            nonce, gasPrice, gasLimit, to, value);
    byte[] signedMessage = TransactionEncoder.signMessage(
            rawTransaction, chainId.byteValue(), SampleKeys.CREDENTIALS);
    String hexMessage = Numeric.toHexString(signedMessage);

    RawTransaction result = TransactionDecoder.decode(hexMessage);
    assertNotNull(result);
    assertEquals(nonce, result.getNonce());
    assertEquals(gasPrice, result.getGasPrice());
    assertEquals(gasLimit, result.getGasLimit());
    assertEquals(to, result.getTo());
    assertEquals(value, result.getValue());
    assertEquals("", result.getData());
    assertTrue(result instanceof SignedRawTransaction);
    SignedRawTransaction signedResult = (SignedRawTransaction) result;
    assertEquals(SampleKeys.ADDRESS, signedResult.getFrom());
    signedResult.verify(SampleKeys.ADDRESS);
    assertEquals(chainId, signedResult.getChainId());
}
 
Example 8
Source File: TestRuntime81A.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the bean.
 *
 * @return the bean 81 A
 */
private Bean81A createBean() {
	Bean81A result=new Bean81A();
	
	result.id=24;
	result.valueEnum=Bean81Enum.VALUE_1;
	result.valueBidDecimal=BigDecimal.ONE;
	result.valueBidInteger=BigInteger.TEN;
	return result;
}
 
Example 9
Source File: BigIntSerializerTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected BigInteger[] getTestData() {
	Random rnd = new Random(874597969123412341L);

	return new BigInteger[] {
		BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN,
		new BigInteger(1000, rnd), new BigInteger("8745979691234123413478523984729447"),
		BigInteger.valueOf(-1), BigInteger.valueOf(-10000)};
}
 
Example 10
Source File: ActionTestControllerTest.java    From dolphin-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void callPublicMethodWithSeveralBigIntegerParams() {
    Assert.assertNull(controller.getModel().getBigIntegerValue());
    final BigInteger value1 = BigInteger.TEN;
    final BigInteger value2 = BigInteger.TEN;
    final BigInteger value3 = BigInteger.TEN;
    controller.invoke(PUBLIC_WITH_SEVERAL_BIGINTEGER_PARAMS_ACTION, new Param(PARAM_NAME_1, value1), new Param(PARAM_NAME_2, value2), new Param(PARAM_NAME_3, value3));
    Assert.assertEquals(controller.getModel().getBigIntegerValue(), value1.add(value2).add(value3));
}
 
Example 11
Source File: SegmentGeneratorTest.java    From cassandra-reaper with Apache License 2.0 5 votes vote down vote up
@Test
public void testMin() throws Exception {
  BigInteger one = BigInteger.ONE;
  BigInteger ten = BigInteger.TEN;
  assertEquals(one, SegmentGenerator.min(one, ten));
  assertEquals(one, SegmentGenerator.min(ten, one));
  assertEquals(one, SegmentGenerator.min(one, one));
  BigInteger minusTen = BigInteger.TEN.negate();
  assertEquals(minusTen, SegmentGenerator.min(one, minusTen));
}
 
Example 12
Source File: BigIntSerializerTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
protected BigInteger[] getTestData() {
	Random rnd = new Random(874597969123412341L);

	return new BigInteger[] {
		BigInteger.ZERO, BigInteger.ONE, BigInteger.TEN,
		new BigInteger(1000, rnd), new BigInteger("8745979691234123413478523984729447"),
		BigInteger.valueOf(-1), BigInteger.valueOf(-10000)};
}
 
Example 13
Source File: FunctionReturnDecoderTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecodeIndexedDynamicArrayValue() {
    DynamicArray<Uint256> array =
            new DynamicArray<>(Uint256.class, new Uint256(BigInteger.TEN));

    String encoded = TypeEncoder.encodeDynamicArray(array);
    String hash = Hash.sha3(encoded);

    assertEquals(
            FunctionReturnDecoder.decodeIndexedValue(
                    hash, new TypeReference<DynamicArray>() {}),
            (new Bytes32(Numeric.hexStringToByteArray(hash))));
}
 
Example 14
Source File: FunctionReturnDecoderTest.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDecodeIndexedUint256Value() {
    Uint256 value = new Uint256(BigInteger.TEN);
    String encoded = TypeEncoder.encodeNumeric(value);

    assertThat(FunctionReturnDecoder.decodeIndexedValue(
            encoded,
            new TypeReference<Uint256>() {}),
            equalTo(value));
}
 
Example 15
Source File: JsonWriterTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Test
public void test_writeNumber_BigInteger() {
    for (final BigInteger number : new BigInteger[]{
            BigInteger.ZERO,
            BigInteger.ONE,
            BigInteger.TEN,
            new BigInteger("" + Long.MAX_VALUE + "" + Long.MAX_VALUE)}) {
        final String expectedJson = String.valueOf(number);
        final String actualJson = WRITER.use(() -> WRITER.writeNumber(number));
        Assertions.assertThat(actualJson).isEqualTo(expectedJson);
    }
}
 
Example 16
Source File: PrivateTransactionDecoderTest.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecodingPrivacyGroup() {
    final BigInteger nonce = BigInteger.ZERO;
    final BigInteger gasPrice = BigInteger.ONE;
    final BigInteger gasLimit = BigInteger.TEN;
    final String to = "0x0add5355";
    final RawPrivateTransaction rawTransaction =
            RawPrivateTransaction.createTransaction(
                    nonce,
                    gasPrice,
                    gasLimit,
                    to,
                    "",
                    MOCK_ENCLAVE_KEY,
                    MOCK_ENCLAVE_KEY,
                    RESTRICTED);
    byte[] encodedMessage = PrivateTransactionEncoder.encode(rawTransaction);
    final String hexMessage = Numeric.toHexString(encodedMessage);

    final RawPrivateTransaction result = PrivateTransactionDecoder.decode(hexMessage);
    assertNotNull(result);
    assertEquals(nonce, result.getNonce());
    assertEquals(gasPrice, result.getGasPrice());
    assertEquals(gasLimit, result.getGasLimit());
    assertEquals(to, result.getTo());
    assertEquals("", result.getData());
    assertEquals(MOCK_ENCLAVE_KEY, result.getPrivateFrom());
    assertEquals(MOCK_ENCLAVE_KEY, result.getPrivacyGroupId().get());
    assertEquals(RESTRICTED, result.getRestriction());
}
 
Example 17
Source File: NetworkCurrencyTest.java    From symbol-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
void assertCreatedUsingMosaicId() {
    MosaicId mosaicId = new MosaicId(BigInteger.TEN);
    NetworkCurrency networkCurrency = new NetworkCurrencyBuilder(
        mosaicId, 6).withSupplyMutable(false)
        .withTransferable(true).build();

    assertEquals(mosaicId, networkCurrency.getMosaicId().get());
    assertEquals(mosaicId, networkCurrency.getUnresolvedMosaicId());
    Assertions.assertFalse(networkCurrency.getNamespaceId().isPresent());
}
 
Example 18
Source File: FunctionReturnDecoderTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecodeIndexedDynamicArrayValue() {
    DynamicArray<Uint256> array = new DynamicArray<>(new Uint256(BigInteger.TEN));
    String encoded = TypeEncoder.encodeDynamicArray(array);
    String hash = Hash.sha3(encoded);

    assertThat(FunctionReturnDecoder.decodeIndexedValue(
            hash,
            new TypeReference<DynamicArray>() {}),
            equalTo(new Bytes32(Numeric.hexStringToByteArray(hash))));
}
 
Example 19
Source File: PrivateTransactionDecoderTest.java    From web3j with Apache License 2.0 4 votes vote down vote up
@Test
public void testDecodingSigned() throws Exception {
    final BigInteger nonce = BigInteger.ZERO;
    final BigInteger gasPrice = BigInteger.ONE;
    final BigInteger gasLimit = BigInteger.TEN;
    final String to = "0x0add5355";
    final RawPrivateTransaction rawTransaction =
            RawPrivateTransaction.createTransaction(
                    nonce,
                    gasPrice,
                    gasLimit,
                    to,
                    "",
                    MOCK_ENCLAVE_KEY,
                    MOCK_PRIVATE_FOR,
                    RESTRICTED);
    final String privateKey =
            "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63";
    final Credentials credentials = Credentials.create(privateKey);
    final byte[] encodedMessage =
            PrivateTransactionEncoder.signMessage(rawTransaction, credentials);
    final String hexMessage = Numeric.toHexString(encodedMessage);

    final RawPrivateTransaction result = PrivateTransactionDecoder.decode(hexMessage);
    assertNotNull(result);
    assertEquals(nonce, result.getNonce());
    assertEquals(gasPrice, result.getGasPrice());
    assertEquals(gasLimit, result.getGasLimit());
    assertEquals(to, result.getTo());
    assertEquals("", result.getData());
    assertEquals(MOCK_ENCLAVE_KEY, result.getPrivateFrom());
    assertEquals(MOCK_PRIVATE_FOR, result.getPrivateFor().get());
    assertEquals(RESTRICTED, result.getRestriction());
    assertTrue(result instanceof SignedRawPrivateTransaction);
    final SignedRawPrivateTransaction signedResult = (SignedRawPrivateTransaction) result;
    assertNotNull(signedResult.getSignatureData());
    Sign.SignatureData signatureData = signedResult.getSignatureData();
    final byte[] encodedTransaction = PrivateTransactionEncoder.encode(rawTransaction);
    final BigInteger key = Sign.signedMessageToKey(encodedTransaction, signatureData);
    assertEquals(key, credentials.getEcKeyPair().getPublicKey());
    assertEquals(credentials.getAddress(), signedResult.getFrom());
    signedResult.verify(credentials.getAddress());
    assertNull(signedResult.getChainId());
}
 
Example 20
Source File: AliasServiceTest.java    From symbol-sdk-java with Apache License 2.0 4 votes vote down vote up
private NamespaceInfo createAlias(Address address) {

        return new NamespaceInfo(true, 0, "metadaId", NamespaceRegistrationType.ROOT_NAMESPACE, 1,
            Collections.emptyList(), null, null, BigInteger.ONE, BigInteger.TEN,
            new AddressAlias(address));
    }