@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()); }
@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()); }