rdl 1.1.0 → 1.1.1.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGES.md +25 -0
  4. data/README.md +104 -64
  5. data/extras/type_tests/%.rb +171 -0
  6. data/extras/type_tests/&.rb +159 -0
  7. data/extras/type_tests/**.rb +222 -0
  8. data/extras/type_tests/*.rb +177 -0
  9. data/extras/type_tests/+.rb +170 -0
  10. data/extras/type_tests/-.rb +171 -0
  11. data/extras/type_tests/1scomp.rb +157 -0
  12. data/extras/type_tests/<.rb +170 -0
  13. data/extras/type_tests/<<.rb +159 -0
  14. data/extras/type_tests/>>.rb +159 -0
  15. data/extras/type_tests/[].rb +163 -0
  16. data/extras/type_tests/^.rb +159 -0
  17. data/extras/type_tests/abs.rb +155 -0
  18. data/extras/type_tests/abs2.rb +164 -0
  19. data/extras/type_tests/angle.rb +157 -0
  20. data/extras/type_tests/arg.rb +157 -0
  21. data/extras/type_tests/bit_length.rb +157 -0
  22. data/extras/type_tests/ceil.rb +157 -0
  23. data/extras/type_tests/ceilRational.rb +160 -0
  24. data/extras/type_tests/conj.rb +158 -0
  25. data/extras/type_tests/defwhere.rb +86 -0
  26. data/extras/type_tests/denominator.rb +157 -0
  27. data/extras/type_tests/div.rb +172 -0
  28. data/extras/type_tests/divslash.rb +179 -0
  29. data/extras/type_tests/even?.rb +157 -0
  30. data/extras/type_tests/fdiv.rb +244 -0
  31. data/extras/type_tests/finite?.rb +157 -0
  32. data/extras/type_tests/floor.rb +157 -0
  33. data/extras/type_tests/floorRational.rb +161 -0
  34. data/extras/type_tests/hash.rb +157 -0
  35. data/extras/type_tests/imag.rb +158 -0
  36. data/extras/type_tests/infinite?.rb +157 -0
  37. data/extras/type_tests/modulo.rb +171 -0
  38. data/extras/type_tests/nan?.rb +157 -0
  39. data/extras/type_tests/neg.rb +155 -0
  40. data/extras/type_tests/next.rb +157 -0
  41. data/extras/type_tests/next_float.rb +157 -0
  42. data/extras/type_tests/numerator.rb +157 -0
  43. data/extras/type_tests/phase.rb +157 -0
  44. data/extras/type_tests/prev_float.rb +157 -0
  45. data/extras/type_tests/quo.rb +179 -0
  46. data/extras/type_tests/rationalize.rb +157 -0
  47. data/extras/type_tests/rationalizeArg.rb +198 -0
  48. data/extras/type_tests/real.rb +157 -0
  49. data/extras/type_tests/real?.rb +157 -0
  50. data/extras/type_tests/round.rb +157 -0
  51. data/extras/type_tests/roundArg.rb +169 -0
  52. data/extras/type_tests/size.rb +157 -0
  53. data/extras/type_tests/to_c.rb +157 -0
  54. data/extras/type_tests/to_f.rb +155 -0
  55. data/extras/type_tests/to_i.rb +157 -0
  56. data/extras/type_tests/to_r.rb +157 -0
  57. data/extras/type_tests/to_s.rb +157 -0
  58. data/extras/type_tests/truncate.rb +157 -0
  59. data/extras/type_tests/truncateArg.rb +166 -0
  60. data/extras/type_tests/type tests +1 -0
  61. data/extras/type_tests/zero?.rb +155 -0
  62. data/extras/type_tests/|.rb +159 -0
  63. data/lib/rdl/contracts/and.rb +1 -1
  64. data/lib/rdl/contracts/flat.rb +2 -2
  65. data/lib/rdl/contracts/proc.rb +2 -1
  66. data/lib/rdl/types/.#lexer.rex +1 -0
  67. data/lib/rdl/types/dependent_arg.rb +47 -0
  68. data/lib/rdl/types/finitehash.rb +5 -5
  69. data/lib/rdl/types/generic.rb +3 -3
  70. data/lib/rdl/types/lexer.rex +5 -2
  71. data/lib/rdl/types/lexer.rex.rb +3 -0
  72. data/lib/rdl/types/method.rb +144 -15
  73. data/lib/rdl/types/nominal.rb +1 -1
  74. data/lib/rdl/types/parser.racc +6 -1
  75. data/lib/rdl/types/parser.tab.rb +272 -245
  76. data/lib/rdl/types/tuple.rb +1 -1
  77. data/lib/rdl/types/type_inferencer.rb +7 -7
  78. data/lib/rdl/wrap.rb +16 -11
  79. data/rdl.gemspec +3 -3
  80. data/test/test_dsl.rb +4 -5
  81. data/test/test_le.rb +5 -5
  82. data/test/test_lib_types.rb +34 -34
  83. data/test/test_member.rb +3 -3
  84. data/test/test_type_contract.rb +63 -1
  85. data/test/test_types.rb +2 -0
  86. data/types/ruby-2.x/_aliases.rb +2 -2
  87. data/types/ruby-2.x/bigdecimal.rb +246 -12
  88. data/types/ruby-2.x/bignum.rb +253 -0
  89. data/types/ruby-2.x/complex.rb +111 -22
  90. data/types/ruby-2.x/fixnum.rb +238 -31
  91. data/types/ruby-2.x/float.rb +217 -35
  92. data/types/ruby-2.x/integer.rb +17 -16
  93. data/types/ruby-2.x/numeric.rb +31 -21
  94. data/types/ruby-2.x/rational.rb +196 -18
  95. metadata +67 -4
@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bigdecimal'
4
+ require 'rdl'
5
+ require 'rdl_types'
6
+
7
+ MAX_FIXNUM = 2**(0.size*8-2)-1 #Largest fixnum. -2 since 1 bit used for sign, 1 bit used as int marker.
8
+ MIN_FIXNUM = -(2**(0.size*8-2)) #Smallest fixnum.
9
+
10
+ def test()
11
+ x = gen_number(0.2,0.2,0.2,0.05,0.05,0.2,0,0.1)
12
+ type_one = x.class.to_s
13
+ if type_one=="BigDecimal"
14
+ y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
15
+ type_two = y.class.to_s
16
+ elsif type_one=="Rational"
17
+ y = gen_number(0.2,0.2,0.2,0.1,0,0.2,0,0.1)
18
+ type_two = y.class.to_s
19
+ elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
20
+ y = gen_number(0.2,0.2,0,0.1,0.1,0.3,0,0.1)
21
+ type_two = y.class.to_s
22
+ else
23
+ y = gen_number(0.2,0.2,0.2,0.05,0.05,0.2,0,0.1)
24
+ type_two = y.class.to_s
25
+ end
26
+ #puts "Arg1= #{x} and type = #{type_one}"
27
+ #puts "Arg2= #{y} and type = #{type_two}"
28
+ operation_type = query(type_one+'#%',y)
29
+ expected_type = operation_type[operation_type.index('->')+3..-1]
30
+ w = x%y
31
+ #puts "here"
32
+ test_result = w.is_a?(Object.const_get(expected_type))
33
+ if !test_result
34
+ puts "Arg1= #{x} (type: #{type_one})"
35
+ puts "Arg2= #{y} (type: #{type_two})"
36
+ puts "Res= #{w}"
37
+ puts "Expected type: #{expected_type}"
38
+ puts "Received type: #{w.class}"
39
+ end
40
+ #puts test_result
41
+ return test_result
42
+ end
43
+
44
+ def gen_fixnum()
45
+ return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
46
+ end
47
+
48
+ def gen_bignum()
49
+ r = Random.rand()
50
+ if r<0.5
51
+ return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
52
+ else
53
+ return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
54
+ end
55
+ end
56
+
57
+ def gen_float()
58
+ r = Random.rand()
59
+ if r<0.5
60
+ return Float::MAX*Random.rand
61
+ else
62
+ return -1*Float::MAX*Random.rand
63
+ end
64
+ end
65
+
66
+ def gen_bigdec()
67
+ r = Random.rand()
68
+ if r<0.33
69
+ return BigDecimal.new(gen_fixnum())
70
+ elsif r<0.66
71
+ return BigDecimal.new(gen_bignum())
72
+ else
73
+ return BigDecimal.new(gen_float(),0)
74
+ end
75
+ end
76
+
77
+ def gen_complex()
78
+ x = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
79
+ #puts x
80
+ y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
81
+ #puts y
82
+ return Complex(x,y)
83
+ end
84
+
85
+ def gen_rational()
86
+ x = gen_fixnum()
87
+ y = gen_fixnum()
88
+ return Rational(x,y)
89
+ end
90
+
91
+
92
+ def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
93
+ r = Random.rand()
94
+ if r<probFixnum then
95
+ #Fixnum type
96
+ x = gen_fixnum()
97
+ elsif r<(probFixnum+probBignum)
98
+ x = gen_bignum()
99
+ elsif r<(probFixnum+probBignum+probBigDec)
100
+ #BigDecimal type
101
+ x = gen_bigdec()
102
+ elsif r<(probFixnum+probBignum+probBigDec+probInf)
103
+ x=Float::INFINITY
104
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
105
+ x=Float::NAN
106
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
107
+ #Random Float type
108
+ x = gen_float()
109
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
110
+ x= gen_complex()
111
+ elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
112
+ x = gen_rational()
113
+ end
114
+ return x
115
+ end
116
+
117
+ def rounds(x)
118
+ counter = 0
119
+ for i in 0..x
120
+ b= test()
121
+ if (!b) then
122
+ counter=counter+1
123
+ end
124
+
125
+ end
126
+ return counter
127
+ end
128
+
129
+
130
+ def query(q,y)
131
+ $__rdl_contract_switch.off {
132
+ if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
133
+ klass = nil
134
+ klass_pref = nil
135
+ meth = nil
136
+ if q =~ /(.+)#(.+)/
137
+ klass = $1
138
+ klass_pref = "#{klass}#"
139
+ meth = $2.to_sym
140
+ elsif q =~ /(.+)\.(.+)/
141
+ klass_pref = "#{$1}."
142
+ klass = RDL::Util.add_singleton_marker($1)
143
+ meth = $2.to_sym
144
+ else
145
+ klass = self.class.to_s
146
+ klass_pref = "#{klass}#"
147
+ meth = q.to_sym
148
+ end
149
+ if RDL::Wrap.has_contracts?(klass, meth, :type)
150
+ typs = RDL::Wrap.get_contracts(klass, meth, :type)
151
+ typs.each { |t|
152
+ #puts "#{klass_pref}#{meth}: #{t}"
153
+ t_string = "#{t}"
154
+ t_string =~ /\((\w*)\)(.+)/
155
+
156
+ #puts y
157
+ if y.is_a?(Object.const_get($1))
158
+ return t_string
159
+ end
160
+ #return "#{t}"
161
+ }
162
+ nil
163
+ else
164
+ #puts "No type for #{klass_pref}#{meth}"
165
+ end
166
+ else
167
+ #puts "Not implemented"
168
+ end
169
+ }
170
+ end
171
+
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bigdecimal'
4
+ require 'rdl'
5
+ require 'rdl_types'
6
+
7
+ MAX_FIXNUM = 2**(0.size*8-2)-1 #Largest fixnum. -2 since 1 bit used for sign, 1 bit used as int marker.
8
+ MIN_FIXNUM = -(2**(0.size*8-2)) #Smallest fixnum.
9
+
10
+ def test()
11
+ x = gen_number(0.5,0.5,0,0,0,0,0,0)
12
+ type_one = x.class.to_s
13
+ y = gen_number(0.5,0.5,0,0,0,0,0,0)
14
+ type_two = y.class.to_s
15
+ #puts "Arg1= #{x} and type = #{type_one}"
16
+ #puts "Arg2= #{y} and type = #{type_two}"
17
+ operation_type = query(type_one+'#&',y)
18
+ expected_type = operation_type[operation_type.index('->')+3..-1]
19
+ w = x&y
20
+ test_result = w.is_a?(Object.const_get(expected_type))
21
+ if !test_result
22
+ puts "Arg1= #{x}"
23
+ puts "Arg2= #{y}"
24
+ puts "Res= #{w}"
25
+ puts "Expected type: #{expected_type}"
26
+ puts "Received type: #{w.class}"
27
+ end
28
+ #puts test_result
29
+ return test_result
30
+ end
31
+
32
+ def gen_fixnum()
33
+ return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
34
+ end
35
+
36
+ def gen_bignum()
37
+ r = Random.rand()
38
+ if r<0.5
39
+ return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
40
+ else
41
+ return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
42
+ end
43
+ end
44
+
45
+ def gen_float()
46
+ r = Random.rand()
47
+ if r<0.5
48
+ return (2**32)*Random.rand
49
+ else
50
+ return -1*(2**32)*Random.rand
51
+ end
52
+ end
53
+
54
+ def gen_bigdec()
55
+ r = Random.rand()
56
+ if r<0.33
57
+ return BigDecimal.new(gen_fixnum())
58
+ elsif r<0.66
59
+ return BigDecimal.new(gen_bignum())
60
+ else
61
+ return BigDecimal.new(gen_float(),0)
62
+ end
63
+ end
64
+
65
+ def gen_complex()
66
+ x = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
67
+ #puts x
68
+ y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
69
+ #puts y
70
+ return Complex(x,y)
71
+ end
72
+
73
+ def gen_rational()
74
+ x = gen_fixnum()
75
+ y = gen_fixnum()
76
+ return Rational(x,y)
77
+ end
78
+
79
+
80
+ def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
81
+ r = Random.rand()
82
+ if r<probFixnum then
83
+ #Fixnum type
84
+ x = gen_fixnum()
85
+ elsif r<(probFixnum+probBignum)
86
+ x = gen_bignum()
87
+ elsif r<(probFixnum+probBignum+probBigDec)
88
+ #BigDecimal type
89
+ x = gen_bigdec()
90
+ elsif r<(probFixnum+probBignum+probBigDec+probInf)
91
+ x=Float::INFINITY
92
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
93
+ x=Float::NAN
94
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
95
+ #Random Float type
96
+ x = gen_float()
97
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
98
+ x= gen_complex()
99
+ elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
100
+ x = gen_rational()
101
+ end
102
+ return x
103
+ end
104
+
105
+ def rounds(x)
106
+ counter = 0
107
+ for i in 0..x
108
+ b= test()
109
+ if (!b) then
110
+ counter=counter+1
111
+ end
112
+
113
+ end
114
+ return counter
115
+ end
116
+
117
+
118
+ def query(q,y)
119
+ $__rdl_contract_switch.off {
120
+ if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
121
+ klass = nil
122
+ klass_pref = nil
123
+ meth = nil
124
+ if q =~ /(.+)#(.+)/
125
+ klass = $1
126
+ klass_pref = "#{klass}#"
127
+ meth = $2.to_sym
128
+ elsif q =~ /(.+)\.(.+)/
129
+ klass_pref = "#{$1}."
130
+ klass = RDL::Util.add_singleton_marker($1)
131
+ meth = $2.to_sym
132
+ else
133
+ klass = self.class.to_s
134
+ klass_pref = "#{klass}#"
135
+ meth = q.to_sym
136
+ end
137
+ if RDL::Wrap.has_contracts?(klass, meth, :type)
138
+ typs = RDL::Wrap.get_contracts(klass, meth, :type)
139
+ typs.each { |t|
140
+ #puts "#{klass_pref}#{meth}: #{t}"
141
+ t_string = "#{t}"
142
+ t_string =~ /\((\w*)\)(.+)/
143
+
144
+ #puts y
145
+ if y.is_a?(Object.const_get($1))
146
+ return t_string
147
+ end
148
+ #return "#{t}"
149
+ }
150
+ nil
151
+ else
152
+ #puts "No type for #{klass_pref}#{meth}"
153
+ end
154
+ else
155
+ #puts "Not implemented"
156
+ end
157
+ }
158
+ end
159
+
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bigdecimal'
4
+ require 'rdl'
5
+ require 'rdl_types'
6
+
7
+ MAX_FIXNUM = 2**(0.size*8-2)-1 #Largest fixnum. -2 since 1 bit used for sign, 1 bit used as int marker.
8
+ MIN_FIXNUM = -(2**(0.size*8-2)) #Smallest fixnum.
9
+
10
+ def test()
11
+ x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
12
+ type_one = x.class.to_s
13
+ if x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
14
+ y = gen_number(0.25,0.25,0,0.1,0.1,0.2,0,0.1)
15
+ type_two = y.class.to_s
16
+ elsif x.is_a?(Complex)
17
+ y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
18
+ type_two = y.class.to_s
19
+ elsif type_one=="BigDecimal"
20
+ if x<0
21
+ y = gen_number_2(0.25,0.25,0.2,0,0,0.3,0,0)
22
+ type_two = y.class.to_s
23
+ else
24
+ y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
25
+ type_two = y.class.to_s
26
+ end
27
+ elsif x<0
28
+ y = gen_number_2(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
29
+ type_two = y.class.to_s
30
+ else
31
+ y = gen_number_2(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
32
+ type_two = y.class.to_s
33
+ end
34
+ puts "Arg1= #{x} and type = #{type_one}"
35
+ puts "Arg2= #{y} and type = #{type_two}"
36
+ operation_type = query(type_one+'#**',y)
37
+ expected_type = operation_type[operation_type.index('->')+3..-1]
38
+ w = x**y
39
+ puts "here"
40
+ test_result = w.is_a?(Object.const_get(expected_type))
41
+ if !test_result
42
+ puts "Arg1= #{x} (type: #{type_one})"
43
+ puts "Arg2= #{y} (type: #{type_two})"
44
+ puts "Res= #{w}"
45
+ puts "Expected type: #{expected_type}"
46
+ puts "Received type: #{w.class}"
47
+ end
48
+ #puts test_result
49
+ return test_result
50
+ end
51
+
52
+ def gen_fixnum()
53
+ return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
54
+ end
55
+
56
+ def gen_bignum()
57
+ r = Random.rand()
58
+ if r<0.5
59
+ return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
60
+ else
61
+ return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
62
+ end
63
+ end
64
+
65
+ def gen_float()
66
+ r = Random.rand()
67
+ if r<0.5
68
+ return (2**32)*Random.rand
69
+ else
70
+ return -1*(2**32)*Random.rand
71
+ end
72
+ end
73
+
74
+ def gen_bigdec()
75
+ r = Random.rand()
76
+ if r<0.33
77
+ return BigDecimal.new(gen_fixnum())
78
+ elsif r<0.66
79
+ return BigDecimal.new(gen_bignum())
80
+ else
81
+ return BigDecimal.new((2**32)*Random.rand,0)
82
+ end
83
+ end
84
+
85
+ def gen_bigdec_2()
86
+ r = Random.rand()
87
+ if r<0.33
88
+ return BigDecimal.new(gen_fixnum())
89
+ elsif r<0.66
90
+ return BigDecimal.new(gen_bignum())
91
+ else
92
+ return BigDecimal.new(gen_float(),0)
93
+ end
94
+ end
95
+
96
+
97
+ def gen_complex()
98
+ x = gen_number(0.25,0.25,0.1,0.05,0.05,0.2,0,0.1)
99
+ #puts x
100
+ if x.is_a?(BigDecimal)
101
+ y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
102
+ elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
103
+ y = gen_number(0.25,0.25,0,0.1,0.1,0.2,0,0.1)
104
+ else
105
+ y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
106
+ #puts y
107
+ end
108
+ return Complex(x,y)
109
+ end
110
+
111
+ def gen_rational()
112
+ x = gen_fixnum()
113
+ y = gen_fixnum()
114
+ return Rational(x,y)
115
+ end
116
+
117
+
118
+ def gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
119
+ r = Random.rand()
120
+ if r<probFixnum then
121
+ #Fixnum type
122
+ x = gen_fixnum()
123
+ elsif r<(probFixnum+probBignum)
124
+ x = gen_bignum()
125
+ elsif r<(probFixnum+probBignum+probBigDec)
126
+ #BigDecimal type
127
+ x = gen_bigdec()
128
+ elsif r<(probFixnum+probBignum+probBigDec+probInf)
129
+ x=Float::INFINITY
130
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
131
+ x=Float::NAN
132
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
133
+ #Random Float type
134
+ x = gen_float()
135
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
136
+ x= gen_complex()
137
+ elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
138
+ x = gen_rational()
139
+ end
140
+ return x
141
+ end
142
+
143
+ def gen_number_2(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational)
144
+ r = Random.rand()
145
+ if r<probFixnum then
146
+ #Fixnum type
147
+ x = gen_fixnum()
148
+ elsif r<(probFixnum+probBignum)
149
+ x = gen_bignum()
150
+ elsif r<(probFixnum+probBignum+probBigDec)
151
+ #BigDecimal type
152
+ x = gen_bigdec_2()
153
+ elsif r<(probFixnum+probBignum+probBigDec+probInf)
154
+ x=Float::INFINITY
155
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
156
+ x=Float::NAN
157
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
158
+ #Random Float type
159
+ x = gen_float()
160
+ elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
161
+ x= gen_complex()
162
+ elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
163
+ x = gen_rational()
164
+ end
165
+ return x
166
+ end
167
+
168
+ def rounds(x)
169
+ counter = 0
170
+ for i in 0..x
171
+ b= test()
172
+ if (!b) then
173
+ counter=counter+1
174
+ end
175
+
176
+ end
177
+ return counter
178
+ end
179
+
180
+
181
+ def query(q,y)
182
+ $__rdl_contract_switch.off {
183
+ if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
184
+ klass = nil
185
+ klass_pref = nil
186
+ meth = nil
187
+ if q =~ /(.+)#(.+)/
188
+ klass = $1
189
+ klass_pref = "#{klass}#"
190
+ meth = $2.to_sym
191
+ elsif q =~ /(.+)\.(.+)/
192
+ klass_pref = "#{$1}."
193
+ klass = RDL::Util.add_singleton_marker($1)
194
+ meth = $2.to_sym
195
+ else
196
+ klass = self.class.to_s
197
+ klass_pref = "#{klass}#"
198
+ meth = q.to_sym
199
+ end
200
+ if RDL::Wrap.has_contracts?(klass, meth, :type)
201
+ typs = RDL::Wrap.get_contracts(klass, meth, :type)
202
+ typs.each { |t|
203
+ #puts "#{klass_pref}#{meth}: #{t}"
204
+ t_string = "#{t}"
205
+ t_string =~ /\((\w*)\)(.+)/
206
+
207
+ #puts y
208
+ if y.is_a?(Object.const_get($1))
209
+ return t_string
210
+ end
211
+ #return "#{t}"
212
+ }
213
+ nil
214
+ else
215
+ #puts "No type for #{klass_pref}#{meth}"
216
+ end
217
+ else
218
+ #puts "Not implemented"
219
+ end
220
+ }
221
+ end
222
+