2023-07-11 16:52:48 +00:00
|
|
|
|
|
|
|
require "./spec_helper"
|
|
|
|
|
|
|
|
require "../src/timecost/range"
|
|
|
|
|
|
|
|
describe TimeCost::Range do
|
2023-07-11 22:22:07 +00:00
|
|
|
|
2023-07-11 16:52:48 +00:00
|
|
|
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
|
2023-07-11 22:22:07 +00:00
|
|
|
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)
|
2023-07-11 16:52:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe ".overlap?" do
|
2023-07-11 22:22:07 +00:00
|
|
|
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
|
2023-07-11 16:52:48 +00:00
|
|
|
end
|
|
|
|
|
2023-07-11 22:22:07 +00:00
|
|
|
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
|
2023-07-11 16:52:48 +00:00
|
|
|
end
|
|
|
|
|
2023-07-11 22:22:07 +00:00
|
|
|
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
|
2023-07-11 16:52:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|