Skip to content

Instantly share code, notes, and snippets.

@cris
Created April 20, 2011 15:36
Show Gist options
  • Save cris/5fcd2185f7885b94e7f8 to your computer and use it in GitHub Desktop.
Save cris/5fcd2185f7885b94e7f8 to your computer and use it in GitHub Desktop.
Test of log2 helper math function
require 'spec_helper'
describe UtilsLogic::Math do
describe ".log2" do
subject {UtilsLogic::Math.log2(number)}
context "usual case" do
let(:number) {128}
it {should == 7}
end
context "edge case" do
let(:number) {1}
it {should == 0}
end
end
end
describe UtilsLogic::Date do
describe ".age" do
let(:date) {Date.parse(str_date)}
let(:now_date) {Date.parse(str_now_date)}
subject {UtilsLogic::Date.age(date, now_date)}
context "normal case: birthday was in this year" do
let(:str_date) {"1983-04-23"}
let(:str_now_date) {"2011-05-13"}
it {should == 28}
end
context "normal case: birthday will be in this year" do
let(:str_date) {"1983-06-23"}
let(:str_now_date) {"2011-05-13"}
it {should == 27}
end
context "edge case: birthday is today" do
let(:str_date) {"1983-05-13"}
let(:str_now_date) {"2011-05-13"}
it {should == 28}
end
context "edge case: birthday was yesterday" do
let(:str_date) {"1983-05-12"}
let(:str_now_date) {"2011-05-13"}
it {should == 28}
end
context "edge case: birthday will be tomorrow" do
let(:str_date) {"1983-05-14"}
let(:str_now_date) {"2011-05-13"}
it {should == 27}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment