xrvg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,207 @@
1
+ require 'test/unit'
2
+ require 'utils'
3
+
4
+ class IntegerTest < Test::Unit::TestCase
5
+
6
+ def test_denum!
7
+ assert_equal( [10.0, 20.0, 30.0], (10.0..30.0).samples( 3 ) )
8
+ end
9
+
10
+ def test_numsplit!
11
+ assert_equal( [0.0, 5.0, 10.0], (0.0..10.0).samples( 3 ) )
12
+ end
13
+
14
+ def test_itergeo!
15
+ # assert_equal( [1.0, 0.246596963941606, 0.0608100626252179], (1.0..0.0).geo(2.8).samples(3) )
16
+ end
17
+
18
+ def test_randsplit1!
19
+ result = 3.randsplit!
20
+ puts "result #{result.join(" ")}"
21
+ assert_equal( 1.0, result[0] + result[1] + result[2] )
22
+ end
23
+
24
+ if nil
25
+ def test_randsplit2!
26
+ result = 3.randsplit!(0.3)
27
+ puts "result minsize 0.3 #{result.join(" ")}"
28
+ assert_equal( 1.0, result[0] + result[1] + result[2] )
29
+ result.each {|v| assert( v > 0.3 ) }
30
+ end
31
+ end
32
+
33
+ def test_randsplitsum!
34
+ result = 3.randsplitsum!
35
+ puts "test_randsplitsum! result #{result.join(" ")}"
36
+ result.each_cons(2) {|min, max| assert( min <= max )}
37
+ end
38
+
39
+ def test_randsplitsum2!
40
+ result = 3.randsplitsum!(0.3)
41
+ puts "test_randsplitsum! minsize result #{result.join(" ")}"
42
+ result.each_cons(2) {|min, max| assert( min <= max )}
43
+ end
44
+
45
+ end
46
+
47
+ class StringTest < Test::Unit::TestCase
48
+
49
+ def test_subreplace
50
+ alpha = "1"
51
+ beta = "2"
52
+ tokens = {"%ALPHA%" => alpha,
53
+ "%BETA%" => beta }
54
+ assert_equal( "1 > 2", "%ALPHA% > %BETA%".subreplace( tokens ) )
55
+ end
56
+ end
57
+
58
+
59
+ class ArrayTest < Test::Unit::TestCase
60
+
61
+ def test_pairs
62
+ a = [ 1, 2, 3]
63
+ b = Array.new
64
+ a.pairs { |i1, i2| b.push( [i1, i2] ) }
65
+ assert_equal( [[1,2] , [2,3]], b )
66
+ end
67
+
68
+ def test_pairs2
69
+ a = [ 1, 2, 3]
70
+ assert_equal( [[1,2] , [2,3]], a.pairs )
71
+ end
72
+
73
+
74
+ def test_foreach
75
+ b = Array.new
76
+ [1, 2, 3, 4].foreach {|i, j| b.push( [j,i] )}
77
+ assert_equal( [[2, 1], [4, 3]], b)
78
+ end
79
+
80
+ def test_slice
81
+ assert_equal( [1, 2, 3], [0, 1, 2, 3].[](1..-1) )
82
+ end
83
+
84
+ def test_uplets
85
+ assert_equal( [[1, 2], [2, 3]], [1, 2, 3].uplets(2) )
86
+ result = []; [1, 2, 3].uplets {|i,j| result.push( [i,j] )}
87
+ assert_equal( [[1, 2], [2, 3]], result )
88
+ end
89
+
90
+ def test_assignment
91
+ a, b, c = [1, 2, 3]
92
+ assert_equal( a, 1 )
93
+ assert_equal( b, 2 )
94
+ assert_equal( c, 3 )
95
+ end
96
+
97
+ def test_hash
98
+ a = ["a", 1, "b", 2, "c", 3]
99
+ b = Hash[ *a ]
100
+ assert_equal( 1, b["a"] )
101
+ end
102
+
103
+ def test_flattenonce
104
+ assert_equal( [1,2], [[1], [2]].flattenonce )
105
+ end
106
+
107
+ def test_forzip
108
+ assert_equal( [1,2,"a",3,4,"b"], [ [1,2,3,4], ["a","b"] ].forzip( [2,1] ) )
109
+ assert_equal( [1,2,"a",3,4,"b"], [ [1,2,3,4], ["a","b"] ].forzip( [2] ) )
110
+ result = []; [ [1,2,3,4], ["a","b"] ].forzip( [2,1] ) {|i,j,k| result.push( [k,j,i] )}
111
+ assert_equal( [["a",2,1],["b",4,3]], result )
112
+ assert_equal( [[1], 1, [2], 2], [[[1],[2]], [1, 2]].forzip )
113
+ end
114
+
115
+ def test_forpattern
116
+ assert_equal( [1,2,"a",3,4,"b"], [ [1,2,3,4], ["a","b"] ].forpattern( [0,0,1] ) )
117
+ assert_equal( [1,"a",2,3,"b",4], [ [1,2,3,4], ["a","b"] ].forpattern( [0,1,0] ) )
118
+ end
119
+
120
+ def test_sub
121
+ assert_equal( [1,3,5], [1,2,3,4,5].sub(2) )
122
+ assert_equal( [1,3,5], [1,2,3,4,5].half )
123
+ end
124
+
125
+ end
126
+
127
+ class FloatTest < Test::Unit::TestCase
128
+
129
+ def test_interpol
130
+ assert_equal( 2.3, ( 2.0..3.0 ).sample( 0.3 ) )
131
+ end
132
+
133
+ def test_complement
134
+ assert_equal( 0.75, 0.25.complement )
135
+ end
136
+
137
+ def test_randsplit
138
+ assert_equal( 2, 0.25.randsplit.length )
139
+ puts "randsplit 0.25 #{0.25.randsplit}"
140
+ r = 0.25.randsplit
141
+ assert_equal( 0.25, r[0] + r[1] )
142
+ end
143
+
144
+ end
145
+
146
+ class RangeTest < Test::Unit::TestCase
147
+
148
+ def test_samples
149
+ assert_equal( [0.0, 0.5, 1.0], (0.0..1.0).samples(3))
150
+ end
151
+
152
+ def test_samples2
153
+ # assert_equal( [0.0, 0.667128916301921, 0.889196841637666], (0.0..1.0).geo(2.2).samples(3))
154
+ end
155
+
156
+ def test_split
157
+ assert_equal( [(0.0..0.5), (0.5..1.0)], (0.0..1.0).splits(2) )
158
+ end
159
+
160
+ def test_split2
161
+ # assert_equal( [(0.0..0.75), (0.75..1.0)], (0.0..1.0).geo(3.0).splits(2) )
162
+ end
163
+
164
+ def test_period
165
+ assert_equal( [0.0, 0.5, 1.0], (0.0..1.0).samples(3))
166
+ assert_equal( [0.0, 0.5, 1.0, 1.5, 2.0], (0.0..2.0).samples(5))
167
+ end
168
+
169
+ def test_bisamples
170
+ # assert_equal( [0.0, 0.5, 1.0], (0.0..1.0).bisamples([0.5, 0.5]) )
171
+ # assert_equal( [0.0, 0.4, 0.5, 0.9, 1.0], (0.0..1.0).bisamples([0.4, 0.1]) )
172
+ end
173
+ end
174
+
175
+ class SampleClass
176
+ include Samplable
177
+
178
+ def sampleA( abs )
179
+ return "a#{abs}"
180
+ end
181
+
182
+ def sampleB( abs )
183
+ return "b#{abs}"
184
+ end
185
+ end
186
+
187
+ class SampleTest < Test::Unit::TestCase
188
+
189
+ def test_samples
190
+ assert_equal( [0.0, 1.0, 2.0], (0.0..2.0).samples(3))
191
+ end
192
+
193
+ def test_array_samples
194
+ # TODO
195
+ # assert_equal( [0.0, 0.0, 0.864664716763387, 1.72932943352677], [(0.0..1.0),(0.0..2.0)].geo(2.0).samples(3))
196
+ end
197
+
198
+ def test_class_sample
199
+ s = SampleClass.new
200
+ assert_equal( ["a0.0", "b0.0", "a0.5", "b0.5", "a1.0", "b1.0"], [s.filter(:sampleA), s.filter(:sampleB)].samples(3))
201
+ end
202
+
203
+ def test_roller
204
+ assert_equal( ["a", "b", "a"], Roller["a","b"].samples(3))
205
+ end
206
+
207
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: xrvg
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2008-02-02 00:00:00 +01:00
8
+ summary: Ruby vector graphics library
9
+ require_paths:
10
+ - lib
11
+ email: jblondinet@nospam@yahoo.com
12
+ homepage: http://xrvg.rubyforge.org/
13
+ rubyforge_project: xrvg
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - "Julien L\xE9onard"
31
+ files:
32
+ - ./examples/foreach.rb
33
+ - ./examples/hellocrown.rb
34
+ - ./examples/hellocrown2.rb
35
+ - ./examples/hellocrownrecurse.rb
36
+ - ./examples/helloworld.rb
37
+ - ./examples/helloworldcompact.rb
38
+ - ./examples/helloworldexpanded.rb
39
+ - ./examples/palette_circle.rb
40
+ - ./examples/sample.rb
41
+ - ./examples/uplets.rb
42
+ - lib/assertion.rb
43
+ - lib/attributable.rb
44
+ - lib/color.rb
45
+ - lib/frame.rb
46
+ - lib/geometry2D.rb
47
+ - lib/interpolation.rb
48
+ - lib/render.rb
49
+ - lib/samplation.rb
50
+ - lib/shape.rb
51
+ - lib/style.rb
52
+ - lib/trace.rb
53
+ - lib/utils.rb
54
+ - lib/xrvg.rb
55
+ - Rakefile
56
+ - LICENCE
57
+ - README
58
+ test_files:
59
+ - test/test_attributable.rb
60
+ - test/test_color.rb
61
+ - test/test_frame.rb
62
+ - test/test_geometry2D.rb
63
+ - test/test_render.rb
64
+ - test/test_style.rb
65
+ - test/test_utils.rb
66
+ rdoc_options:
67
+ - --title
68
+ - XRVG API documentation
69
+ - --main
70
+ - README
71
+ extra_rdoc_files:
72
+ - README
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ requirements: []
78
+
79
+ dependencies: []
80
+