-
-
Save erithmetic/4070015 to your computer and use it in GitHub Desktop.
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
# hotness = age_in_minutes / (votes**2.5) | |
def original_hotness(now, created_at, votes) | |
age_in_minutes = (((created_at.to_f / 60).floor * 60) - ((now.to_f / 60).floor * 60)) / -60 | |
age_in_minutes / (votes**2.5) | |
end | |
def new_hotness(now, created_at, votes) | |
age_in_minutes = (now - created_at) / 60 | |
age_in_minutes / (votes**2.5) | |
end | |
require 'time' | |
require 'test/unit/assertions' | |
include Test::Unit::Assertions | |
now = Time.now | |
created_at = Time.parse('2012-10-10 13:45:00') | |
assert_equal original_hotness(now, created_at, 0) , new_hotness(now, created_at, 0) | |
assert_equal original_hotness(now, created_at, 1) , new_hotness(now, created_at, 1) | |
assert_equal original_hotness(now, created_at, 100), new_hotness(now, created_at, 100) | |
puts 'pass!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
not quite...