Created
October 3, 2011 15:57
-
-
Save jaksonmoura/1259442 to your computer and use it in GitHub Desktop.
Chop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://codekata.pragprog.com/2007/01/kata_two_karate.html | |
| class Chop | |
| def chop(int, ar) | |
| return -1 unless ar.include?(int) | |
| return ar.index(int) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'test/unit' | |
| require './Chop' | |
| class TestChop < Test::Unit::TestCase | |
| def setup | |
| @chop = Chop.new | |
| end | |
| def teardown | |
| @chop = nil | |
| end | |
| def test_chop | |
| assert_equal(-1, @chop.chop(0, [1, 2, 3])) | |
| assert_equal(0, @chop.chop(1, [1, 2, 3])) | |
| assert_equal(2, @chop.chop(3, [1, 2, 3])) | |
| # | |
| assert_equal(0, @chop.chop(1, [1, 3, 5])) | |
| assert_equal(1, @chop.chop(3, [1, 3, 5])) | |
| assert_equal(2, @chop.chop(5, [1, 3, 5])) | |
| assert_equal(-1, @chop.chop(0, [1, 3, 5])) | |
| assert_equal(-1, @chop.chop(2, [1, 3, 5])) | |
| assert_equal(-1, @chop.chop(4, [1, 3, 5])) | |
| assert_equal(-1, @chop.chop(6, [1, 3, 5])) | |
| # | |
| assert_equal(0, @chop.chop(1, [1, 3, 5, 7])) | |
| assert_equal(1, @chop.chop(3, [1, 3, 5, 7])) | |
| assert_equal(2, @chop.chop(5, [1, 3, 5, 7])) | |
| assert_equal(3, @chop.chop(7, [1, 3, 5, 7])) | |
| assert_equal(-1, @chop.chop(0, [1, 3, 5, 7])) | |
| assert_equal(-1, @chop.chop(2, [1, 3, 5, 7])) | |
| assert_equal(-1, @chop.chop(4, [1, 3, 5, 7])) | |
| assert_equal(-1, @chop.chop(6, [1, 3, 5, 7])) | |
| assert_equal(-1, @chop.chop(8, [1, 3, 5, 7])) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment