require "./spec_helper" require "../src/timecost/range" describe TimeCost::Range do epsilon = 0.5 overlap_time = (epsilon / 2).hours separate_time = (epsilon * 2).hours author = TimeCost::Author.new( name: "Jon Snow", email: "jon.snow@example.com" ) commit_base = TimeCost::Commit.new( commit_hash: Random::Secure.base64(40), author: author, datetime: Time.utc, ) commit_overlap_before = TimeCost::Commit.new( commit_hash: Random::Secure.base64(40), author: author, datetime: Time.utc - overlap_time, ) commit_overlap_after = TimeCost::Commit.new( commit_hash: Random::Secure.base64(40), author: author, datetime: Time.utc + overlap_time, ) commit_separate_before = TimeCost::Commit.new( commit_hash: Random::Secure.base64(40), author: author, datetime: Time.utc - separate_time, ) commit_separate_after = TimeCost::Commit.new( commit_hash: Random::Secure.base64(40), author: author, datetime: Time.utc + separate_time, ) describe ".new" do it "can be created without epsilon" do range_base = TimeCost::Range.new( commit: commit_base ) range_base.should be_a(TimeCost::Range) end it "can be created with epsilon" do range_base = TimeCost::Range.new( commit: commit_base, epsilon: epsilon ) range_base.should be_a(TimeCost::Range) end end describe ".overlap?" do it "must return true when range overlaps range before" do range_base = TimeCost::Range.new( commit: commit_base ) range_before = TimeCost::Range.new( commit: commit_overlap_before ) overlap1 = range_base.overlap? range_before overlap1.should be_true overlap2 = range_before.overlap? range_base overlap2.should be_true end it "must return true when range overlaps range after" do range_base = TimeCost::Range.new( commit: commit_base ) range_after = TimeCost::Range.new( commit: commit_overlap_after ) overlap1 = range_base.overlap? range_after overlap1.should be_true overlap2 = range_after.overlap? range_base overlap2.should be_true end it "must return false when range does not overlap range before" do range_base = TimeCost::Range.new( commit: commit_base ) range_before = TimeCost::Range.new( commit: commit_separate_before ) overlap1 = range_base.overlap? range_before overlap1.should be_false overlap2 = range_before.overlap? range_base overlap2.should be_false end it "must return false when range does not overlap range after" do range_base = TimeCost::Range.new( commit: commit_base ) range_after = TimeCost::Range.new( commit: commit_separate_after ) overlap1 = range_base.overlap? range_after overlap1.should be_false overlap2 = range_after.overlap? range_base overlap2.should be_false end end end