Skip to content

Commit

Permalink
added more tests and edited README
Browse files Browse the repository at this point in the history
  • Loading branch information
giusepped committed Nov 24, 2015
1 parent 74e445f commit 945bb9a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,28 @@

*The range of number is given in a text file (the first two lines represent the starting and the ending numbers of the range respectively)

## Installation

In your terminal do the following

```bash
$ git clone https://github.com/giusepped/palindrome_numbers
$ cd palindrome numbers
$ ruby counter.rb
```

## Test

In order to run the Rspec tests (there are 5 tests that test the same range numbers that are in the test files and one other), do the following

```bash
$ rspec
```

## Approach

I created an external class that does the counting in a range. I have to methods for checking wether a number (once converted into a string) is a palindrome:
* the first one uses the reverse ruby in-built method
* the second one uses recursion


1 change: 1 addition & 0 deletions lib/palindrome_counter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def check_palindrome(string)
# when checking for a large range, I implemented also a recursive method to check
# if improved performance but it did not too much, I guess the problem is iterating
# through every single element of a large range

def check_palindrome_recursive(string)
return true if string.length < 2
return false if string[0] != string[-1]
Expand Down
9 changes: 9 additions & 0 deletions spec/palindrome_counter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@
it 'should return 90 when counting from 1000 to 10000' do
expect(subject.count(1000, 10000)).to eq 90
end

it 'should return 10 when counting from 11200000 to 11300000' do
expect(subject.count(11200000, 11300000)).to eq 10
end

it 'should return 1854 when counting from 1034567 to 2888888' do
expect(subject.count(1034567, 2888888)).to eq 1854
end

end

0 comments on commit 945bb9a

Please sign in to comment.