Behdad Analui's solution, 41 specs#74
Conversation
|
|
||
| describe Calculator do | ||
|
|
||
|
|
There was a problem hiding this comment.
create a common instance for Calculator and use it throughout the specs.
let(:c) { Calculator.new }
| it 'returns the sum of its arguments when they are float' do | ||
| first_arg = 3.53 | ||
| second_arg = 8.64 | ||
| expect(@test_calc.add(first_arg, second_arg)).to be_within(0.01).of(12.17) |
There was a problem hiding this comment.
using variables for arguments is not necessary, you can directly add them:
expect(@test_calc.add(3.53, 8.64)).to be_within(0.01).of(12.17)
|
|
||
| describe '#subtract' do | ||
|
|
||
| it 'returns the subtract of its positive integer arguments' do |
There was a problem hiding this comment.
the correct term would be "difference" - it 'returns the difference of positive integer arguments' do
|
|
||
| describe '#multiply' do | ||
|
|
||
| it 'returns the multiply of its positive integer arguments' do |
There was a problem hiding this comment.
the correct term is "product" - it 'returns the product of its positive integer arguments' do
| second_arg = 2.21 | ||
| expect(@test_calc.divide(first_arg, second_arg)).to be_within(0.01).of(-2.0) | ||
| end | ||
|
|
There was a problem hiding this comment.
missing spec:
it 'returns a float if there is a remainder with 2 integers'
| first_arg = 6 | ||
| second_arg = 1.7 | ||
| expect(@test_calc.pow(first_arg, second_arg)).to eq(6**1.7) | ||
| end |
There was a problem hiding this comment.
Also, test the case when the power is 0
|
|
||
| it "can calculate sqr root of a positive integer in 2 decimal digits" do | ||
| first_arg = 224 | ||
| expect(@test_calc.sqrt(first_arg)).to be_within(0.1).of(15) |
There was a problem hiding this comment.
you should check if the result has 2 decimal places exactly.
|
|
||
| it "getter, returns the memory object" do | ||
| @test_calc.memory = 13 | ||
| memory_instance = @test_calc.memory |
There was a problem hiding this comment.
this line is redundant, you can directly use @test_calc.memory in the next line.
| @test_calc = Calculator.new(false) | ||
| expect(@test_calc.output(50)).not_to be_a(String) | ||
| end | ||
| end |
There was a problem hiding this comment.
Also, check if all the main methods(add, subtract, multiply etc) return string if stringify is true
| memory_instance = @test_calc.memory | ||
| expect(memory_instance).to be_nil | ||
| end | ||
| end |
There was a problem hiding this comment.
Also, write tests for memory= method
No description provided.