Created
May 24, 2012 16:17
-
-
Save jamierumbelow/2782505 to your computer and use it in GitHub Desktop.
TDD for Pandr
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
$ ruby popularity_test.rb | |
Loaded suite popularity_test | |
Started | |
. | |
Finished in 0.000979 seconds. | |
1 tests, 4 assertions, 0 failures, 0 errors, 0 skips |
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
def most_popular_post(posts) | |
posts.sort{ |a,b| a[:popularity] <=> b[:popularity] }.last | |
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 'minitest/autorun' | |
require './popularity' | |
class TestPopularity < MiniTest::Unit::TestCase | |
def setup | |
@posts = [ { id: 1, popularity: 100 }, { id: 2, popularity: 50 }, { id: 3, popularity: 75 } ] | |
@other_posts = [ { id: 6, popularity: 40 }, { id: 12, popularity: 50 }, { id: 8, popularity: 75 } ] | |
end | |
def test_most_popular_post_returns_most_popular | |
post = most_popular_post(@posts) | |
assert_equal 1, post[:id] | |
assert_equal 100, post[:popularity] | |
post = most_popular_post(@other_posts) | |
assert_equal 8, post[:id] | |
assert_equal 75, post[:popularity] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment