ascii-tracker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b848e61d0882fc155ab6294909494690761926e7
4
- data.tar.gz: d22e74f6102673c75c40e3fc2e58a41c6f1b713a
3
+ metadata.gz: 4d87cd7fac6f81bd5d1bb27cc10c61ac39470270
4
+ data.tar.gz: 72bc11acb60ff36a25a5e4b4af3420ae64c7c9f2
5
5
  SHA512:
6
- metadata.gz: a42bcb45db21c925574b5ca04bd1fc9ca144f562f34c8fbe8379927b6dba116cbf128c2e9845f232e7f6e25eaaf8d8a13186a74d8a83c86c20970dc5949589cc
7
- data.tar.gz: 16f78a6fd81fb919caf62ad6899eeb3597ea5d5d85f93d7618a91ae28545806e443396fbba80d0eefefc9fbb31a6247084c0ec8ba70cc406f7a2749b6d05749c
6
+ metadata.gz: ae181b06b65b5201befe60fecfadfb6968d5908b5fe7c913484082e6487f5cd264c7a412341f63ef362e4441dff5c4ec026fa4c82125c772d019c860f6183c2a
7
+ data.tar.gz: 935678933dc414e9af31f5fea0084f4e36a5ccd075fac96d51a6ee7f99fbdeecedc27a286c9e4947d8042204c82097a5eaf5a114d0ba7ada861b2ccedcaf01f4
data/Guardfile CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  guard :rspec, all_on_start: true, cli: '--format nested --debug --color' do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/model/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
8
8
  watch('lib/asciitracker.rb') { "spec" }
9
9
  end
@@ -29,11 +29,9 @@ Applix.main(ARGV, debug: false) do
29
29
  end
30
30
 
31
31
  def forward(target)
32
- begin
33
- (op = @argv.shift) && target.send(op, self)
34
- rescue ArgumentError => e
35
- target.send(op)
36
- end
32
+ (op = @argv.shift) and target.send(op, self)
33
+ rescue ArgumentError => e
34
+ target.send(op)
37
35
  end
38
36
  end
39
37
 
@@ -2,6 +2,7 @@ require "asciitracker/version"
2
2
 
3
3
  require 'date'
4
4
  require 'asciitracker/hash_ext'
5
+ require 'asciitracker/exceptions'
5
6
  require 'asciitracker/hhmm'
6
7
  require 'asciitracker/record'
7
8
  require 'asciitracker/slot'
@@ -5,19 +5,10 @@ module AsciiTracker
5
5
  @c = Controller.new
6
6
  end
7
7
 
8
- def stop
9
- puts "Stop!"
10
- end
11
-
12
- def foo context
13
- puts "Hey!"
14
- context.forward(self)
15
- end
16
-
17
8
  def scan context
18
9
  filename = context.argv.shift
19
10
  puts "scanning file: #{filename}"
20
- AsciiTracker::Parser.parse @c, IO.read(filename)
11
+ AsciiTracker::Parser.parse(@c, IO.read(filename))
21
12
  #puts "records:\n#{records.join("\n")}"
22
13
  #puts "--> 2: #{@c.model}"
23
14
  #puts "--> 3: #{@c.model.records}"
@@ -17,18 +17,18 @@ module AsciiTracker
17
17
  def new_slot start, stop, desc = nil
18
18
  #slot = Slot.new :date=>@day, :start=> start, :end=>stop, :desc=>desc
19
19
  @rec = @slot = Slot.new(
20
- :start => start, :end =>stop, :desc =>desc, :date => @day.dup
20
+ start: start, end: stop, desc: desc, date: @day.dup
21
21
  )
22
22
 
23
23
  # updates parant records when this slot is an interruption
24
24
  overlaps = @model.find_overlaps(@slot, @day)
25
- puts "new slot(#{@slot}), overlaps: #{overlaps}"
25
+ #puts "new slot(#{@slot}), overlaps: #{overlaps}"
26
26
  unless overlaps.empty?
