Design updates with error handling

This commit is contained in:
bterkuile committed 2025-10-18 09:13:12 -05:00
1 parent 4c73608549
commit 4b84df0af9
9 files changed
+124 -38

No files matched your search

+10 -9
View File
@@ -44,7 +44,7 @@ RSpec.describe StrikeMe::BTC do
context 'arithmetic' do
it 'supports multiplication with numbers' do
btc1 = described_class.new(234_529)
btc1 = described_class.new 234_529
btc2 = btc1 * 3
btc3 = btc2 * 2.9
@@ -54,14 +54,14 @@ RSpec.describe StrikeMe::BTC do
expect(btc2).not_to eq btc1
expect(btc2).not_to eq btc3
expect(btc1.sats).to eq 234_529
expect(btc1).to eq 234_529
expect(btc2).to eq 703_587
expect(btc3).to eq 2_040_402
expect(btc1.sats).to eq 234_529
expect(btc1).to eq 234_529
expect(btc2).to eq 703_587
expect(btc3).to eq 2_040_402
end
it 'supports division with numbers' do
btc1 = described_class.new(34_529)
btc1 = described_class.new 34_529
btc2 = btc1 / 3
btc3 = btc2 / 2.9
@@ -74,7 +74,7 @@ RSpec.describe StrikeMe::BTC do
expect(btc1.sats).to eq 34_529
expect(btc1).to eq 34_529
expect(btc2).to eq 11_509
expect(btc3).to eq 3_968
expect(btc3).to eq 3_968
end
it 'supports addition with other BTC objects' do
@@ -89,8 +89,8 @@ RSpec.describe StrikeMe::BTC do
end
it 'supports subtraction with other BTC objects' do
btc1 = described_class.new(34_529)
btc2 = described_class.new(2_556)
btc1 = described_class.new 34_529
btc2 = described_class.new 2_556
btc3 = btc1 - btc2
expect { btc1 - 23 }.to raise_error StrikeMe::BTC::Error
@@ -101,6 +101,7 @@ RSpec.describe StrikeMe::BTC do
end
it 'is consistent for small values' do
# if floor is used instead of round, the small number 3, multiplied by 100 million can result in 2.99999999 leading to 2
string = 3.sats.to_s
expect(string).to eq '0.00000003'
expect(string.to_f.btc.sats).to eq 3