Rewrite diff methods
This commit is contained in:
@ -3,10 +3,43 @@ require "./spec_helper"
|
||||
module Dayoff::Test
|
||||
extend self
|
||||
|
||||
describe "can check same date" do
|
||||
it "planned can calc in range" do
|
||||
planned_date = PlannedDate.new(t(1, 12), 8)
|
||||
date = t(1, 20)
|
||||
res = planned_date.same_date? date
|
||||
res.should be_true
|
||||
t1 = t(1, 0)
|
||||
t2 = t(2, 0)
|
||||
res = planned_date.in_range t1, t2
|
||||
res.total_hours.should eq 8
|
||||
end
|
||||
|
||||
it "planned can calc in range 2" do
|
||||
planned_date = PlannedDate.new(t(3, 0), 8)
|
||||
t1 = t(1, 0)
|
||||
t2 = t(2, 0)
|
||||
res = planned_date.in_range t1, t2
|
||||
res.total_hours.should eq 0
|
||||
end
|
||||
|
||||
it "planned can calc in range 2" do
|
||||
planned_date = PlannedDate.new(d(1), 8)
|
||||
t1 = t(1, 0).at_beginning_of_day
|
||||
t2 = t(1, 0).at_end_of_day
|
||||
res = planned_date.in_range t1, t2
|
||||
res.total_hours.should eq 8
|
||||
end
|
||||
|
||||
it "worked can calc in range" do
|
||||
work_record = WorkRecord.new(t(1, 10), t(1, 20))
|
||||
t1 = t(1, 15).at_beginning_of_day
|
||||
t2 = t(1, 15)
|
||||
res = work_record.in_range t1, t2
|
||||
res.total_hours.should eq 5
|
||||
end
|
||||
|
||||
it "worked can calc in range 2" do
|
||||
work_record = WorkRecord.new(t(1, 10), t(1, 20))
|
||||
t1 = t(2, 15).at_beginning_of_day
|
||||
t2 = t(2, 15)
|
||||
res = work_record.in_range t1, t2
|
||||
res.total_hours.should eq 0
|
||||
end
|
||||
end
|
||||
|
@ -18,15 +18,6 @@ module Dayoff::Test
|
||||
end
|
||||
|
||||
describe Profile do
|
||||
it "can calc work hours" do
|
||||
storage = MemoryStorage.new
|
||||
storage.set_work_records [
|
||||
WorkRecord.new(t(1, 10), t(1, 20)),
|
||||
]
|
||||
prof = Profile.new(storage)
|
||||
prof.get_work_hours(t(2, 0)).total_hours.should eq 10
|
||||
end
|
||||
|
||||
it "can write new record" do
|
||||
storage = MemoryStorage.new
|
||||
storage.set_work_records [
|
||||
@ -54,27 +45,6 @@ module Dayoff::Test
|
||||
records.last.finish.should eq finish_time
|
||||
end
|
||||
|
||||
it "can calc planned hours" do
|
||||
prof = create_profile
|
||||
span = prof.get_planned_hours t(3, 12)
|
||||
expected = 8 * 3
|
||||
expected.should eq span.total_hours
|
||||
end
|
||||
|
||||
it "can calc work hours" do
|
||||
prof = create_profile
|
||||
span = prof.get_work_hours t(3, 12)
|
||||
expected = 10 * 2
|
||||
expected.should eq span.total_hours
|
||||
end
|
||||
|
||||
it "can calc remaining time" do
|
||||
prof = create_profile
|
||||
span = prof.remaining_time t(3, 12)
|
||||
expected = 8 * 3 - 10 * 2
|
||||
expected.should eq span.total_hours
|
||||
end
|
||||
|
||||
it "not start twice" do
|
||||
prof = create_profile
|
||||
start_time = t(3, 10, 0)
|
||||
@ -95,10 +65,17 @@ module Dayoff::Test
|
||||
end
|
||||
end
|
||||
|
||||
it "can calc remaining time" do
|
||||
prof = create_profile
|
||||
span = prof.remaining_time t(3, 12)
|
||||
expected = 8 * 3 - 10 * 2
|
||||
expected.should eq span.total_hours
|
||||
end
|
||||
|
||||
it "can calc diff on concrete date" do
|
||||
prof = create_profile
|
||||
span = prof.date_status d(1)
|
||||
span.total_hours.should eq -2
|
||||
span = prof.date_status t(1, 15)
|
||||
span.total_hours.should eq 3
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user