27
27
  # parents are covers which are a subset of overlaps
28
28
  if parent = @model.find_best_cover(@slot, @day)
29
29
  parent.add_interrupt(@slot)
30
30
  else
31
- raise TimecardException, <<-EOM
31
+ raise Exception, <<-EOM
32
32
  #{@slot}
33
33
  overlaps with:
34
34
  #{overlaps.first} ...
@@ -0,0 +1,22 @@
1
+ module AsciiTracker
2
+
3
+ class Exception < RuntimeError
4
+ attr_accessor :reason
5
+ attr_reader :callstack
6
+
7
+ def initialize *args
8
+ super *args
9
+ @callstack = caller
10
+ end
11
+ end
12
+
13
+ class InvalidInterrupt < AsciiTracker::Exception; end
14
+ class NotYetImplemented < AsciiTracker::Exception; end
15
+
16
+ module Exceptions
17
+ def not_yet_implemented txt = nil
18
+ txt ||= "#{caller[0]} (caller: #{caller[1]})"
19
+ raise NotYetImplemented, txt
20
+ end
21
+ end
22
+ end
@@ -80,21 +80,21 @@ module AsciiTracker
80
80
  def add_interrupt slot_or_span
81
81
  slr = slot_or_span # shortcut
82
82
  unless covers? slr
83
- raise TimecardException, "interrupt not covered! #{slr}"
83
+ raise Exception, "interrupt not covered! #{slr}"
84
84
  end
85
85
 
86
86
  unless slr.span <= span
87
- raise TimecardException, "'#{self}' overload(#{span}): #{slr}"
87
+ raise Exception, "'#{self}' overload(#{span}): #{slr}"
88
88
  end
89
- #raise TimecardException, "overload: #{slr}" unless slr.span <= span
89
+ #raise Exception, "overload: #{slr}" unless slr.span <= span
90
90
 
91
91
  # new interrupts may not overlap with existing ones!
92
92
  if slr.respond_to?(:t_start)
93
- #raise TimecardException, "overlap: #{slr}" if @interrupts.any? do |i|
93
+ #raise Exception, "overlap: #{slr}" if @interrupts.any? do |i|
94
94
  # slr.overlaps? i
95
95
  #end
96
96
  if @interrupts.any? { |rec| slr.overlaps? rec }
97
- raise TimecardException, "overlap: #{slr}"
97
+ raise Exception, "overlap: #{slr}"
98
98
  end
99
99
  end
100
100
 
@@ -1,3 +1,3 @@
1
1
  module AsciiTracker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,208 @@
