TDD Practice - Divide without Divide
One question I use to coach test driven development with team members who are new to the concept is:
Write a function to divide without using the
/operator.
It’s a great exercise, to break habits because / is a fundamental
function that it’s implemented at the CPU level - one will have to
work to avoid using it.
Given this criteria and the following test:
it 'divides by 1' do
divide(1,1).to eq(1)
endWhat would you write?
def divide(a,b)
# what would you write here?
endThink about this and implement it yourself before moving forward.