Ad
  • Default User Avatar

    Not sure, just trained this kata. I suggested to add a testcase for this.

  • Default User Avatar

    It would be great to add a testcase for test_even(2.0)

    This would cover the float case better. Many submitted solutions pass the existing tests where they should fail.

  • Default User Avatar

    It shouldn't!

    [1] pry(main)> def test_even(n)
    [1] pry(main)*   n % 2 == 0
    [1] pry(main)* end
    => :test_even
    [2] pry(main)> test_even(2.0)
    => true
    [3] pry(main)> 2.0 % 2
    => 0.0
    [4] pry(main)> 0.0 == 0
    => true
    

    Maybe you're thinking of .eql?:

    [5] pry(main)> 0.0.eql? 0
    => false
    

    Edit: just observed that floats should be considered uneven for this, so I eat my words! Has the kata changed since it was originally written?

  • Default User Avatar

    This would fail test_even(2.0)

  • Custom User Avatar

    I have to say it is a ugly feature of ruby to use % for formatting. I would rather use sprintf or other helper methods to achieve this.

  • Default User Avatar

    I'm curious as to how this works. Any links to what the percent operator does in this case? Whatever it is, it looks fancy and useful.
    EDIT: Found it after some tough google work
    http://www.ruby-doc.org/core-2.1.1/String.html#method-i-25

  • Default User Avatar

    The input string needs to be defined more precisely. Input validation needed?