1
+ require 'spec_helper'
2
+
3
+ include AsciiTracker
4
+ describe AsciiTracker::Record do
5
+
6
+ it "finds the class" do
7
+ Slot.should_not == nil
8
+ end
9
+
10
+ describe "with 10:45 - 12:15" do
11
+ let(:rec) { Slot.new start: "10:45", end: "12:15", desc: "foo bar" }
12
+
13
+ it "should fit Records" do
14
+ # span are always contained...
15
+ rec.covers?(Record.new(:span => 0.5)).should == true
16
+ rec.covers?(Record.new(:span => 1.5)).should == true
17
+ end
18
+
19
+ it "should not cover records with are to long" do
20
+ rec.covers?(Record.new(:span => "1:31")).should == false
21
+ rec.covers?(Record.new(:span => 5.0)).should == false
22
+ end
23
+
24
+ it "should calc slot covers" do
25
+ rec.covers?(Slot.new(:start=>"10:45", :end=>"12:15")).should == true
26
+ rec.covers?(Slot.new(:start=>"10:00", :end=>"12:15")).should == false
27
+ rec.covers?(Slot.new(:start=>"10:45", :end=>"13:00")).should == false
28
+ end
29
+ end
30
+
31
+ it "should construct from start, end and desc options" do
32
+ rec = Slot.new :start => "10:15", :end => "10:45", :desc => "foo bar"
33
+ rec.desc.should == "foo bar"
34
+ rec.t_start.should == (HHMM "10:15")
35
+ rec.t_end.should == (HHMM "10:45")
36
+ rec.span.should == 0.5
37
+ rec.gross_length.should == 0.5
38
+ rec.interrupts.length.should == 0
39
+ end
40
+
41
+ it "should support long overlaps around midnight" do
42
+ rec = Slot.new :start => "14:00", :end => "02:00"
43
+ rec.interrupts.length.should == 0
44
+ rec.span.should == 12
45
+ end
46
+
47
+ it "should cover slots over midnight" do
48
+ rec = Slot.new :start=>"23:00", :end=>"01:00", :desc=>"foo bar"
49
+ rec.covers?(Record.new(:span => 1.0)).should == true
50
+ end
51
+
52
+ it "should support slots over midnight" do
53
+ rec = Slot.new :start=>"23:00", :end=>"01:00", :desc=>"foo bar"
54
+ rec.span.should == 2
55
+ rec.interrupts.length.should == 0
56
+
57
+ rec = Slot.new :start=>"20:00", :end=>"05:00", :desc=>"foo bar"
58
+ rec.span.should == 9
59
+ rec.interrupts.length.should == 0
60
+ end
61
+
62
+ describe "with base slot" do
63
+ let(:base) { Slot.new start: '5:00', end: '6:00' }
64
+
65
+ it "sould calc overlaps" do
66
+ a = Slot.new :start => "4:00", :end => "4:30"
67
+ base.overlaps?(a).should == false
68
+
69
+ a1 = Slot.new :start => "4:00", :end => "5:00"
70
+ base.overlaps?(a1).should == false
71
+
72
+ b = Slot.new :start => "1:00", :end => "5:30"
73
+ base.overlaps?(b).should == true
74
+
75
+ c = Slot.new :start => "1:00", :end => "7:00"
76
+ base.overlaps?(c).should == true
77
+
78
+ d = Slot.new :start => "5:15", :end => "5:45"
79
+ base.overlaps?(d).should == true
80
+
81
+ d1 = Slot.new :start => "5:00", :end => "5:45"
82
+ base.overlaps?(d1).should == true
83
+
84
+ d2= Slot.new :start => "5:15", :end => "6:00"
85
+ base.overlaps?(d2).should == true
86
+
87
+ e = Slot.new :start => "5:30", :end => "7:00"
88
+ base.overlaps?(e).should == true
89
+
90
+ f = Slot.new :start => "7:00", :end => "9:00"
91
+ base.overlaps?(f).should == false
92
+
93
+ f1 = Slot.new :start => "6:00", :end => "9:00"
94
+ base.overlaps?(f1).should == false
95
+ end
96
+ end
97
+
98
+ describe "with base over around midnight" do
99
+ let(:base) { Slot.new start: '22:00', end: '02:00' }
100
+
101
+ it "should calc overlaps around midnight" do
102
+ # before
103
+ a = Slot.new :start => "20:00", :end => "21:59"
104
+ base.covers?(a).should == false
105
+ base.overlaps?(a).should == false
106
+ # after
107
+ a = Slot.new :start => "02:01", :end => "04:00"
108
+ base.covers?(a).should == false
109
+ base.overlaps?(a).should == false
110
+
111
+ a = Slot.new :start => "23:00", :end => "23:10"
112
+ puts " -- #{[base.t_start, base.t_end, a.t_start, a.t_end].join(', ')}"
113
+ base.covers?(a).should == true
114
+ base.overlaps?(a).should == true
115
+
116
+ a = Slot.new :start => "23:00", :end => "01:00"
117
+ puts " -- #{[base.t_start, base.t_end, a.t_start, a.t_end].join(', ')}"
118
+ base.covers?(a).should == true
119
+ base.overlaps?(a).should == true
120
+
121
+ a = Slot.new :start => "01:00", :end => "01:10"
122
+ puts " -- #{[base.t_start, base.t_end, a.t_start, a.t_end].join(', ')}"
123
+ base.overlaps?(a).should == true
124
+ base.covers?(a).should == true
125
+ end
126
+ end
127
+
128
+ context 'interrups' do
129
+
130
+ let(:rec) { Slot.new start: '10:00', end: '12:30', desc: 'whatever' }
131
+ it 'inits slots as uninterrupted' do
132
+ rec.interrupts.length.should be(0)
133
+ end
134
+
135
+ context 'with spans' do
136
+ let(:one_hour) { Record.new span: 1, desc: 'one hour of wasted time' }
137
+
138
+ it 'aggregates interrupts and subtracts the interupt time from record' do
139
+ expect { rec.add_interrupt one_hour }.not_to raise_error
140
+ rec.interrupts.length.should eq(1)
141
+ rec.span.should eq(1.5)
142
+
143
+ expect { rec.add_interrupt one_hour }.not_to raise_error
144
+ rec.interrupts.length.should eq(2)
145
+ rec.span.should eq(0.5)
146
+ end
147
+
148
+ it 'raises error on interrupt not fitting the record' do
149
+ expect { rec.add_interrupt one_hour }.not_to raise_error
150
+ expect { rec.add_interrupt one_hour }.not_to raise_error
151
+ expect { rec.add_interrupt one_hour }.to raise_error(
152
+ AsciiTracker::Exception, /overload\(0.5\).*one hour of wasted time/
153
+ )
154
+ end
155
+ end
156
+
157
+ context 'with other slots' do
158
+ let(:rec) { Slot.new start: '10:00', end: '12:30', desc: 'foo bar' }
159
+
160
+ it 'aggregates interrupts and subtracts the interupt time from record' do
161
+ rec.add_interrupt(Slot.new start: '10:00', end: '12:00', desc: '?')
162
+ rec.interrupts.length.should eq(1)
163
+ rec.span.should eq(0.5)
164
+
165
+ rec.add_interrupt(Slot.new start: '12:00', end: '12:15', desc: '?')
166
+ rec.interrupts.length.should eq(2)
167
+ rec.span.should eq(0.25)
168
+
169
+ rec.add_interrupt(Slot.new start: '12:15', end: '12:30', desc: '?')
170
+ rec.interrupts.length.should eq(3)
171
+ rec.span.should eq(0.0)
172
+ end
173
+
174
+ it 'bails out on records overlapping start or end time' do
175
+ expect {
176
+ rec.add_interrupt(Slot.new start: '12:30', end: '13:00', desc: 'X')
177
+ }.to raise_error(
178
+ AsciiTracker::Exception, /interrupt not covered!.*12:30-13:00/
179
+ )
180
+
181
+ expect {
182
+ rec.add_interrupt(Slot.new start: '09:30', end: '11:00', desc: 'X')
183
+ }.to raise_error(
184
+ AsciiTracker::Exception, /interrupt not covered!.*09:30-11:00/
185
+ )
186
+
187
+ expect {
188
+ rec.add_interrupt(Slot.new start: '09:59', end: '12:01', desc: 'X')
189
+ }.to raise_error(
190
+ AsciiTracker::Exception, /interrupt not covered!.*09:59-12:01/
191
+ )
192
+ end
193
+
194
+ it 'raises error on stuffin slot to overfilled record' do
195
+ rec.add_interrupt(Slot.new start: '10:00', end: '12:30', desc: '?')
196
+ rec.interrupts.length.should eq(1)
197
+ rec.span.should eq(0.0)
198
+ # rec is full now
199
+
200
+ expect {
201
+ rec.add_interrupt(Slot.new start: '10:01', end: '10:02', desc: 'X')
202
+ }.to raise_error(
203
+ AsciiTracker::Exception, /overload\(0.0\): 2013-07-11 10:01-10:02 X/
204
+ )
205
+ end
206
+ end
207
+ end
208
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ascii-tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - dirk lüsebrink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-10 00:00:00.000000000 Z
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: applix
@@ -86,7 +86,7 @@ description: "\n keeping track of time in a textfile. now web app, no mouse c
86
86
  email:
