spec/lib/stellar/price_spec.rb in stellar-base-0.1.4 vs spec/lib/stellar/price_spec.rb in stellar-base-0.2.0
- old
+ new
@@ -16,6 +16,19 @@
expect(actual_p.n).to be <= Stellar::Price::MAX_PRECISION
expect(actual_p.d).to be <= Stellar::Price::MAX_PRECISION
end
end
+ it "works with bigdecimal" do
+ whole = random.rand(1_000_000)
+ fractional = random.rand(10_000_000) # seven significant digits available for fractional
+
+ expected = BigDecimal.new("#{whole}.#{fractional}")
+ actual_p = subject.from_f(expected)
+ actual = BigDecimal.new(actual_p.n) / BigDecimal.new(actual_p.d)
+
+ expect(actual).to be_within(BigDecimal.new("0.000000001")).of(actual)
+ expect(actual_p.n).to be <= Stellar::Price::MAX_PRECISION
+ expect(actual_p.d).to be <= Stellar::Price::MAX_PRECISION
+ end
+
end