Skip to content

Instantly share code, notes, and snippets.

@jamierumbelow
Created May 24, 2012 16:17
Show Gist options
  • Save jamierumbelow/2782505 to your computer and use it in GitHub Desktop.
Save jamierumbelow/2782505 to your computer and use it in GitHub Desktop.
TDD for Pandr
$ ruby popularity_test.rb
Loaded suite popularity_test
Started
.
Finished in 0.000979 seconds.
1 tests, 4 assertions, 0 failures, 0 errors, 0 skips
def most_popular_post(posts)
posts.sort{ |a,b| a[:popularity] <=> b[:popularity] }.last
end
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