87
87
  - dirk.luesebrink@gmail.com
88
88
  executables:
89
- - atracker.rb
89
+ - atracker
90
90
  extensions: []
91
91
  extra_rdoc_files: []
92
92
  files:
@@ -98,10 +98,11 @@ files:
98
98
  - README.md
99
99
  - Rakefile
100
100
  - ascii-tracker.gemspec
101
- - bin/atracker.rb
101
+ - bin/atracker
102
102
  - lib/asciitracker.rb
103
103
  - lib/asciitracker/app.rb
104
104
  - lib/asciitracker/controller.rb
105
+ - lib/asciitracker/exceptions.rb
105
106
  - lib/asciitracker/hash_ext.rb
106
107
  - lib/asciitracker/hhmm.rb
107
108
  - lib/asciitracker/model.rb
@@ -110,11 +111,11 @@ files:
110
111
  - lib/asciitracker/record.rb
111
112
  - lib/asciitracker/slot.rb
112
113
  - lib/asciitracker/version.rb
113
- - spec/model/controller_spec.rb
114
- - spec/model/hhmm_spec.rb
115
- - spec/model/model_spec.rb
116
- - spec/model/record_spec.rb
117
- - spec/model/slot_spec.rb
114
+ - spec/model/asciitracker/controller_spec.rb
115
+ - spec/model/asciitracker/hhmm_spec.rb
116
+ - spec/model/asciitracker/model_spec.rb
117
+ - spec/model/asciitracker/record_spec.rb
118
+ - spec/model/asciitracker/slot_spec.rb
118
119
  - spec/spec_helper.rb
