xrvg 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +21 -0
- data/README +3 -3
- data/Rakefile +4 -4
- data/examples/bezierbasic.rb +1 -0
- data/examples/bezierbasicvector.rb +1 -0
- data/examples/foreach.rb +1 -0
- data/examples/geodash.rb +1 -0
- data/examples/geodash2.rb +1 -0
- data/examples/hellocrown.rb +1 -0
- data/examples/hellocrown2.rb +1 -0
- data/examples/hellocrownrecurse.rb +1 -0
- data/examples/helloworldcompact.rb +1 -0
- data/examples/helloworldexpanded.rb +1 -0
- data/examples/multibezierbasic.rb +1 -0
- data/examples/palette_circle.rb +1 -0
- data/examples/randomdash.rb +1 -0
- data/examples/range_examples.rb +1 -0
- data/examples/range_examples2.rb +1 -0
- data/examples/sample.rb +1 -0
- data/examples/simpledash.rb +1 -0
- data/examples/uplets.rb +1 -0
- data/lib/bezier.rb +21 -55
- data/lib/bezierbuilders.rb +194 -0
- data/lib/beziermotifs.rb +114 -0
- data/lib/bezierspline.rb +20 -75
- data/lib/beziertools.rb +211 -0
- data/lib/color.rb +26 -7
- data/lib/fitting.rb +203 -0
- data/lib/frame.rb +2 -1
- data/lib/geometry2D.rb +6 -5
- data/lib/interbezier.rb +87 -0
- data/lib/interpolation.rb +6 -5
- data/lib/parametriclength.rb +87 -0
- data/lib/render.rb +4 -9
- data/lib/samplation.rb +71 -82
- data/lib/shape.rb +47 -25
- data/lib/style.rb +2 -1
- data/lib/trace.rb +2 -0
- data/lib/utils.rb +111 -17
- data/lib/xrvg.rb +16 -6
- data/test/test_attributable.rb +34 -2
- data/test/test_bezier.rb +93 -2
- data/test/test_bezierbuilders.rb +92 -0
- data/test/test_beziertools.rb +97 -0
- data/test/test_color.rb +65 -24
- data/test/test_fitting.rb +47 -0
- data/test/test_frame.rb +7 -2
- data/test/test_geometry2D.rb +26 -7
- data/test/test_interbezier.rb +29 -0
- data/test/test_interpolation.rb +16 -1
- data/test/test_parametric_length.rb +15 -0
- data/test/test_render.rb +54 -6
- data/test/test_shape.rb +103 -10
- data/test/test_trace.rb +13 -0
- data/test/test_utils.rb +114 -12
- data/test/test_xrvg.rb +3 -0
- metadata +16 -5
- data/lib/assertion.rb +0 -14
- data/lib/attributable.rb +0 -152
data/test/test_interpolation.rb
CHANGED
@@ -5,8 +5,23 @@ class InterpolatorTest < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def test_quadtree
|
7
7
|
quad = QuadTree.new( [0.0,1.0, 0.2,0.0, 0.6,1.0, 0.8,0.0, 1.0,1.0] )
|
8
|
-
assert_equal( [0.2,0.0,0.6,1.0], quad.range( 0.5 ) )
|
8
|
+
assert_equal( [0.2,0.0, 0.6,1.0], quad.range( 0.5 ) )
|
9
9
|
assert_equal( [0.0,1.0, 0.2,0.0], quad.range( 0.0 ) )
|
10
10
|
assert_equal( [0.8,0.0, 1.0,1.0], quad.range( 1.0 ) )
|
11
|
+
assert_equal( [0.8,0.0, 1.0,1.0], quad.range( 1.1 ) )
|
11
12
|
end
|
13
|
+
|
14
|
+
def test_interpolator
|
15
|
+
interpolator = Interpolator[ :samplelist, [0.0,0.0, 1.0,2.0]]
|
16
|
+
assert_equal( 1.0, interpolator.interpolate( 0.5 ) )
|
17
|
+
assert_equal( 2.0, interpolator.interpolate( 2.5 ) )
|
18
|
+
end
|
19
|
+
|
20
|
+
class A
|
21
|
+
include Interpolation
|
22
|
+
end
|
23
|
+
def test_interpolation
|
24
|
+
assert_raise(NotImplementedError) {A[].samplelist}
|
25
|
+
end
|
26
|
+
|
12
27
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'bezier'
|
3
|
+
|
4
|
+
class ParametricLengthTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class A
|
7
|
+
include ParametricLength
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_holes
|
11
|
+
assert_raise(NotImplementedError) {A[].parameter_range}
|
12
|
+
assert_raise(NotImplementedError) {A[].pointfromparameter( 0.0, V2D[] )}
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/test/test_render.rb
CHANGED
@@ -3,16 +3,64 @@ require 'render'
|
|
3
3
|
|
4
4
|
class SVGRenderTest < Test::Unit::TestCase
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
def test_raster
|
9
|
-
if nil
|
6
|
+
def test_render
|
10
7
|
require 'shape'
|
11
|
-
|
8
|
+
if File.exist?( "svgrender.svg" )
|
9
|
+
File.delete( "svgrender.svg" )
|
10
|
+
end
|
11
|
+
render = SVGRender.new( :filename, "svgrender.svg" )
|
12
12
|
render.add( Circle[] )
|
13
13
|
render.end
|
14
|
-
assert( File.exist?( "svgrender.
|
14
|
+
assert( File.exist?( "svgrender.svg" ) )
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_render2
|
18
|
+
require 'shape'
|
19
|
+
if File.exist?( "svgrender.svg" )
|
20
|
+
File.delete( "svgrender.svg" )
|
21
|
+
end
|
22
|
+
SVGRender.[](:filename, "svgrender.svg") do |render|
|
23
|
+
render.add( Circle[] )
|
24
|
+
render.add( Circle[:center, V2D[1.0,1.0]] )
|
25
|
+
render.add( Circle[:center, V2D[-1.0,-1.0]] )
|
26
|
+
|
27
|
+
end
|
28
|
+
assert( File.exist?( "svgrender.svg" ) )
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_render3
|
32
|
+
require 'shape'
|
33
|
+
if File.exist?( "svgrender.svg" )
|
34
|
+
File.delete( "svgrender.svg" )
|
35
|
+
end
|
36
|
+
SVGRender.[](:filename, "svgrender.svg") do |render|
|
37
|
+
render.add( Circle[:radius, 0.0] )
|
38
|
+
end
|
39
|
+
assert( File.exist?( "svgrender.svg" ) )
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_render4
|
43
|
+
require 'shape'
|
44
|
+
if File.exist?( "svgrender.svg" )
|
45
|
+
File.delete( "svgrender.svg" )
|
46
|
+
end
|
47
|
+
circle = Circle.new
|
48
|
+
gradient = CircularGradient.new( :colorlist, [0.0, Color.black(1.0), 1.0, Color.black(0.0)], :circle, circle )
|
49
|
+
render = SVGRender.new( :filename, "svgrender.svg" )
|
50
|
+
render.add( Circle[], Style[ :fill, gradient, :stroke, gradient, :strokewidth, 0.01 ] )
|
51
|
+
render.end
|
52
|
+
assert( File.exist?( "svgrender.svg" ) )
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_layer
|
56
|
+
if File.exist?( "svgrender.svg" )
|
57
|
+
File.delete( "svgrender.svg" )
|
15
58
|
end
|
59
|
+
render = SVGRender.new( :filename, "svgrender.svg" )
|
60
|
+
render.layers = [:stars, :disk, :dustback, :halo, :dustforeground]
|
61
|
+
render.add( Circle[], nil, :stars )
|
62
|
+
render.end
|
63
|
+
assert( File.exist?( "svgrender.svg" ) )
|
16
64
|
end
|
17
65
|
|
18
66
|
end
|
data/test/test_shape.rb
CHANGED
@@ -4,29 +4,95 @@ require 'test/unit'
|
|
4
4
|
class ShapeTest < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def test_abstract
|
7
|
-
|
7
|
+
assert_raise(NotImplementedError){Shape[].contour}
|
8
|
+
assert_raise(NotImplementedError){Shape[].svg}
|
9
|
+
assert_raise(NotImplementedError){Shape[].viewbox}
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_default_style
|
13
|
+
assert_equal( Color.black, Shape[].default_style.fill )
|
8
14
|
end
|
9
15
|
|
10
16
|
end
|
11
17
|
|
18
|
+
class CurveTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
def test_abstract
|
21
|
+
assert_raise(NotImplementedError){Curve[].contour}
|
22
|
+
assert_raise(NotImplementedError){Curve[].svg}
|
23
|
+
assert_raise(NotImplementedError){Curve[].point(0.0)}
|
24
|
+
assert_raise(NotImplementedError){Curve[].tangent(0.0)}
|
25
|
+
assert_raise(NotImplementedError){Curve[].acc(0.0)}
|
26
|
+
assert_raise(NotImplementedError){Curve[].length(0.0)}
|
27
|
+
assert_raise(NotImplementedError){Curve[].rotation(0.0)}
|
28
|
+
assert_raise(NotImplementedError){Curve[].scale(0.0)}
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_default_style
|
32
|
+
assert_equal( Color.black, Shape[].default_style.fill )
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
12
36
|
|
13
|
-
class LineTest < Test::Unit::TestCase
|
14
37
|
|
38
|
+
class LineTest < Test::Unit::TestCase
|
39
|
+
@@line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0] ] ]
|
40
|
+
|
15
41
|
def test_point
|
16
|
-
|
17
|
-
|
18
|
-
|
42
|
+
assert_equal( V2D[0.0, 0.3], @@line.point( 0.3 ) )
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_points
|
46
|
+
assert_equal( [V2D[0.0, 0.3], V2D[0.0, 0.7]] , @@line.points( [0.3,0.7] ) )
|
19
47
|
end
|
20
48
|
|
21
49
|
def test_tangent
|
22
|
-
|
23
|
-
|
50
|
+
assert_equal( V2D[0.0, 1.0], @@line.tangent( 0.3 ) )
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_tangents
|
54
|
+
assert_equal( [V2D[0.0, 1.0],V2D[0.0, 1.0]], @@line.tangents( [0.3,0.7] ) )
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_acc
|
58
|
+
assert_equal( V2D[0.0, 0.0], @@line.acc( 0.3 ) )
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_normal
|
62
|
+
assert_equal( V2D[-1.0, 0.0], @@line.normal( 0.3 ) )
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_normals
|
66
|
+
assert_equal( [V2D[-1.0, 0.0],V2D[-1.0, 0.0]], @@line.normals( [0.3,0.7] ) )
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_acc_normal
|
70
|
+
assert_equal( 0.0, @@line.acc_normal( 0.3 ) )
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_curvature
|
74
|
+
assert_equal( 0.0, @@line.curvature( 0.3 ) )
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_surface
|
78
|
+
assert_equal( 0.0, @@line.surface )
|
79
|
+
assert_equal( 1.0, Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 1.0, 1.0] ] ].surface )
|
24
80
|
end
|
25
81
|
|
26
82
|
def test_frame
|
27
|
-
|
28
|
-
result
|
29
|
-
|
83
|
+
result = Frame[ :center, V2D[0.0,0.5], :vector, V2D[0.0,1.0], :rotation, 0.0, :scale, 1.0 ]
|
84
|
+
assert_equal( result, @@line.frame( 0.5 ) )
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_frames
|
88
|
+
result = [Frame[ :center, V2D[0.0,0.5], :vector, V2D[0.0,1.0], :rotation, 0.0, :scale, 1.0 ],
|
89
|
+
Frame[ :center, V2D[0.0,0.7], :vector, V2D[0.0,1.0], :rotation, 0.0, :scale, 1.0 ]]
|
90
|
+
assert_equal( result, @@line.frames( [0.5, 0.7] ) )
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_framev
|
94
|
+
result = [ V2D[0.0,0.5], V2D[0.0,1.0] ]
|
95
|
+
assert_equal( result, @@line.framev( 0.5 ) )
|
30
96
|
end
|
31
97
|
|
32
98
|
|
@@ -40,6 +106,24 @@ class LineTest < Test::Unit::TestCase
|
|
40
106
|
assert( V2D.vequal?( v1, v2 ) )
|
41
107
|
end
|
42
108
|
end
|
109
|
+
|
110
|
+
def test_length
|
111
|
+
line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0], V2D[ 1.0, 1.0] ] ]
|
112
|
+
assert_equal( 2.0, line.length )
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_translate
|
116
|
+
line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0], V2D[ 1.0, 1.0] ] ].translate( V2D[1.0,2.0] )
|
117
|
+
assert_equal( V2D[ 1.0, 2.0], line.point( 0.0 ) )
|
118
|
+
assert_equal( V2D[ 2.0, 3.0], line.point( 2.0 ) )
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_reverse
|
122
|
+
line = Line[ :points, [ V2D[ 0.0, 0.0], V2D[ 0.0, 1.0], V2D[ 1.0, 1.0] ] ].reverse
|
123
|
+
assert_equal( V2D[ 1.0, 1.0], line.point( 0.0 ) )
|
124
|
+
assert_equal( V2D[ 0.0, 0.0], line.point( 2.0 ) )
|
125
|
+
end
|
126
|
+
|
43
127
|
end
|
44
128
|
|
45
129
|
class CircleTest < Test::Unit::TestCase
|
@@ -65,6 +149,11 @@ class CircleTest < Test::Unit::TestCase
|
|
65
149
|
end
|
66
150
|
end
|
67
151
|
|
152
|
+
def test_curvature
|
153
|
+
assert( 1.0.fequal?( Circle[].curvature( 0.0 ) ) )
|
154
|
+
assert( Circle[].curvature( Range.O.rand ).fequal?( Circle[].curvature( Range.O.rand ) ) )
|
155
|
+
end
|
156
|
+
|
68
157
|
def test_diameter
|
69
158
|
cd = Circle.diameter( V2D[0.0,1.0], V2D[0.0,-1.0] )
|
70
159
|
c2 = Circle[ :center, V2D::O, :radius, 1.0 ]
|
@@ -72,4 +161,8 @@ class CircleTest < Test::Unit::TestCase
|
|
72
161
|
assert_equal( cd.radius, c2.radius )
|
73
162
|
assert( V2D.vequal?( V2D[0.0,1.0], cd.point( 0.0 ) ) )
|
74
163
|
end
|
164
|
+
|
165
|
+
def test_rotate
|
166
|
+
assert( V2D.vequal?( V2D[0.0,1.0], Circle[].rotate(Math::PI/2.0).point( 0.0 ) ) )
|
167
|
+
end
|
75
168
|
end
|
data/test/test_trace.rb
ADDED
data/test/test_utils.rb
CHANGED
@@ -17,17 +17,8 @@ class IntegerTest < Test::Unit::TestCase
|
|
17
17
|
|
18
18
|
def test_randsplit1!
|
19
19
|
result = 3.randsplit!
|
20
|
-
puts "result #{result.join(" ")}"
|
21
20
|
assert_equal( 1.0, result[0] + result[1] + result[2] )
|
22
|
-
|
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
|
21
|
+
assert_equal( [], 3.randsplit!( 4.0 ) )
|
31
22
|
end
|
32
23
|
|
33
24
|
def test_randsplitsum!
|
@@ -67,7 +58,6 @@ class ArrayTest < Test::Unit::TestCase
|
|
67
58
|
[(0.0..1.0), (1.0..0.0)].samples(3) {|v1,v2| result += [v1,v2] }
|
68
59
|
assert_equal( [0.0, 1.0, 0.5, 0.5, 1.0, 0.0], result )
|
69
60
|
end
|
70
|
-
|
71
61
|
|
72
62
|
def test_pairs
|
73
63
|
a = [ 1, 2, 3]
|
@@ -83,9 +73,13 @@ class ArrayTest < Test::Unit::TestCase
|
|
83
73
|
|
84
74
|
|
85
75
|
def test_foreach
|
86
|
-
b =
|
76
|
+
b = []
|
87
77
|
[1, 2, 3, 4].foreach {|i, j| b.push( [j,i] )}
|
88
78
|
assert_equal( [[2, 1], [4, 3]], b)
|
79
|
+
|
80
|
+
b = []
|
81
|
+
[1, 2, 3, 4].foreach {|i| b << i}
|
82
|
+
assert_equal( [1, 2, 3, 4], b)
|
89
83
|
end
|
90
84
|
|
91
85
|
def test_slice
|
@@ -104,6 +98,10 @@ class ArrayTest < Test::Unit::TestCase
|
|
104
98
|
assert_equal( [[1, 2], [2, 3]], result )
|
105
99
|
end
|
106
100
|
|
101
|
+
def test_triplets
|
102
|
+
assert_equal( [[1, 2, 3], [2, 3, 4]], [1, 2, 3, 4].triplets )
|
103
|
+
end
|
104
|
+
|
107
105
|
def test_assignment
|
108
106
|
a, b, c = [1, 2, 3]
|
109
107
|
assert_equal( a, 1 )
|
@@ -132,13 +130,30 @@ class ArrayTest < Test::Unit::TestCase
|
|
132
130
|
def test_forpattern
|
133
131
|
assert_equal( [1,2,"a",3,4,"b"], [ [1,2,3,4], ["a","b"] ].forpattern( [0,0,1] ) )
|
134
132
|
assert_equal( [1,"a",2,3,"b",4], [ [1,2,3,4], ["a","b"] ].forpattern( [0,1,0] ) )
|
133
|
+
result = []
|
134
|
+
[ [1,2,3,4], ["a","b"] ].forpattern( [0,1,0] ) do |v1, v2, v3|
|
135
|
+
result += [v1,v2,v3]
|
136
|
+
end
|
137
|
+
assert_equal( [1,"a",2,3,"b",4], result )
|
135
138
|
end
|
136
139
|
|
137
140
|
def test_sub
|
138
141
|
assert_equal( [1,3,5], [1,2,3,4,5].sub(2) )
|
139
142
|
assert_equal( [1,3,5], [1,2,3,4,5].half )
|
143
|
+
result = []
|
144
|
+
[1,2,3,4,5].sub(2) {|v| result << v}
|
145
|
+
assert_equal( [1,3,5], result )
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_mean
|
149
|
+
assert_equal( 3, [1,3,5].mean )
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_range
|
153
|
+
assert_equal( (1.0..5.0), [5.0,3.0,1.0].range )
|
140
154
|
end
|
141
155
|
|
156
|
+
|
142
157
|
end
|
143
158
|
|
144
159
|
class FloatTest < Test::Unit::TestCase
|
@@ -158,22 +173,51 @@ class FloatTest < Test::Unit::TestCase
|
|
158
173
|
assert_equal( 0.25, r[0] + r[1] )
|
159
174
|
end
|
160
175
|
|
176
|
+
def test_float_include
|
177
|
+
assert( Float.floatlist_include?( [1.0,2.0,3.0001,4.0], 3.0, 0.001 ) )
|
178
|
+
assert_equal( false, Float.floatlist_include?( [1.0,2.0,3.0001,4.0], 3.0, 0.0001 ) )
|
179
|
+
end
|
180
|
+
|
161
181
|
end
|
162
182
|
|
163
183
|
class RangeTest < Test::Unit::TestCase
|
164
184
|
|
165
185
|
def test_samples
|
166
186
|
assert_equal( [0.0, 0.5, 1.0], (0.0..1.0).samples(3))
|
187
|
+
assert_equal( [1.0], (1.0..2.0).samples(1))
|
167
188
|
end
|
168
189
|
|
169
190
|
def test_samples2
|
170
191
|
# assert_equal( [0.0, 0.667128916301921, 0.889196841637666], (0.0..1.0).geo(2.2).samples(3))
|
171
192
|
end
|
172
193
|
|
194
|
+
def test_samples3
|
195
|
+
assert_not_equal( [0.0, 1.0], (0.0..1.0).ssort.random.samples(2))
|
196
|
+
end
|
197
|
+
|
198
|
+
|
199
|
+
def test_samplesblock
|
200
|
+
result = []
|
201
|
+
(0.0..1.0).samples(3) do |v|
|
202
|
+
result << v
|
203
|
+
end
|
204
|
+
assert_equal( [0.0, 0.5, 1.0], result)
|
205
|
+
end
|
206
|
+
|
207
|
+
|
173
208
|
def test_split
|
174
209
|
assert_equal( [(0.0..0.5), (0.5..1.0)], (0.0..1.0).splits(2) )
|
175
210
|
end
|
176
211
|
|
212
|
+
def test_splitblock
|
213
|
+
result = []
|
214
|
+
(0.0..1.0).splits(2) do |subrange|
|
215
|
+
result << subrange
|
216
|
+
end
|
217
|
+
assert_equal( [(0.0..0.5), (0.5..1.0)], result )
|
218
|
+
end
|
219
|
+
|
220
|
+
|
177
221
|
def test_split2
|
178
222
|
# assert_equal( [(0.0..0.75), (0.75..1.0)], (0.0..1.0).geo(3.0).splits(2) )
|
179
223
|
end
|
@@ -199,6 +243,7 @@ class RangeTest < Test::Unit::TestCase
|
|
199
243
|
assert_equal( 2, (1.0..2.0).rand( 2 ).length )
|
200
244
|
assert_equal( 1.8, (1.0..2.0).complement(1.2) )
|
201
245
|
assert_equal( 0.5, (1.0..2.0).abscissa(1.5) )
|
246
|
+
assert_equal( 1.0, (1.0..1.0).abscissa(1.5) )
|
202
247
|
|
203
248
|
# Splittable module
|
204
249
|
assert_equal( (1.2..1.3), (1.0..2.0).split(0.2,0.3) )
|
@@ -215,6 +260,15 @@ class RangeTest < Test::Unit::TestCase
|
|
215
260
|
assert_equal( (1.3..2.3), (1.0..2.0).translate(0.3) )
|
216
261
|
end
|
217
262
|
|
263
|
+
def test_range_sym
|
264
|
+
assert_equal( (-0.3..0.3), Range.sym( 0.3 ) )
|
265
|
+
assert_equal( (-0.5..0.5), Range.sym( -0.5 ) )
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_resize
|
269
|
+
assert_equal( (-0.5..1.5), Range.O.resize( 2.0 ) )
|
270
|
+
end
|
271
|
+
|
218
272
|
end
|
219
273
|
|
220
274
|
class SampleClass
|
@@ -235,6 +289,21 @@ class SampleTest < Test::Unit::TestCase
|
|
235
289
|
assert_equal( [0.0, 1.0, 2.0], (0.0..2.0).samples(3))
|
236
290
|
end
|
237
291
|
|
292
|
+
def test_samples2
|
293
|
+
assert_equal( [0.0, 1.0, 2.0], (0.0..2.0).samples([0.0,0.5,1.0]))
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_hash
|
297
|
+
assert_raise(RuntimeError) {Range.O.apply( [0.0], :toto )}
|
298
|
+
end
|
299
|
+
|
300
|
+
def test_limit
|
301
|
+
assert_equal( [], Range.O.samples(0) )
|
302
|
+
result = []
|
303
|
+
Range.O.samples(0) {|v| result << v}
|
304
|
+
assert_equal( [], result )
|
305
|
+
end
|
306
|
+
|
238
307
|
def test_array_samples
|
239
308
|
# TODO
|
240
309
|
# assert_equal( [0.0, 0.0, 0.864664716763387, 1.72932943352677], [(0.0..1.0),(0.0..2.0)].geo(2.0).samples(3))
|
@@ -247,6 +316,39 @@ class SampleTest < Test::Unit::TestCase
|
|
247
316
|
|
248
317
|
def test_roller
|
249
318
|
assert_equal( ["a", "b", "a"], Roller["a","b"].samples(3))
|
319
|
+
|
320
|
+
rand = Roller["a","b"].rand
|
321
|
+
assert( ["a","b"].include?( rand ) )
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_random_split
|
325
|
+
splits = Range.O.random.splits( 2 )
|
326
|
+
assert_equal( 0.0, splits[0].begin )
|
327
|
+
assert_equal( 1.0, splits[1].end )
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_geo
|
331
|
+
assert_equal( 1.0, (0.0..1.0).geo(100.0).sample( 1.0 ) )
|
332
|
+
end
|
333
|
+
|
334
|
+
def test_alternate
|
335
|
+
assert_equal( [1.0,1.5], (1.0..0.0).alternate.samples( [0.0,0.5] ) )
|
336
|
+
assert_equal( [0.0,-0.5], AlternateFilter[(0.0..1.0)].samples( [0.0,0.5] ) )
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_split_errors
|
340
|
+
assert_raise(RuntimeError){Range.O.random.splits( 0 )}
|
341
|
+
assert_raise(RuntimeError){Range.O.random.splits( [0.0] )}
|
342
|
+
assert_equal( [(0.0..1.0)], (0.0..1.0).splits(1) )
|
343
|
+
end
|
344
|
+
|
345
|
+
def test_multisamples
|
346
|
+
assert_equal( [0.0, 0.1875, 0.3125, 0.5, 0.625, 0.8125, 0.9375], (0.0..1.0).multisamples( [4, 2], [3.0, 1.0] ) )
|
347
|
+
end
|
348
|
+
|
349
|
+
def test_randomgauss
|
350
|
+
(0.0..1.0).randgauss
|
250
351
|
end
|
251
352
|
|
252
353
|
end
|
354
|
+
|