positionrange 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,146 @@
1
+ #--#
2
+ # Copyright: (c) 2006-2008 The LogiLogi Foundation <foundation@logilogi.org>
3
+ #
4
+ # License:
5
+ # This file is part of the PositionRange Library. PositionRange is free
6
+ # software. You can run/distribute/modify PositionRange under the terms of
7
+ # the GNU Affero General Public License version 3. The Affero GPL states
8
+ # that running a modified version or a derivative work also requires you to
9
+ # make the sourcecode of that work available to everyone that can interact
10
+ # with it. We chose the Affero GPL to ensure that PositionRange remains open
11
+ # and libre (LICENSE.txt contains the full text of the legally binding
12
+ # license).
13
+ #++#
14
+
15
+ require File.dirname(__FILE__) + '/test_helper.rb'
16
+
17
+ class PositionRangeTest < Test::Unit::TestCase
18
+ ### Initialization
19
+
20
+ def test_initialization
21
+ p = PositionRange.new(2,6, :mooo => 88)
22
+ assert_equal 2, p.first
23
+ assert_equal 6, p.last
24
+ assert_equal 88, p.mooo
25
+ end
26
+
27
+ def test_initialization_exceptions
28
+ assert_raise(PositionRange::Error) {
29
+ PositionRange.new(4,2)
30
+ }
31
+ assert_raise(PositionRange::Error) {
32
+ PositionRange.new(-1,3)
33
+ }
34
+ end
35
+
36
+ ### Parsing
37
+
38
+ def test_parsing
39
+ assert_equal PositionRange.new(1,4), PositionRange.from_s('1,4')
40
+ assert_equal '1,3', PositionRange.new(1,3).to_s
41
+ end
42
+
43
+ def test_parsing_exceptions
44
+ assert_raise(StandardError) {
45
+ PositionRange.from_s('4,,2')
46
+ }
47
+ end
48
+
49
+ ### Methods
50
+
51
+ def test_define_attribute
52
+ p = PositionRange.new(1,2, :kk => 0)
53
+ assert p.respond_to?('kk')
54
+ p.kk = 3
55
+ assert_equal 3, p.kk
56
+ p.lll = 5
57
+ assert_equal 5, p.lll
58
+ p2 = PositionRange.new(1,2)
59
+ assert p2.attributes.include?('kk')
60
+ assert p2.attributes.include?('lll')
61
+ end
62
+
63
+ def test_dynamic_attributes
64
+ p = PositionRange.new(1,3,:blah => 2)
65
+ assert_equal 2, p.blah
66
+ k = PositionRange.new(2,44,:blah => 7)
67
+ assert_equal 7, k.blah
68
+ assert_equal 2, p.blah
69
+ end
70
+
71
+ def test_size
72
+ assert_equal 3, PositionRange.new(1,4).size
73
+ end
74
+
75
+ def test_new_dup
76
+ p = PositionRange.new(1,3)
77
+ p.authorship = 'a'
78
+ p.link = 34
79
+
80
+ pd = p.new_dup(4,6)
81
+
82
+ assert_equal p.authorship, pd.authorship
83
+ assert_equal p.link, pd.link
84
+ end
85
+
86
+ def test_substraction
87
+ p1 = PositionRange.new(11,20)
88
+ p2 = PositionRange.new(16,25)
89
+ assert_equal PositionRange.new(11,16), p1 - p2
90
+
91
+ p3 = PositionRange.new(10,11)
92
+ assert_equal PositionRange.new(11,20), p1 - p3
93
+
94
+ p4 = PositionRange.new(19,21)
95
+ assert_equal PositionRange.new(11,19), p1 - p4
96
+
97
+ p5 = p1.dup
98
+ assert_equal nil, p1 - p5
99
+
100
+ p6 = PositionRange.new(30,80)
101
+ assert_equal p1, p1 - p6
102
+
103
+ p7 = PositionRange.new(2,4)
104
+ p8 = PositionRange.new(3,4)
105
+ assert_equal PositionRange.new(2,3), p7 - p8
106
+ end
107
+
108
+ def test_eq_eq_eq
109
+ p1 = PositionRange.new(1,5)
110
+ p2 = PositionRange.new(4,10)
111
+ assert p1 === p2
112
+
113
+ p3 = PositionRange.new(2,3)
114
+ assert p1 === p3
115
+
116
+ p4 = PositionRange.new(15,90)
117
+ assert !(p1 === p4)
118
+ end
119
+
120
+ def test_comparison
121
+ p1 = PositionRange.new(1,3)
122
+ p2 = PositionRange.new(2,3)
123
+ assert p1 < p2
124
+
125
+ p1 = PositionRange.new(1,3)
126
+ p2 = PositionRange.new(1,2)
127
+ assert p1 > p2
128
+
129
+ p1 = PositionRange.new(1,3)
130
+ p2 = PositionRange.new(1,3)
131
+ assert p1 == p2
132
+ end
133
+
134
+ def test_has_equal_pointer_attributes
135
+ p1 = PositionRange.new(1,3)
136
+ p1.link = 'aa'
137
+ p2 = PositionRange.new(7,13)
138
+ p2.link = 'aa'
139
+ p2.authorship = 3
140
+ assert !p1.has_equal_pointer_attributes?(p2)
141
+ p2.authorship = nil
142
+ assert p1.has_equal_pointer_attributes?(p2)
143
+ p2.link = 'ac'
144
+ assert !p1.has_equal_pointer_attributes?(p2)
145
+ end
146
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/position_range'
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: positionrange
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Wybo Wiersma
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-29 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Allows you to assign random attributes to ranges and juggle them in lists.
17
+ email: wybo@logilogi.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - Rakefile
26
+ - install.rb
27
+ - README.txt
28
+ - CHANGELOG.txt
29
+ - LICENSE.txt
30
+ - lib/position_range.rb
31
+ - lib/positionrange.rb
32
+ - lib/position_range
33
+ - lib/position_range/error.rb
34
+ - lib/position_range/list.rb
35
+ - lib/position_range/version.rb
36
+ - test/position_range_list_test.rb
37
+ - test/position_range_test.rb
38
+ - test/test_helper.rb
39
+ has_rdoc: true
40
+ homepage: http://positionrange.rubyforge.org
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements:
59
+ - none
60
+ rubyforge_project: positionrange
61
+ rubygems_version: 1.3.1
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Ranges with attributes that can be juggled.
65
+ test_files: []
66
+