119
120
  homepage: ''
120
121
  licenses:
@@ -141,9 +142,9 @@ signing_key:
141
142
  specification_version: 4
142
143
  summary: time tracking the ascii way
143
144
  test_files:
144
- - spec/model/controller_spec.rb
145
- - spec/model/hhmm_spec.rb
146
- - spec/model/model_spec.rb
147
- - spec/model/record_spec.rb
148
- - spec/model/slot_spec.rb
145
+ - spec/model/asciitracker/controller_spec.rb
146
+ - spec/model/asciitracker/hhmm_spec.rb
147
+ - spec/model/asciitracker/model_spec.rb
148
+ - spec/model/asciitracker/record_spec.rb
149
+ - spec/model/asciitracker/slot_spec.rb
149
150
  - spec/spec_helper.rb
@@ -1,207 +0,0 @@
1
- require 'spec_helper'
2
-
3
- include AsciiTracker
4
- describe "AsciiTracker::Record" do
5
- it "finds the class" do
6
- Slot.should_not == nil
7
- end
8
-
9
- describe "with 10:45 - 12:15" do
10
- before :each do
11
- @rec = Slot.new :start=>"10:45", :end=>"12:15", :desc=>"foo bar"
12
- end
13
-
14
- it "should fit Records" do
15
- # span are always contained...
16
- @rec.covers?(Record.new(:span => 0.5)).should == true
17
- @rec.covers?(Record.new(:span => 1.5)).should == true
18
- end
19
-
20
- it "should not cover records with are to long" do
21
- @rec.covers?(Record.new(:span => "1:31")).should == false
22
- @rec.covers?(Record.new(:span => 5.0)).should == false
23
- end
24
-
25
- it "should calc slot covers" do
26
- @rec.covers?(Slot.new(:start=>"10:45", :end=>"12:15")).should == true
27
- @rec.covers?(Slot.new(:start=>"10:00", :end=>"12:15")).should == false
28
- @rec.covers?(Slot.new(:start=>"10:45", :end=>"13:00")).should == false
29
- end
30
- end
31
-
32
- it "should construct from start, end and desc options" do
33
- rec = Slot.new :start => "10:15", :end => "10:45", :desc => "foo bar"
34
- rec.desc.should == "foo bar"
35
- rec.t_start.should == (HHMM "10:15")
36
- rec.t_end.should == (HHMM "10:45")
37
- rec.span.should == 0.5
38
- rec.gross_length.should == 0.5
39
- rec.interrupts.length.should == 0
40
- end
41
-
42
- it "should support long overlaps around midnight" do
43
- rec = Slot.new :start => "14:00", :end => "02:00"
44
- rec.interrupts.length.should == 0
45
- rec.span.should == 12
46
- end
47
-
48
- it "should cover slots over midnight" do
49
- rec = Slot.new :start=>"23:00", :end=>"01:00", :desc=>"foo bar"
50
- rec.covers?(Record.new(:span => 1.0)).should == true
51
- end
52
-
53
- it "should support slots over midnight" do
54
- rec = Slot.new :start=>"23:00", :end=>"01:00", :desc=>"foo bar"
55
- rec.span.should == 2
56
- rec.interrupts.length.should == 0
57
-
58
- rec = Slot.new :start=>"20:00", :end=>"05:00", :desc=>"foo bar"
59
- rec.span.should == 9
60
- rec.interrupts.length.should == 0
61
- end
62
-
63
- describe "with base slot" do
64
- before :each do
65
- @base = Slot.new :start => "5:00", :end => "6:00"
66
- end
67
-
68
- it "sould calc overlaps" do
69
- a = Slot.new :start => "4:00", :end => "4:30"
70
- @base.overlaps?(a).should == false
71
-
72
- a1 = Slot.new :start => "4:00", :end => "5:00"
73
- @base.overlaps?(a1).should == false
74
-
75
- b = Slot.new :start => "1:00", :end => "5:30"
76
- @base.overlaps?(b).should == true
77
-
78
- c = Slot.new :start => "1:00", :end => "7:00"
79
- @base.overlaps?(c).should == true
80
-
81
- d = Slot.new :start => "5:15", :end => "5:45"
82
- @base.overlaps?(d).should == true
83
-
84
- d1 = Slot.new :start => "5:00", :end => "5:45"
85
- @base.overlaps?(d1).should == true
86
-
87
- d2= Slot.new :start => "5:15", :end => "6:00"
88
- @base.overlaps?(d2).should == true
89
-
90
- e = Slot.new :start => "5:30", :end => "7:00"
91
- @base.overlaps?(e).should == true
92
-
93
- f = Slot.new :start => "7:00", :end => "9:00"
94
- @base.overlaps?(f).should == false
95
-
96
- f1 = Slot.new :start => "6:00", :end => "9:00"
97
- @base.overlaps?(f1).should == false
98
- end
99
- end
100
-
101
- describe "with base over around midnight" do
102
- before :each do
103
- @base = Slot.new :start => "22:00", :end => "02:00"
104
- end
105
-
106
- it "should calc overlaps around midnight" do
107
- # before
108
- a = Slot.new :start => "20:00", :end => "21:59"
109
- @base.covers?(a).should == false
110
- @base.overlaps?(a).should == false
111
- # after
112
- a = Slot.new :start => "02:01", :end => "04:00"
113
- @base.covers?(a).should == false
114
- @base.overlaps?(a).should == false
115
-
116
- a = Slot.new :start => "23:00", :end => "23:10"
117
- puts " -- #{[@base.t_start, @base.t_end, a.t_start, a.t_end].join(', ')}"
118
- @base.covers?(a).should == true
119
- @base.overlaps?(a).should == true
120
-
121
- a = Slot.new :start => "23:00", :end => "01:00"
122
- puts " -- #{[@base.t_start, @base.t_end, a.t_start, a.t_end].join(', ')}"
123
- @base.covers?(a).should == true
124
- @base.overlaps?(a).should == true
125
-
126
- a = Slot.new :start => "01:00", :end => "01:10"
127
- puts " -- #{[@base.t_start, @base.t_end, a.t_start, a.t_end].join(', ')}"
128
- @base.overlaps?(a).should == true
129
- @base.covers?(a).should == true
130
- end
131
- end
132
- end
133
- __END__
134
-
135
- class SlotTest < Test::Unit::TestCase
136
-
137
- include Timecard
138
-
139
-
140
- def test_overlaps_around_midnight
141
- puts "\n--> #{self}"
142
-
143
- base = Slot.new :start => "22:00", :end => "02:00"
144
-
145
- # before
146
- a = Slot.new :start => "20:00", :end => "21:59"
147
- assert ! base.covers?(a)
148
- assert ! base.overlaps?(a)
149
- # after
150
- a = Slot.new :start => "02:01", :end => "04:00"
151
- assert ! base.covers?(a)
152
- assert ! base.overlaps?(a)
153
-
154
- a = Slot.new :start => "23:00", :end => "23:10"
155
- puts " -- #{[base.t_start, base.t_end, a.t_start, a.t_end].join(', ')}"
156
- assert base.covers?(a)
157
- assert base.overlaps?(a)
158
-
159
- a = Slot.new :start => "23:00", :end => "01:00"
160
- puts " -- #{[base.t_start, base.t_end, a.t_start, a.t_end].join(', ')}"
161
- assert base.covers?(a)
162
- assert base.overlaps?(a)
163
-
164
- a = Slot.new :start => "01:00", :end => "01:10"
165
- puts " -- #{[base.t_start, base.t_end, a.t_start, a.t_end].join(', ')}"
166
- assert base.overlaps?(a)
167
- assert base.covers?(a)
168
- end
169
-
170
- def test_add_interrupt_slot_or_span
171
- puts "\n--> #{self}"
172
- rec = Slot.new :start=>"10:00", :end=>"12:30", :desc=>"foo bar"
173
- assert_equal 2.5, rec.span
174
- assert_equal 0, rec.interrupts.length
175
-
176
- wasted_time = Record.new :span => 1, :desc => "one hour of wasted time"
177
- rec.add_interrupt wasted_time
178
- assert_equal 1, rec.interrupts.length
179
- assert_equal 1.5, rec.span
180
- rec.add_interrupt wasted_time
181
- assert_equal 2, rec.interrupts.length
182
- assert_equal 0.5, rec.span
183
-
184
- assert_raise(TimecardException) { rec.add_interrupt(wasted_time) }
185
-
186
- rec = Slot.new :start=>"10:00", :end=>"12:30", :desc=>"foo bar"
187
- slot = Slot.new :start=>"10:00", :end => "12:00", :desc => "intruppt"
188
- rec.add_interrupt(slot)
189
- assert_equal 0.5, rec.span
190
-
191
- slot = Slot.new :start=>"12:30", :end => "13:00", :desc => "intruppt"
192
- assert_raise(TimecardException) { rec.add_interrupt(slot) }
193
- slot = Slot.new :start=>"09:30", :end => "11:00", :desc => "intruppt"
194
- assert_raise(TimecardException) { rec.add_interrupt(slot) }
195
-
196
- slot = Slot.new :start=>"12:00", :end => "12:15", :desc => "intruppt"
197
- rec.add_interrupt(slot)
198
- assert_equal 0.25, rec.span
199
- slot = Slot.new :start=>"12:15", :end => "12:30", :desc => "intruppt"
200
- rec.add_interrupt(slot)
201
- assert_equal 0.0, rec.span
202
-
203
- slot = Slot.new :start=>"12:15", :end => "12:30", :desc => "intruppt"
204
- assert_raise(TimecardException) { rec.add_interrupt(slot) }
205
- end
206
- end
207
-