boundy 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/boundy.rb +19 -0
- data/lib/boundy/bound.rb +65 -0
- data/lib/boundy/bound/comparator.rb +67 -0
- data/lib/boundy/bound/constrainer.rb +29 -0
- data/lib/boundy/bound/infinite.rb +46 -0
- data/lib/boundy/bound/infinite/above.rb +12 -0
- data/lib/boundy/bound/infinite/below.rb +13 -0
- data/lib/boundy/comparator.rb +19 -0
- data/lib/boundy/comparators.rb +28 -0
- data/lib/boundy/domain.rb +115 -0
- data/lib/boundy/domain/anterior.rb +45 -0
- data/lib/boundy/domain/builder.rb +31 -0
- data/lib/boundy/domain/comparator.rb +26 -0
- data/lib/boundy/domain/constrainer.rb +21 -0
- data/lib/boundy/domain/finite.rb +64 -0
- data/lib/boundy/domain/posterior.rb +43 -0
- data/lib/boundy/formatter.rb +9 -0
- data/lib/boundy/formatter/sql.rb +26 -0
- data/lib/boundy/formatter/sql/domain.rb +20 -0
- data/lib/boundy/formatter/sql/domain/plugin.rb +22 -0
- data/lib/boundy/formatter/sql/factory.rb +14 -0
- data/lib/boundy/formatter/sql/plugin.rb +38 -0
- data/lib/boundy/formatters/bound.rb +16 -0
- data/lib/boundy/formatters/domain.rb +12 -0
- data/lib/boundy/formatters/fixnum.rb +20 -0
- data/lib/boundy/formatters/sql/bound.rb +22 -0
- data/lib/boundy/formatters/sql/domain.rb +28 -0
- data/lib/boundy/formatters/sql/domain/anterior.rb +23 -0
- data/lib/boundy/formatters/sql/domain/finite.rb +24 -0
- data/lib/boundy/formatters/sql/domain/posterior.rb +23 -0
- data/lib/boundy/formatters/time.rb +42 -0
- data/lib/boundy/range/comparator.rb +38 -0
- data/lib/boundy/range/constrainer.rb +17 -0
- data/lib/boundy/time/comparator.rb +37 -0
- data/test/integration/boundy_test.rb +37 -0
- data/test/integration/domain_test.rb +18 -0
- data/test/integration/formatter/sql_test.rb +21 -0
- data/test/integration/test_helper.rb +14 -0
- data/test/unit/boundy/bound/comparator_test.rb +37 -0
- data/test/unit/boundy/bound/constrainer_test.rb +123 -0
- data/test/unit/boundy/bound/infinite/above_test.rb +36 -0
- data/test/unit/boundy/bound/infinite/below_test.rb +36 -0
- data/test/unit/boundy/bound/infinite_test.rb +0 -0
- data/test/unit/boundy/bound_test.rb +86 -0
- data/test/unit/boundy/comparator_test.rb +0 -0
- data/test/unit/boundy/domain/anterior_test.rb +103 -0
- data/test/unit/boundy/domain/comparator_test.rb +75 -0
- data/test/unit/boundy/domain/constrainer_test.rb +11 -0
- data/test/unit/boundy/domain/posterior_test.rb +75 -0
- data/test/unit/boundy/domain_test.rb +50 -0
- data/test/unit/boundy/formatter/sql/domain/plugin_test.rb +16 -0
- data/test/unit/boundy/formatter/sql/plugin_test.rb +50 -0
- data/test/unit/boundy/formatter/sql_test.rb +26 -0
- data/test/unit/boundy/formatters/bound_test.rb +43 -0
- data/test/unit/boundy/formatters/domain_test.rb +12 -0
- data/test/unit/boundy/formatters/sql/domain/anterior_test.rb +29 -0
- data/test/unit/boundy/formatters/sql/domain/finite_test.rb +35 -0
- data/test/unit/boundy/formatters/sql/domain/posterior_test.rb +30 -0
- data/test/unit/boundy/formatters/time_test.rb +27 -0
- data/test/unit/boundy/range/comparator_test.rb +44 -0
- data/test/unit/boundy/range/constrainer_test.rb +11 -0
- data/test/unit/boundy/time/comparator_test.rb +40 -0
- data/test/unit/test_helper.rb +14 -0
- metadata +154 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
require 'boundy/bound'
|
4
|
+
require 'boundy/bound/infinite/above'
|
5
|
+
|
6
|
+
class Boundy::Bound::Infinite::AboveTest < Test::Unit::TestCase
|
7
|
+
setup do
|
8
|
+
now = Time.now
|
9
|
+
@now_bound = Boundy::Bound.new(now)
|
10
|
+
@above = Boundy::Bound::Infinite::Above.new
|
11
|
+
end
|
12
|
+
|
13
|
+
test "< finite" do
|
14
|
+
assert_equal false, @above < @now_bound
|
15
|
+
end
|
16
|
+
|
17
|
+
test "> finite" do
|
18
|
+
assert_equal true, @above > @now_bound
|
19
|
+
end
|
20
|
+
|
21
|
+
test "<= finite" do
|
22
|
+
assert_equal false, @above <= @now_bound
|
23
|
+
end
|
24
|
+
|
25
|
+
test "=> finite" do
|
26
|
+
assert_equal true, @above >= @now_bound
|
27
|
+
end
|
28
|
+
|
29
|
+
test "==" do
|
30
|
+
assert_equal false, @above == @now_bound
|
31
|
+
end
|
32
|
+
|
33
|
+
test "<=> finite" do
|
34
|
+
assert_equal 1, @above <=> @now_bound
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path('../../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
require 'boundy/bound'
|
4
|
+
require 'boundy/bound/infinite/below'
|
5
|
+
|
6
|
+
class Boundy::Bound::Infinite::BelowTest < Test::Unit::TestCase
|
7
|
+
setup do
|
8
|
+
now = Time.now
|
9
|
+
@now_bound = Boundy::Bound.new(now)
|
10
|
+
@above = Boundy::Bound::Infinite::Below.new
|
11
|
+
end
|
12
|
+
|
13
|
+
test "< finite" do
|
14
|
+
assert_equal true, @above < @now_bound
|
15
|
+
end
|
16
|
+
|
17
|
+
test "> finite" do
|
18
|
+
assert_equal false, @above > @now_bound
|
19
|
+
end
|
20
|
+
|
21
|
+
test "<= finite" do
|
22
|
+
assert_equal true, @above <= @now_bound
|
23
|
+
end
|
24
|
+
|
25
|
+
test "=> finite" do
|
26
|
+
assert_equal false, @above >= @now_bound
|
27
|
+
end
|
28
|
+
|
29
|
+
test "==" do
|
30
|
+
assert_equal false, @above == @now_bound
|
31
|
+
end
|
32
|
+
|
33
|
+
test "<=> finite" do
|
34
|
+
assert_equal -1, @above <=> @now_bound
|
35
|
+
end
|
36
|
+
end
|
File without changes
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
require 'boundy/bound'
|
4
|
+
require 'boundy/domain'
|
5
|
+
require 'boundy/domain/anterior'
|
6
|
+
require 'boundy/domain/posterior'
|
7
|
+
|
8
|
+
class Boundy::BoundTest < Test::Unit::TestCase
|
9
|
+
time = 5.days.ago
|
10
|
+
test_bound = Boundy::Bound.new(time)
|
11
|
+
|
12
|
+
times = [
|
13
|
+
{
|
14
|
+
name: "behind",
|
15
|
+
time: time - 2.days,
|
16
|
+
truthiness: [
|
17
|
+
{method: :within?, domain: :anterior},
|
18
|
+
{method: :before?, domain: :posterior}
|
19
|
+
]
|
20
|
+
},
|
21
|
+
{
|
22
|
+
name: "equal",
|
23
|
+
time: time,
|
24
|
+
truthiness: [
|
25
|
+
{method: :within?, domain: :anterior},
|
26
|
+
{method: :within?, domain: :posterior},
|
27
|
+
{method: :within?, domain: :enclosed}
|
28
|
+
]
|
29
|
+
},
|
30
|
+
{
|
31
|
+
name: "ahead",
|
32
|
+
time: time + 2.days,
|
33
|
+
truthiness: [
|
34
|
+
{method: :within?, domain: :posterior},
|
35
|
+
{method: :after?, domain: :anterior}
|
36
|
+
]
|
37
|
+
}
|
38
|
+
]
|
39
|
+
|
40
|
+
domain_classes = {
|
41
|
+
:anterior => Boundy::Domain::Anterior,
|
42
|
+
:posterior => Boundy::Domain::Posterior,
|
43
|
+
:enclosed => Boundy::Domain
|
44
|
+
}
|
45
|
+
|
46
|
+
domains = [:anterior, :posterior]
|
47
|
+
methods = [:before?, :within?, :after?]
|
48
|
+
|
49
|
+
cases = times.product(methods, domains).map do |p|
|
50
|
+
t = p[0]
|
51
|
+
method = p[1]
|
52
|
+
domain = p[2]
|
53
|
+
|
54
|
+
truthiness = t[:truthiness]
|
55
|
+
klass = domain_classes[domain]
|
56
|
+
|
57
|
+
expected = (truthiness.include?({method: method, domain: domain}))
|
58
|
+
|
59
|
+
t.merge({ :method => method,
|
60
|
+
:domain => domain,
|
61
|
+
:class => klass,
|
62
|
+
:expected => expected,
|
63
|
+
:failure => "#{domain.to_s}##{method} against #{t[:time]}"
|
64
|
+
})
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
cases.each do |c|
|
69
|
+
test "##{c[:domain]}##{c[:method]}_#{c[:name]}" do
|
70
|
+
bound = Boundy::Bound.new(c[:time])
|
71
|
+
domain = c[:class].new(bound)
|
72
|
+
result = test_bound.method(c[:method]).call(domain)
|
73
|
+
assert_equal c[:expected], result, c[:failure]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
test "<=>" do
|
78
|
+
now = Time.new(2013,9,1)
|
79
|
+
|
80
|
+
from = Boundy::Bound.new(now - 5.day)
|
81
|
+
to = Boundy::Bound.new(now - 1.day)
|
82
|
+
|
83
|
+
assert_equal from <=> to, -1
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
File without changes
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
require 'boundy/domain'
|
4
|
+
require 'boundy/domain/anterior'
|
5
|
+
|
6
|
+
class Boundy::Domain::AnteriorTest < Test::Unit::TestCase
|
7
|
+
setup do
|
8
|
+
@now = Time.now
|
9
|
+
|
10
|
+
@before = @now - 5.days
|
11
|
+
|
12
|
+
@tighter_before = @now - 4.days
|
13
|
+
@looser_before = @now - 6.days
|
14
|
+
|
15
|
+
@after = @now - 2.days
|
16
|
+
@tighter_after = @now - 3.days
|
17
|
+
@looser_after = @now - 1.days
|
18
|
+
|
19
|
+
@datum = @before
|
20
|
+
|
21
|
+
@range = Boundy::Domain::Anterior.new(@datum)
|
22
|
+
end
|
23
|
+
|
24
|
+
# constrain_to
|
25
|
+
test 'constrain_to domain equal' do
|
26
|
+
new = Boundy::Domain.new(@before, @after)
|
27
|
+
|
28
|
+
result = @range.constrain_to(new)
|
29
|
+
|
30
|
+
assert_equal @before, result.from.datum
|
31
|
+
assert_equal @after, result.to.datum
|
32
|
+
end
|
33
|
+
|
34
|
+
test 'constrain_to domain tighter' do
|
35
|
+
new = Boundy::Domain.new(@tighter_before, @tighter_after)
|
36
|
+
|
37
|
+
result = @range.constrain_to(new)
|
38
|
+
|
39
|
+
assert_equal @tighter_before, result.from.datum
|
40
|
+
assert_equal @tighter_after, result.to.datum
|
41
|
+
end
|
42
|
+
|
43
|
+
test 'constrain_to domain loserr' do
|
44
|
+
new = Boundy::Domain.new(@looser_before, @looser_after)
|
45
|
+
|
46
|
+
result = @range.constrain_to(new)
|
47
|
+
|
48
|
+
assert_equal @before, result.from.datum
|
49
|
+
assert_equal @looser_after, result.to.datum
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'constrain_to anterior domain equal' do
|
53
|
+
new = Boundy::Domain::Anterior.new(@before)
|
54
|
+
|
55
|
+
result = @range.constrain_to(new)
|
56
|
+
|
57
|
+
assert_equal @before, result.from.datum
|
58
|
+
end
|
59
|
+
|
60
|
+
test 'constrain_to anterior domain tighter' do
|
61
|
+
new = Boundy::Domain::Anterior.new(@tighter_before)
|
62
|
+
|
63
|
+
result = @range.constrain_to(new)
|
64
|
+
|
65
|
+
assert_equal @tighter_before, result.from.datum
|
66
|
+
end
|
67
|
+
|
68
|
+
test 'constrain_to anterior domain loserr' do
|
69
|
+
new = Boundy::Domain::Anterior.new(@looser_before)
|
70
|
+
|
71
|
+
result = @range.constrain_to(new)
|
72
|
+
|
73
|
+
assert_equal @before, result.from.datum
|
74
|
+
end
|
75
|
+
|
76
|
+
test 'constrain_to range equal' do
|
77
|
+
range = (@before .. @after)
|
78
|
+
|
79
|
+
result = @range.constrain_to(range)
|
80
|
+
|
81
|
+
assert_equal @before, result.from.datum
|
82
|
+
assert_equal @after, result.to.datum
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'constrain_to range tighter' do
|
86
|
+
range = (@tighter_before .. @tighter_after)
|
87
|
+
|
88
|
+
result = @range.constrain_to(range)
|
89
|
+
|
90
|
+
assert_equal @tighter_before, result.from.datum
|
91
|
+
assert_equal @tighter_after, result.to.datum
|
92
|
+
end
|
93
|
+
|
94
|
+
test 'constrain_to range looser' do
|
95
|
+
range = (@looser_before .. @looser_after)
|
96
|
+
|
97
|
+
result = @range.constrain_to(range)
|
98
|
+
|
99
|
+
assert_equal @before, result.from.datum
|
100
|
+
assert_equal @looser_after, result.to.datum
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
require 'boundy/bound'
|
4
|
+
require 'boundy/domain'
|
5
|
+
require 'boundy/domain/comparator'
|
6
|
+
|
7
|
+
class Boundy::Domain::ComparatorTest < Test::Unit::TestCase
|
8
|
+
time = 5.days.ago
|
9
|
+
test_bound = Boundy::Bound.new(time)
|
10
|
+
|
11
|
+
times = [
|
12
|
+
{
|
13
|
+
name: "behind",
|
14
|
+
range: (time - 2.days .. time - 1.day),
|
15
|
+
truthiness: [
|
16
|
+
{method: :before?}
|
17
|
+
]
|
18
|
+
},
|
19
|
+
{
|
20
|
+
name: "touching from behind",
|
21
|
+
range: (time - 1.days .. time),
|
22
|
+
truthiness: [
|
23
|
+
{method: :within?}
|
24
|
+
]
|
25
|
+
},
|
26
|
+
{
|
27
|
+
name: "within",
|
28
|
+
range: (time - 1.days .. time + 1.day),
|
29
|
+
truthiness: [
|
30
|
+
{method: :within?}
|
31
|
+
]
|
32
|
+
},
|
33
|
+
{
|
34
|
+
name: "touching from ahead",
|
35
|
+
range: (time .. time + 1.day),
|
36
|
+
truthiness: [
|
37
|
+
{method: :within?}
|
38
|
+
]
|
39
|
+
},
|
40
|
+
{
|
41
|
+
name: "ahead",
|
42
|
+
range: (time + 1.days .. time + 2.day),
|
43
|
+
truthiness: [
|
44
|
+
{method: :after?}
|
45
|
+
]
|
46
|
+
}
|
47
|
+
]
|
48
|
+
|
49
|
+
methods = [:before?, :after?, :within?]
|
50
|
+
|
51
|
+
cases = times.product(methods).map do |p|
|
52
|
+
t = p[0]
|
53
|
+
method = p[1]
|
54
|
+
truthiness = t[:truthiness]
|
55
|
+
|
56
|
+
expected = (truthiness.include?({method: method}))
|
57
|
+
|
58
|
+
t.merge({ :method => method,
|
59
|
+
:expected => expected,
|
60
|
+
:failure => "#{method} failed"
|
61
|
+
})
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
cases.each do |c|
|
66
|
+
test "##{c[:method]}_#{c[:name]}" do
|
67
|
+
range = c[:range]
|
68
|
+
domain = Boundy::Domain.new(range.begin, range.end)
|
69
|
+
comp = Boundy::Domain::Comparator.new(test_bound, domain)
|
70
|
+
|
71
|
+
assert_equal c[:expected], comp.method(c[:method]).call
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
require 'boundy/domain/constrainer'
|
4
|
+
|
5
|
+
class Boundy::Domain::ConstrainerTest < Test::Unit::TestCase
|
6
|
+
test "foo" do
|
7
|
+
mock_range = mock
|
8
|
+
mock_bound = mock
|
9
|
+
Boundy::Domain::Constrainer.new(mock_range,mock_bound)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require File.expand_path('../../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
require 'boundy/domain'
|
4
|
+
require 'boundy/domain/posterior'
|
5
|
+
|
6
|
+
class Boundy::Domain::PosteriorTest < Test::Unit::TestCase
|
7
|
+
setup do
|
8
|
+
@now = Time.now
|
9
|
+
@before = @now - 5.days
|
10
|
+
|
11
|
+
@tighter_before = @now - 4.days
|
12
|
+
@looser_before = @now - 6.days
|
13
|
+
|
14
|
+
@after = @now - 2.days
|
15
|
+
@tighter_after = @now - 3.days
|
16
|
+
@looser_after = @now - 1.days
|
17
|
+
|
18
|
+
@datum = @after
|
19
|
+
|
20
|
+
@range = Boundy::Domain::Posterior.new(@datum)
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'constrain_to datum_bound equal' do
|
24
|
+
new = Boundy::Domain.new(@before, @after)
|
25
|
+
|
26
|
+
result = @range.constrain_to(new)
|
27
|
+
|
28
|
+
assert_equal @before, result.from.datum
|
29
|
+
assert_equal @after, result.to.datum
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'constrain_to datum_bound tighter' do
|
33
|
+
new = Boundy::Domain.new(@tighter_before, @tighter_after)
|
34
|
+
|
35
|
+
result = @range.constrain_to(new)
|
36
|
+
|
37
|
+
assert_equal @tighter_before, result.from.datum
|
38
|
+
assert_equal @tighter_after, result.to.datum
|
39
|
+
end
|
40
|
+
|
41
|
+
test 'constrain_to datum_bound looser' do
|
42
|
+
new = Boundy::Domain.new(@looser_before, @looser_after)
|
43
|
+
|
44
|
+
result = @range.constrain_to(new)
|
45
|
+
|
46
|
+
assert_equal @looser_before, result.from.datum
|
47
|
+
assert_equal @after, result.to.datum
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'constrain_to range equal' do
|
51
|
+
range = (@before .. @after)
|
52
|
+
|
53
|
+
result = @range.constrain_to(range)
|
54
|
+
|
55
|
+
assert_equal @before, result.from.datum
|
56
|
+
assert_equal @after, result.to.datum
|
57
|
+
end
|
58
|
+
test 'constrain_to range tighter' do
|
59
|
+
range = (@tighter_before .. @tighter_after)
|
60
|
+
|
61
|
+
result = @range.constrain_to(range)
|
62
|
+
|
63
|
+
assert_equal @tighter_before, result.from.datum
|
64
|
+
assert_equal @tighter_after, result.to.datum
|
65
|
+
end
|
66
|
+
|
67
|
+
test 'constrain_to range looser' do
|
68
|
+
range = (@looser_before .. @looser_after)
|
69
|
+
|
70
|
+
result = @range.constrain_to(range)
|
71
|
+
|
72
|
+
assert_equal @looser_before, result.from.datum
|
73
|
+
assert_equal @after, result.to.datum
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.expand_path('../../test_helper', __FILE__)
|
2
|
+
|
3
|
+
require 'boundy/domain'
|
4
|
+
require 'boundy/domain/finite'
|
5
|
+
require 'boundy/range/comparator'
|
6
|
+
|
7
|
+
class Boundy::DomainTest < Test::Unit::TestCase
|
8
|
+
setup do
|
9
|
+
@now = Time.now
|
10
|
+
@before = @now - 5.days
|
11
|
+
|
12
|
+
@tighter_before = @now - 4.days
|
13
|
+
@looser_before = @now - 6.days
|
14
|
+
|
15
|
+
@after = @now - 2.days
|
16
|
+
@tighter_after = @now - 3.days
|
17
|
+
@looser_after = @now - 1.days
|
18
|
+
|
19
|
+
@domain = Boundy::Domain.new(@before, @after)
|
20
|
+
end
|
21
|
+
|
22
|
+
test 'constrain_to domain equal' do
|
23
|
+
new = Boundy::Domain.new(@before, @after)
|
24
|
+
|
25
|
+
result = @domain.constrain_to(new)
|
26
|
+
|
27
|
+
assert_equal @before, result.from.datum
|
28
|
+
assert_equal @after, result.to.datum
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'constrain_to domain tighter' do
|
32
|
+
new = Boundy::Domain.new(@tighter_before, @tighter_after)
|
33
|
+
|
34
|
+
result = @domain.constrain_to(new)
|
35
|
+
|
36
|
+
assert_equal @tighter_before, result.from.datum
|
37
|
+
assert_equal @tighter_after, result.to.datum
|
38
|
+
end
|
39
|
+
|
40
|
+
test 'constrain_to domain loserr' do
|
41
|
+
new = Boundy::Domain.new(@looser_before, @looser_after)
|
42
|
+
|
43
|
+
result = @domain.constrain_to(new)
|
44
|
+
|
45
|
+
assert_equal @before, result.from.datum
|
46
|
+
assert_equal @after, result.to.datum
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|