DEV Community

Discussion on: Daily Challenge #193 - What's the Real Floor?

Collapse
nijeesh4all profile image
Nijeesh Joshy

Ruby Oneliner


def getRealFloor floor 
 floor <= 0 ? floor : floor > 13 ? floor - 2 : floor - 1
end

Some tests


require "test/unit"

class GetRealFloorTest < Test::Unit::TestCase
  def test_get_real_floor
    assert_equal 0,  get_real_floor(0)
    assert_equal 2,  get_real_floor(3)
    assert_equal 6,  get_real_floor(7)
    assert_equal 18, get_real_floor(20)
    assert_equal 0,  get_real_floor(1)
    assert_equal -6, get_real_floor(-6)
  end
end


#1 tests, 6 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications