Ejemplo n.º 1
0
  @Test
  public void cryptoToCryptoRate() throws Exception {
    // 1BTC = 100LTC
    ExchangeRateBase rate = new ExchangeRateBase(oneBtc, LTC.oneCoin().multiply(100));

    assertEquals(LTC, rate.convert(oneBtc).type);
    assertEquals(BTC, rate.convert(LTC.oneCoin()).type);

    assertEquals("1", rate.convert(oneBtc.divide(100)).toPlainString());
    assertEquals("0.01", rate.convert(LTC.oneCoin()).toPlainString());

    // 250NBT = 1BTC
    rate = new ExchangeRateBase(oneNbt.multiply(250), oneBtc);
    assertEquals("0.004", rate.convert(oneNbt).toPlainString());
    assertEquals("2500", rate.convert(oneBtc.multiply(10)).toPlainString());
  }
Ejemplo n.º 2
0
 @Test
 public void smallRate() throws Exception {
   ExchangeRateBase rate =
       new ExchangeRateBase(Value.parse(BTC, "10000"), FiatValue.parse("XXX", "0.00001"));
   assertEquals("0", rate.convert(oneBtc).toPlainString()); // Tiny value!
   assertEquals("1000000000", rate.convert(FiatValue.parse("XXX", "1")).toPlainString());
 }
Ejemplo n.º 3
0
 @Test
 public void bigRate() throws Exception {
   ExchangeRateBase rate =
       new ExchangeRateBase(Value.parse(BTC, "0.0001"), FiatValue.parse("BYR", "5320387.3"));
   assertEquals("53203873000", rate.convert(oneBtc).toPlainString());
   assertEquals("0", rate.convert(FiatValue.parse("BYR", "1")).toPlainString()); // Tiny value!
 }
Ejemplo n.º 4
0
  @Test
  public void cryptoToFiatRate() throws Exception {
    ExchangeRateBase rate = new ExchangeRateBase(oneBtc, FiatValue.parse("EUR", "500"));

    assertEquals(FiatType.get("EUR"), rate.convert(oneBtc).type);
    assertEquals(BTC, rate.convert(FiatValue.parse("EUR", "1")).type);

    assertEquals("0.5", rate.convert(oneBtc.divide(1000)).toPlainString());
    assertEquals("0.002", rate.convert(FiatValue.parse("EUR", "1")).toPlainString());
  }
Ejemplo n.º 5
0
  @Test
  public void cryptoToCryptoRateParseConstructor() throws Exception {
    // 1BTC = 100LTC
    ExchangeRateBase rate = new ExchangeRateBase(BTC, LTC, "100");

    assertEquals(LTC, rate.convert(oneBtc).type);
    assertEquals(BTC, rate.convert(LTC.oneCoin()).type);

    assertEquals("1", rate.convert(oneBtc.divide(100)).toPlainString());
    assertEquals("0.01", rate.convert(LTC.oneCoin()).toPlainString());
  }
Ejemplo n.º 6
0
  @Test
  public void scalingAndRounding() throws Exception {
    // 1BTC = 100.1234567890NBT
    // This rate causes the BTC & NBT to overflow so it sets the correct scale and rounding
    ExchangeRateBase rate = new ExchangeRateBase(BTC, NBT, "100.1234567890");

    // Check the rate's internal state
    assertEquals("100000", rate.value1.toPlainString());
    assertEquals("10012345.6789", rate.value2.toPlainString());

    // Make some conversions
    assertEquals("0.00998767", rate.convert(oneNbt).toPlainString());
    assertEquals("0.000001", rate.convert(Value.parse(NBT, "0.0001")).toPlainString());
    assertEquals("0.0001", rate.convert(Value.parse(BTC, "0.00000099")).toPlainString());
    assertEquals("0.0099", rate.convert(Value.parse(BTC, "0.000099")).toPlainString());
    assertEquals("10012345.6789", rate.convert(oneBtc.multiply(100000)).toPlainString());
    assertEquals("1001.2346", rate.convert(oneBtc.multiply(10)).toPlainString());
    assertEquals("998766.95438852", rate.convert(oneNbt.multiply(100000000)).toPlainString());

    // Check too precise rates
    rate = new ExchangeRateBase(BTC, NBT, "100.12345678901999");
    assertEquals("100000", rate.value1.toPlainString());
    assertEquals("10012345.6789", rate.value2.toPlainString());
  }
Ejemplo n.º 7
0
 @Test(expected = ArithmeticException.class)
 public void coinToFiatTooSmall() throws Exception {
   ExchangeRateBase rate = new ExchangeRateBase(oneBtc, FiatValue.parse("XXX", "1000000000"));
   rate.convert(Value.parse(BTC, "-1000000"));
 }