rdl 2.0.1 → 2.1.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +13 -0
- data/CHANGES.md +35 -0
- data/README.md +153 -116
- data/bin/rdl_query +1 -1
- data/extras/type_tests/typetests.rb +905 -0
- data/lib/rdl.rb +0 -1
- data/lib/rdl/boot.rb +108 -77
- data/lib/rdl/boot_rails.rb +2 -8
- data/lib/rdl/config.rb +44 -17
- data/lib/rdl/contracts/flat.rb +1 -1
- data/lib/rdl/info.rb +3 -3
- data/lib/rdl/query.rb +11 -11
- data/lib/rdl/typecheck.rb +399 -136
- data/lib/rdl/types/finite_hash.rb +3 -2
- data/lib/rdl/types/generic.rb +7 -6
- data/lib/rdl/types/intersection.rb +3 -2
- data/lib/rdl/types/lexer.rex +2 -3
- data/lib/rdl/types/lexer.rex.rb +1 -4
- data/lib/rdl/types/method.rb +7 -6
- data/lib/rdl/types/nominal.rb +10 -1
- data/lib/rdl/types/parser.racc +7 -8
- data/lib/rdl/types/parser.tab.rb +108 -109
- data/lib/rdl/types/structural.rb +1 -0
- data/lib/rdl/types/tuple.rb +2 -2
- data/lib/rdl/types/type.rb +8 -8
- data/lib/rdl/types/type_inferencer.rb +1 -1
- data/lib/rdl/types/union.rb +2 -1
- data/lib/rdl/util.rb +28 -3
- data/lib/rdl/wrap.rb +216 -165
- data/lib/rdl_disable.rb +22 -15
- data/lib/types/core.rb +2 -4
- data/lib/types/core/_aliases.rb +14 -0
- data/lib/types/core/abbrev.rb +3 -0
- data/lib/types/core/array.rb +139 -0
- data/lib/types/core/base64.rb +8 -0
- data/lib/types/core/basic_object.rb +12 -0
- data/lib/types/core/benchmark.rb +9 -0
- data/lib/types/core/bigdecimal.rb +223 -0
- data/lib/types/core/bigmath.rb +10 -0
- data/lib/types/core/bignum.rb +214 -0
- data/lib/types/core/class.rb +15 -0
- data/lib/types/core/complex.rb +123 -0
- data/lib/types/core/coverage.rb +4 -0
- data/lib/types/core/csv.rb +3 -0
- data/lib/types/core/date.rb +4 -0
- data/lib/types/core/dir.rb +37 -0
- data/lib/types/core/encoding.rb +21 -0
- data/lib/types/core/enumerable.rb +96 -0
- data/lib/types/core/enumerator.rb +24 -0
- data/lib/types/core/exception.rb +15 -0
- data/lib/types/core/file.rb +125 -0
- data/lib/types/core/fileutils.rb +4 -0
- data/lib/types/core/fixnum.rb +213 -0
- data/lib/types/core/float.rb +199 -0
- data/lib/types/core/gem.rb +19 -0
- data/lib/types/core/hash.rb +72 -0
- data/lib/types/core/integer.rb +194 -0
- data/lib/types/core/io.rb +101 -0
- data/lib/types/core/kernel.rb +89 -0
- data/lib/types/core/marshal.rb +3 -0
- data/lib/types/core/matchdata.rb +24 -0
- data/lib/types/core/math.rb +50 -0
- data/lib/types/core/module.rb +81 -0
- data/lib/types/core/nil.rb +11 -0
- data/lib/types/core/numeric.rb +56 -0
- data/lib/types/core/object.rb +73 -0
- data/lib/types/core/pathname.rb +104 -0
- data/lib/types/core/proc.rb +12 -0
- data/lib/types/core/process.rb +110 -0
- data/lib/types/core/random.rb +13 -0
- data/lib/types/core/range.rb +37 -0
- data/lib/types/core/rational.rb +207 -0
- data/lib/types/core/regexp.rb +28 -0
- data/lib/types/core/set.rb +56 -0
- data/lib/types/core/string.rb +140 -0
- data/lib/types/core/strscan.rb +6 -0
- data/lib/types/core/symbol.rb +27 -0
- data/lib/types/core/time.rb +66 -0
- data/lib/types/core/uri.rb +18 -0
- data/lib/types/core/yaml.rb +3 -0
- data/lib/types/devise.rb +1 -0
- data/lib/types/devise/controller_helpers.rb +3 -0
- data/lib/types/devise/parameter_sanitizer.rb +2 -0
- data/lib/types/pundit.rb +2 -0
- data/lib/types/rails/_helpers.rb +50 -0
- data/lib/types/rails/abstract_controller/translation.rb +2 -0
- data/lib/types/rails/action_controller/base.rb +3 -0
- data/lib/types/rails/action_controller/instrumentation.rb +6 -0
- data/lib/types/rails/action_controller/metal.rb +3 -0
- data/lib/types/rails/action_controller/mime_responds.rb +13 -0
- data/lib/types/rails/action_controller/parameters.rb +3 -0
- data/lib/types/{rails-5.x → rails}/action_controller/strong_parameters.rb +4 -8
- data/lib/types/rails/action_dispatch/flashhash.rb +8 -0
- data/lib/types/rails/action_dispatch/routing.rb +10 -0
- data/lib/types/rails/action_mailer/base.rb +2 -0
- data/lib/types/rails/action_mailer/message_delivery.rb +2 -0
- data/lib/types/rails/action_view/helpers_sanitizehelper.rb +2 -0
- data/lib/types/rails/action_view/helpers_urlhelper.rb +5 -0
- data/lib/types/rails/active_model/errors.rb +14 -0
- data/lib/types/rails/active_model/validations.rb +2 -0
- data/lib/types/rails/active_record/associations.rb +208 -0
- data/lib/types/rails/active_record/base.rb +2 -0
- data/lib/types/rails/active_record/core.rb +2 -0
- data/lib/types/rails/active_record/finder_methods.rb +2 -0
- data/lib/types/rails/active_record/model_schema.rb +37 -0
- data/lib/types/rails/active_record/relation.rb +11 -0
- data/lib/types/rails/active_record/schema_types.rb +51 -0
- data/lib/types/rails/active_record/validations.rb +2 -0
- data/lib/types/rails/active_support/base.rb +2 -0
- data/lib/types/rails/active_support/logger.rb +3 -0
- data/lib/types/rails/active_support/tagged_logging.rb +2 -0
- data/lib/types/rails/active_support/time_with_zone.rb +13 -0
- data/lib/types/rails/active_support/time_zone.rb +2 -0
- data/lib/types/rails/fixnum.rb +2 -0
- data/lib/types/rails/integer.rb +2 -0
- data/lib/types/rails/rack/request.rb +2 -0
- data/lib/types/rails/string.rb +3 -0
- data/lib/types/rails/time.rb +1 -0
- data/rdl.gemspec +2 -2
- data/test/disabled_test_rdoc.rb +8 -8
- data/test/test_alias.rb +1 -0
- data/test/test_dsl.rb +4 -4
- data/test/test_generic.rb +45 -38
- data/test/test_intersection.rb +10 -10
- data/test/test_le.rb +103 -102
- data/test/test_member.rb +33 -33
- data/test/test_parser.rb +101 -96
- data/test/test_query.rb +84 -84
- data/test/test_rdl.rb +87 -52
- data/test/test_rdl_type.rb +26 -9
- data/test/test_type_contract.rb +32 -31
- data/test/test_typecheck.rb +802 -436
- data/test/test_types.rb +39 -39
- data/test/test_wrap.rb +3 -2
- metadata +91 -120
- data/extras/type_tests/%.rb +0 -171
- data/extras/type_tests/&.rb +0 -159
- data/extras/type_tests/**.rb +0 -222
- data/extras/type_tests/*.rb +0 -177
- data/extras/type_tests/+.rb +0 -170
- data/extras/type_tests/-.rb +0 -171
- data/extras/type_tests/1scomp.rb +0 -157
- data/extras/type_tests/<.rb +0 -170
- data/extras/type_tests/<<.rb +0 -159
- data/extras/type_tests/>>.rb +0 -159
- data/extras/type_tests/[].rb +0 -163
- data/extras/type_tests/^.rb +0 -159
- data/extras/type_tests/abs.rb +0 -155
- data/extras/type_tests/abs2.rb +0 -164
- data/extras/type_tests/angle.rb +0 -157
- data/extras/type_tests/arg.rb +0 -157
- data/extras/type_tests/bit_length.rb +0 -157
- data/extras/type_tests/ceil.rb +0 -157
- data/extras/type_tests/ceilRational.rb +0 -160
- data/extras/type_tests/conj.rb +0 -158
- data/extras/type_tests/defwhere.rb +0 -86
- data/extras/type_tests/denominator.rb +0 -157
- data/extras/type_tests/div.rb +0 -172
- data/extras/type_tests/divslash.rb +0 -179
- data/extras/type_tests/even?.rb +0 -157
- data/extras/type_tests/fdiv.rb +0 -244
- data/extras/type_tests/finite?.rb +0 -157
- data/extras/type_tests/floor.rb +0 -157
- data/extras/type_tests/floorRational.rb +0 -161
- data/extras/type_tests/hash.rb +0 -157
- data/extras/type_tests/imag.rb +0 -158
- data/extras/type_tests/infinite?.rb +0 -157
- data/extras/type_tests/modulo.rb +0 -171
- data/extras/type_tests/nan?.rb +0 -157
- data/extras/type_tests/neg.rb +0 -155
- data/extras/type_tests/next.rb +0 -157
- data/extras/type_tests/next_float.rb +0 -157
- data/extras/type_tests/numerator.rb +0 -157
- data/extras/type_tests/phase.rb +0 -157
- data/extras/type_tests/prev_float.rb +0 -157
- data/extras/type_tests/quo.rb +0 -179
- data/extras/type_tests/rationalize.rb +0 -157
- data/extras/type_tests/rationalizeArg.rb +0 -198
- data/extras/type_tests/real.rb +0 -157
- data/extras/type_tests/real?.rb +0 -157
- data/extras/type_tests/round.rb +0 -157
- data/extras/type_tests/roundArg.rb +0 -169
- data/extras/type_tests/size.rb +0 -157
- data/extras/type_tests/to_c.rb +0 -157
- data/extras/type_tests/to_f.rb +0 -155
- data/extras/type_tests/to_i.rb +0 -157
- data/extras/type_tests/to_r.rb +0 -157
- data/extras/type_tests/to_s.rb +0 -157
- data/extras/type_tests/truncate.rb +0 -157
- data/extras/type_tests/truncateArg.rb +0 -166
- data/extras/type_tests/type tests +0 -1
- data/extras/type_tests/zero?.rb +0 -155
- data/extras/type_tests/|.rb +0 -159
- data/lib/types/core-ruby-2.x/_aliases.rb +0 -15
- data/lib/types/core-ruby-2.x/abbrev.rb +0 -5
- data/lib/types/core-ruby-2.x/array.rb +0 -137
- data/lib/types/core-ruby-2.x/base64.rb +0 -10
- data/lib/types/core-ruby-2.x/basic_object.rb +0 -14
- data/lib/types/core-ruby-2.x/benchmark.rb +0 -11
- data/lib/types/core-ruby-2.x/bigdecimal.rb +0 -224
- data/lib/types/core-ruby-2.x/bigmath.rb +0 -12
- data/lib/types/core-ruby-2.x/bignum.rb +0 -214
- data/lib/types/core-ruby-2.x/class.rb +0 -17
- data/lib/types/core-ruby-2.x/complex.rb +0 -124
- data/lib/types/core-ruby-2.x/coverage.rb +0 -6
- data/lib/types/core-ruby-2.x/csv.rb +0 -5
- data/lib/types/core-ruby-2.x/date.rb +0 -6
- data/lib/types/core-ruby-2.x/dir.rb +0 -38
- data/lib/types/core-ruby-2.x/encoding.rb +0 -23
- data/lib/types/core-ruby-2.x/enumerable.rb +0 -98
- data/lib/types/core-ruby-2.x/enumerator.rb +0 -26
- data/lib/types/core-ruby-2.x/exception.rb +0 -17
- data/lib/types/core-ruby-2.x/file.rb +0 -126
- data/lib/types/core-ruby-2.x/fileutils.rb +0 -6
- data/lib/types/core-ruby-2.x/fixnum.rb +0 -213
- data/lib/types/core-ruby-2.x/float.rb +0 -199
- data/lib/types/core-ruby-2.x/gem.rb +0 -247
- data/lib/types/core-ruby-2.x/hash.rb +0 -72
- data/lib/types/core-ruby-2.x/integer.rb +0 -197
- data/lib/types/core-ruby-2.x/io.rb +0 -103
- data/lib/types/core-ruby-2.x/kernel.rb +0 -90
- data/lib/types/core-ruby-2.x/marshal.rb +0 -5
- data/lib/types/core-ruby-2.x/matchdata.rb +0 -26
- data/lib/types/core-ruby-2.x/math.rb +0 -53
- data/lib/types/core-ruby-2.x/module.rb +0 -83
- data/lib/types/core-ruby-2.x/nil.rb +0 -12
- data/lib/types/core-ruby-2.x/numeric.rb +0 -56
- data/lib/types/core-ruby-2.x/object.rb +0 -75
- data/lib/types/core-ruby-2.x/pathname.rb +0 -106
- data/lib/types/core-ruby-2.x/proc.rb +0 -16
- data/lib/types/core-ruby-2.x/process.rb +0 -127
- data/lib/types/core-ruby-2.x/random.rb +0 -17
- data/lib/types/core-ruby-2.x/range.rb +0 -39
- data/lib/types/core-ruby-2.x/rational.rb +0 -209
- data/lib/types/core-ruby-2.x/regexp.rb +0 -30
- data/lib/types/core-ruby-2.x/set.rb +0 -58
- data/lib/types/core-ruby-2.x/string.rb +0 -143
- data/lib/types/core-ruby-2.x/strscan.rb +0 -7
- data/lib/types/core-ruby-2.x/symbol.rb +0 -29
- data/lib/types/core-ruby-2.x/time.rb +0 -68
- data/lib/types/core-ruby-2.x/uri.rb +0 -20
- data/lib/types/core-ruby-2.x/yaml.rb +0 -5
- data/lib/types/rails-5.x/_helpers.rb +0 -52
- data/lib/types/rails-5.x/action_controller/mime_responds.rb +0 -11
- data/lib/types/rails-5.x/action_dispatch/routing.rb +0 -10
- data/lib/types/rails-5.x/active_model/errors.rb +0 -15
- data/lib/types/rails-5.x/active_model/validations.rb +0 -5
- data/lib/types/rails-5.x/active_record/associations.rb +0 -190
- data/lib/types/rails-5.x/active_record/core.rb +0 -3
- data/lib/types/rails-5.x/active_record/model_schema.rb +0 -39
- data/lib/types/rails-5.x/fixnum.rb +0 -3
data/bin/rdl_query
CHANGED
|
@@ -0,0 +1,905 @@
|
|
|
1
|
+
require 'bigdecimal'
|
|
2
|
+
require 'rdl'
|
|
3
|
+
require 'types/core'
|
|
4
|
+
|
|
5
|
+
## This file contains tests for the Numeric method types specified in lib/types/core-ruby-2.x/.
|
|
6
|
+
## Each method test_x will generate a random Numeric object and call the method :x on that object,
|
|
7
|
+
## checking to ensure that the returned type matches the type specified in the corresponding type
|
|
8
|
+
## file. In order to run a particular test multiple times, call the "rounds" method with that test
|
|
9
|
+
## and the number of rounds you wish to run it as arguments. For example, to run the "test_mod"
|
|
10
|
+
## test 100 times, call TypeTest.rounds(:test_mod, 100).
|
|
11
|
+
|
|
12
|
+
MAX_FIXNUM = 2**(0.size*8-2)-1 #Largest fixnum. -2 since 1 bit used for sign, 1 bit used as int marker.
|
|
13
|
+
MIN_FIXNUM = -(2**(0.size*8-2)) #Smallest fixnum.
|
|
14
|
+
|
|
15
|
+
class TypeTest
|
|
16
|
+
|
|
17
|
+
def self.test_mod()
|
|
18
|
+
x = gen_number(0.2,0.2,0.2,0.05,0.05,0.2,0,0.1)
|
|
19
|
+
type_one = x.class.to_s
|
|
20
|
+
if type_one=="BigDecimal"
|
|
21
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
|
22
|
+
type_two = y.class.to_s
|
|
23
|
+
elsif type_one=="Rational"
|
|
24
|
+
y = gen_number(0.2,0.2,0.2,0.1,0,0.2,0,0.1)
|
|
25
|
+
type_two = y.class.to_s
|
|
26
|
+
elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
|
27
|
+
y = gen_number(0.2,0.2,0,0.1,0.1,0.3,0,0.1)
|
|
28
|
+
type_two = y.class.to_s
|
|
29
|
+
else
|
|
30
|
+
y = gen_number(0.2,0.2,0.2,0.05,0.05,0.2,0,0.1)
|
|
31
|
+
type_two = y.class.to_s
|
|
32
|
+
end
|
|
33
|
+
operation_type, bind = query(type_one+'#%',x,y)
|
|
34
|
+
w = x%y
|
|
35
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
36
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
37
|
+
return test_result
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.test_and()
|
|
41
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
42
|
+
type_one = x.class.to_s
|
|
43
|
+
y = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
44
|
+
type_two = y.class.to_s
|
|
45
|
+
operation_type, bind = query(type_one+'#&',x,y)
|
|
46
|
+
w = x&y
|
|
47
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
48
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
49
|
+
return test_result
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.test_add()
|
|
53
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
54
|
+
type_one = x.class.to_s
|
|
55
|
+
if type_one=="BigDecimal"
|
|
56
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
|
57
|
+
type_two = y.class.to_s
|
|
58
|
+
elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
|
59
|
+
y = gen_number(0.2,0.2,0,0.1,0.1,0.3,0,0.1)
|
|
60
|
+
type_two = y.class.to_s
|
|
61
|
+
elsif x.is_a?(Complex)
|
|
62
|
+
y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
|
|
63
|
+
type_two = y.class.to_s
|
|
64
|
+
else
|
|
65
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
66
|
+
type_two = y.class.to_s
|
|
67
|
+
end
|
|
68
|
+
operation_type, bind = query(type_one+'#+',x,y)
|
|
69
|
+
w = x+y
|
|
70
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
71
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
72
|
+
return test_result
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def self.test_sub()
|
|
76
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
77
|
+
type_one = x.class.to_s
|
|
78
|
+
if type_one=="BigDecimal"
|
|
79
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
|
80
|
+
type_two = y.class.to_s
|
|
81
|
+
elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
|
82
|
+
y = gen_number(0.2,0.2,0,0.1,0.1,0.3,0,0.1)
|
|
83
|
+
type_two = y.class.to_s
|
|
84
|
+
elsif x.is_a?(Complex)
|
|
85
|
+
y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
|
|
86
|
+
type_two = y.class.to_s
|
|
87
|
+
else
|
|
88
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
89
|
+
type_two = y.class.to_s
|
|
90
|
+
end
|
|
91
|
+
operation_type, bind = query(type_one+'#-',x,y)
|
|
92
|
+
w = x-y
|
|
93
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
94
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
95
|
+
return test_result
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def self.test_ones_comp()
|
|
99
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
100
|
+
type_one = x.class.to_s
|
|
101
|
+
operation_type,bind = query(type_one+'#~',x,nil)
|
|
102
|
+
w = ~x
|
|
103
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
104
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
105
|
+
return test_result
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def self.test_mult()
|
|
109
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
110
|
+
type_one = x.class.to_s
|
|
111
|
+
if type_one=="BigDecimal"
|
|
112
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
|
113
|
+
type_two = y.class.to_s
|
|
114
|
+
elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
|
115
|
+
y = gen_number(0.25,0.25,0,0.1,0.1,0.2,0,0.1)
|
|
116
|
+
type_two = y.class.to_s
|
|
117
|
+
elsif x.is_a?(Complex)
|
|
118
|
+
y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
|
|
119
|
+
type_two = y.class.to_s
|
|
120
|
+
else
|
|
121
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
122
|
+
type_two = y.class.to_s
|
|
123
|
+
end
|
|
124
|
+
operation_type, bind = query(type_one+'#*',x,y)
|
|
125
|
+
w = x*y
|
|
126
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
127
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
128
|
+
return test_result
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def self.test_lt()
|
|
132
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0,0.2)
|
|
133
|
+
type_one = x.class.to_s
|
|
134
|
+
if type_one=="BigDecimal"
|
|
135
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
|
136
|
+
type_two = y.class.to_s
|
|
137
|
+
elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
|
138
|
+
y = gen_number(0.2,0.2,0,0.1,0.1,0.3,0,0.1)
|
|
139
|
+
type_two = y.class.to_s
|
|
140
|
+
elsif x.is_a?(Rational)
|
|
141
|
+
y = gen_number(0.2,0.2,0,0.1,0,0.3,0,0.2)
|
|
142
|
+
type_two = y.class.to_s
|
|
143
|
+
else
|
|
144
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0,0.2)
|
|
145
|
+
type_two = y.class.to_s
|
|
146
|
+
end
|
|
147
|
+
operation_type, bind = query(type_one+'#<',x,y)
|
|
148
|
+
w = x<y
|
|
149
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
150
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
151
|
+
return test_result
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def self.test_pow()
|
|
155
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
156
|
+
type_one = x.class.to_s
|
|
157
|
+
if x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
|
158
|
+
y = gen_number(0.25,0.25,0,0.1,0.1,0.2,0,0.1)
|
|
159
|
+
type_two = y.class.to_s
|
|
160
|
+
elsif x.is_a?(Complex)
|
|
161
|
+
y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
|
|
162
|
+
type_two = y.class.to_s
|
|
163
|
+
elsif type_one=="BigDecimal"
|
|
164
|
+
if x<0
|
|
165
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.3,0,0,true)
|
|
166
|
+
type_two = y.class.to_s
|
|
167
|
+
else
|
|
168
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
|
169
|
+
type_two = y.class.to_s
|
|
170
|
+
end
|
|
171
|
+
elsif x<0
|
|
172
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1,true)
|
|
173
|
+
type_two = y.class.to_s
|
|
174
|
+
else
|
|
175
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1,true)
|
|
176
|
+
type_two = y.class.to_s
|
|
177
|
+
end
|
|
178
|
+
operation_type, bind = query(type_one+'#**',x,y)
|
|
179
|
+
w = x**y
|
|
180
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
181
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
182
|
+
return test_result
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def self.test_shiftl()
|
|
186
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
187
|
+
type_one = x.class.to_s
|
|
188
|
+
y = Random.rand(-1000000000..1000000000)
|
|
189
|
+
type_two = y.class.to_s
|
|
190
|
+
operation_type, bind = query(type_one+'#<<',x,y)
|
|
191
|
+
w = x << y
|
|
192
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
193
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
194
|
+
return test_result
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def self.test_shiftr()
|
|
198
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
199
|
+
type_one = x.class.to_s
|
|
200
|
+
y = Random.rand(-1000000000..1000000000)
|
|
201
|
+
type_two = y.class.to_s
|
|
202
|
+
operation_type, bind = query(type_one+'#>>',x,y)
|
|
203
|
+
w = x >> y
|
|
204
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
205
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
206
|
+
return test_result
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def self.test_bitref()
|
|
210
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
211
|
+
type_one = x.class.to_s
|
|
212
|
+
if (x.is_a?(Bignum))
|
|
213
|
+
y = gen_number(0.4,0.4,0,0,0,0,0,0.2)
|
|
214
|
+
else
|
|
215
|
+
y = gen_number(0.2,0.2,0.2,0,0,0.2,0,0.2)
|
|
216
|
+
end
|
|
217
|
+
type_two = y.class.to_s
|
|
218
|
+
operation_type,bind = query(type_one+'#[]',x,y)
|
|
219
|
+
w = x[y]
|
|
220
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
221
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
222
|
+
return test_result
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def self.test_xor()
|
|
226
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
227
|
+
type_one = x.class.to_s
|
|
228
|
+
y = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
229
|
+
type_two = y.class.to_s
|
|
230
|
+
operation_type,bind = query(type_one+'#^',x,y)
|
|
231
|
+
w = x^y
|
|
232
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
233
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
234
|
+
return test_result
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
def self.test_abs()
|
|
238
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
239
|
+
type_one = x.class.to_s
|
|
240
|
+
operation_type,bind = query(type_one+'#abs',x,nil)
|
|
241
|
+
w = x.abs
|
|
242
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
243
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
244
|
+
return test_result
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
def self.test_abs2()
|
|
248
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
249
|
+
type_one = x.class.to_s
|
|
250
|
+
operation_type,bind = query(type_one+'#abs2',x,nil)
|
|
251
|
+
w = x.abs
|
|
252
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
253
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
254
|
+
return test_result
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def self.test_angle()
|
|
258
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
259
|
+
type_one = x.class.to_s
|
|
260
|
+
operation_type,bind = query(type_one+'#angle',x,nil)
|
|
261
|
+
w = x.angle
|
|
262
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
263
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
264
|
+
return test_result
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def self.test_arg()
|
|
268
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
269
|
+
type_one = x.class.to_s
|
|
270
|
+
operation_type,bind = query(type_one+'#arg',x,nil)
|
|
271
|
+
w = x.arg
|
|
272
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
273
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
274
|
+
return test_result
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def self.test_bitlength()
|
|
278
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
279
|
+
type_one = x.class.to_s
|
|
280
|
+
operation_type,bind = query(type_one+'#bit_length',x,nil)
|
|
281
|
+
w = x.bit_length
|
|
282
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
283
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
284
|
+
return test_result
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def self.test_ceil()
|
|
288
|
+
x = gen_number(0.2,0.2,0.2,0,0,0.2,0,0.2)
|
|
289
|
+
type_one = x.class.to_s
|
|
290
|
+
operation_type,bind = query(type_one+'#ceil',x,nil)
|
|
291
|
+
w = x.ceil
|
|
292
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
293
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
294
|
+
return test_result
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
def self.test_ceil_rational()
|
|
298
|
+
x = gen_number(0,0,0,0,0,0,0,1)
|
|
299
|
+
type_one = x.class.to_s
|
|
300
|
+
y = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
301
|
+
type_two = y.class.to_s
|
|
302
|
+
operation_type,bind = query(type_one+'#ceil',x,y)
|
|
303
|
+
w = x.ceil(y)
|
|
304
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
305
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
306
|
+
return test_result
|
|
307
|
+
end
|
|
308
|
+
|
|
309
|
+
def self.test_conj()
|
|
310
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
311
|
+
type_one = x.class.to_s
|
|
312
|
+
operation_type,bind = query(type_one+'#conj',x,nil)
|
|
313
|
+
w = x.conj
|
|
314
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
315
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
316
|
+
return test_result
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
def self.test_denominator()
|
|
320
|
+
x = gen_number(0.2,0.2,0.1,0,0,0.2,0.1,0.2)
|
|
321
|
+
type_one = x.class.to_s
|
|
322
|
+
operation_type,bind = query(type_one+'#denominator',x,nil)
|
|
323
|
+
w = x.denominator
|
|
324
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
325
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
326
|
+
return test_result
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def self.test_div()
|
|
330
|
+
x = gen_number(0.2,0.2,0.2,0,0,0.2,0,0.2)
|
|
331
|
+
type_one = x.class.to_s
|
|
332
|
+
if type_one=="Float"
|
|
333
|
+
y = gen_number(0.3,0.3,0.2,0,0,0.2,0,0)
|
|
334
|
+
else
|
|
335
|
+
y = gen_number(0.2,0.2,0.2,0,0,0.2,0,0.2)
|
|
336
|
+
end
|
|
337
|
+
type_two = y.class.to_s
|
|
338
|
+
operation_type,bind = query(type_one+'#div',x,y)
|
|
339
|
+
w = x.div(y)
|
|
340
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
341
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
342
|
+
return test_result
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
def self.test_divslash()
|
|
346
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
347
|
+
type_one = x.class.to_s
|
|
348
|
+
if type_one=="BigDecimal"
|
|
349
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
|
350
|
+
type_two = y.class.to_s
|
|
351
|
+
elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
|
352
|
+
y = gen_number(0.25,0.25,0,0.1,0.1,0.2,0,0.1)
|
|
353
|
+
type_two = y.class.to_s
|
|
354
|
+
elsif x.is_a?(Complex)
|
|
355
|
+
y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
|
|
356
|
+
type_two = y.class.to_s
|
|
357
|
+
else
|
|
358
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
359
|
+
type_two = y.class.to_s
|
|
360
|
+
end
|
|
361
|
+
operation_type,bind = query(type_one+'#/',x,y)
|
|
362
|
+
w = x/y
|
|
363
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
364
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
365
|
+
return test_result
|
|
366
|
+
end
|
|
367
|
+
|
|
368
|
+
def self.test_even?()
|
|
369
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
370
|
+
type_one = x.class.to_s
|
|
371
|
+
operation_type,bind = query(type_one+'#even?',x,nil)
|
|
372
|
+
w = x.even?
|
|
373
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
374
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
375
|
+
return test_result
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
def self.test_finite?()
|
|
379
|
+
x = gen_number(0,0,0.5,0.05,0.05,0.4,0,0)
|
|
380
|
+
type_one = x.class.to_s
|
|
381
|
+
operation_type,bind = query(type_one+'#finite?',x,nil)
|
|
382
|
+
w = x.finite?
|
|
383
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
384
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
385
|
+
return test_result
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
def self.test_floor()
|
|
389
|
+
x = gen_number(0.2,0.2,0.2,0,0,0.2,0,0.2)
|
|
390
|
+
type_one = x.class.to_s
|
|
391
|
+
operation_type,bind = query(type_one+'#floor',x,nil)
|
|
392
|
+
w = x.floor
|
|
393
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
394
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
395
|
+
return test_result
|
|
396
|
+
end
|
|
397
|
+
|
|
398
|
+
def self.test_floor_rational()
|
|
399
|
+
x = gen_number(0,0,0,0,0,0,0,1)
|
|
400
|
+
type_one = x.class.to_s
|
|
401
|
+
y = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
402
|
+
type_two = y.class.to_s
|
|
403
|
+
operation_type,bind = query(type_one+'#floor',x,y)
|
|
404
|
+
w = x.floor(y)
|
|
405
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
406
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
407
|
+
return test_result
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
def self.test_hash()
|
|
411
|
+
x = gen_number(0.2,0.2,0.1,0.1,0.1,0.1,0.1,0.1)
|
|
412
|
+
type_one = x.class.to_s
|
|
413
|
+
operation_type,bind = query(type_one+'#hash',x,nil)
|
|
414
|
+
w = x.hash
|
|
415
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
416
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
417
|
+
return test_result
|
|
418
|
+
end
|
|
419
|
+
|
|
420
|
+
def self.test_imag()
|
|
421
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
422
|
+
type_one = x.class.to_s
|
|
423
|
+
operation_type,bind = query(type_one+'#imag',x,nil)
|
|
424
|
+
w = x.imag
|
|
425
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
426
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
427
|
+
return test_result
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
def self.test_infinite?()
|
|
432
|
+
x = gen_number(0,0,0.5,0.05,0.05,0.4,0,0)
|
|
433
|
+
type_one = x.class.to_s
|
|
434
|
+
operation_type,bind = query(type_one+'#infinite?',x,nil)
|
|
435
|
+
w = x.infinite?
|
|
436
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
437
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
438
|
+
return test_result
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
def self.test_modulo()
|
|
442
|
+
x = gen_number(0.2,0.2,0.2,0.05,0.05,0.2,0,0.1)
|
|
443
|
+
type_one = x.class.to_s
|
|
444
|
+
if type_one=="BigDecimal"
|
|
445
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
|
446
|
+
type_two = y.class.to_s
|
|
447
|
+
elsif type_one=="Rational"
|
|
448
|
+
y = gen_number(0.2,0.2,0.2,0.1,0,0.2,0,0.1)
|
|
449
|
+
type_two = y.class.to_s
|
|
450
|
+
elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
|
451
|
+
y = gen_number(0.2,0.2,0,0.1,0.1,0.3,0,0.1)
|
|
452
|
+
type_two = y.class.to_s
|
|
453
|
+
else
|
|
454
|
+
y = gen_number(0.2,0.2,0.2,0.05,0.05,0.2,0,0.1)
|
|
455
|
+
type_two = y.class.to_s
|
|
456
|
+
end
|
|
457
|
+
operation_type,bind = query(type_one+'#modulo',x,y)
|
|
458
|
+
w = x.modulo(y)
|
|
459
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
460
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
461
|
+
return test_result
|
|
462
|
+
end
|
|
463
|
+
|
|
464
|
+
def self.test_nan?()
|
|
465
|
+
x = gen_number(0,0,0.5,0.05,0.05,0.4,0,0)
|
|
466
|
+
type_one = x.class.to_s
|
|
467
|
+
operation_type,bind = query(type_one+'#nan?',x,nil)
|
|
468
|
+
w = x.nan?
|
|
469
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
470
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
471
|
+
return test_result
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
def self.test_neg()
|
|
475
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
476
|
+
type_one = x.class.to_s
|
|
477
|
+
operation_type,bind = query(type_one+'#-',x,nil)
|
|
478
|
+
w = -x
|
|
479
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
480
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
481
|
+
return test_result
|
|
482
|
+
end
|
|
483
|
+
|
|
484
|
+
def self.test_next()
|
|
485
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
486
|
+
type_one = x.class.to_s
|
|
487
|
+
operation_type,bind = query(type_one+'#next',x,nil)
|
|
488
|
+
w = x.next
|
|
489
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
490
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
491
|
+
return test_result
|
|
492
|
+
end
|
|
493
|
+
|
|
494
|
+
def self.test_next_float()
|
|
495
|
+
x = gen_number(0,0,0,0.05,0.05,0.9,0,0)
|
|
496
|
+
type_one = x.class.to_s
|
|
497
|
+
operation_type,bind = query(type_one+'#next_float',x,nil)
|
|
498
|
+
w = x.next_float
|
|
499
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
500
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
501
|
+
return test_result
|
|
502
|
+
end
|
|
503
|
+
|
|
504
|
+
def self.test_numerator()
|
|
505
|
+
x = gen_number(0.2,0.2,0.1,0,0,0.2,0.1,0.2)
|
|
506
|
+
type_one = x.class.to_s
|
|
507
|
+
operation_type,bind = query(type_one+'#numerator',x,nil)
|
|
508
|
+
w = x.numerator
|
|
509
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
510
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
511
|
+
return test_result
|
|
512
|
+
end
|
|
513
|
+
|
|
514
|
+
def self.test_phase()
|
|
515
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
516
|
+
type_one = x.class.to_s
|
|
517
|
+
operation_type,bind = query(type_one+'#phase',x,nil)
|
|
518
|
+
w = x.phase
|
|
519
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
520
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
521
|
+
return test_result
|
|
522
|
+
end
|
|
523
|
+
|
|
524
|
+
def self.test_prevfloat()
|
|
525
|
+
x = gen_number(0,0,0,0.05,0.05,0.9,0,0)
|
|
526
|
+
type_one = x.class.to_s
|
|
527
|
+
operation_type,bind = query(type_one+'#prev_float',x,nil)
|
|
528
|
+
w = x.prev_float
|
|
529
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
530
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
531
|
+
return test_result
|
|
532
|
+
end
|
|
533
|
+
|
|
534
|
+
def self.test_quo()
|
|
535
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
536
|
+
type_one = x.class.to_s
|
|
537
|
+
if type_one=="BigDecimal"
|
|
538
|
+
y = gen_number(0.25,0.25,0.2,0,0,0.2,0,0.1)
|
|
539
|
+
type_two = y.class.to_s
|
|
540
|
+
elsif x.is_a?(Float)&&(x==Float::INFINITY|| x.nan?)
|
|
541
|
+
y = gen_number(0.25,0.25,0,0.1,0.1,0.2,0,0.1)
|
|
542
|
+
type_two = y.class.to_s
|
|
543
|
+
elsif x.is_a?(Complex)
|
|
544
|
+
y = gen_number(0.3,0.3,0,0,0,0.3,0,0.1)
|
|
545
|
+
type_two = y.class.to_s
|
|
546
|
+
else
|
|
547
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
548
|
+
type_two = y.class.to_s
|
|
549
|
+
end
|
|
550
|
+
operation_type,bind = query(type_one+'#quo',x,y)
|
|
551
|
+
w = x.quo(y)
|
|
552
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
553
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
554
|
+
return test_result
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
def self.test_rationalize()
|
|
558
|
+
x = gen_number(0.2,0.2,0,0,0,0.2,0.2,0.2)
|
|
559
|
+
type_one = x.class.to_s
|
|
560
|
+
operation_type,bind = query(type_one+'#rationalize',x,nil)
|
|
561
|
+
w = x.rationalize
|
|
562
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
563
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
564
|
+
return test_result
|
|
565
|
+
end
|
|
566
|
+
|
|
567
|
+
def self.test_rationalize_arg()
|
|
568
|
+
x = gen_number(0.2,0.2,0,0,0,0.2,0.2,0.2)
|
|
569
|
+
type_one = x.class.to_s
|
|
570
|
+
if x.is_a?(Rational) || x.is_a?(Float) || x.is_a?(Complex)
|
|
571
|
+
y = gen_number(0.2,0.2,0,0,0,0.2,0.2,0.2)
|
|
572
|
+
else
|
|
573
|
+
y = gen_number2(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
574
|
+
end
|
|
575
|
+
type_two = y.class.to_s
|
|
576
|
+
operation_type,bind = query(type_one+'#rationalize',x,y)
|
|
577
|
+
w = x.rationalize(y)
|
|
578
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
579
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
580
|
+
return test_result
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
def self.test_real()
|
|
584
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
585
|
+
type_one = x.class.to_s
|
|
586
|
+
operation_type,bind = query(type_one+'#real',x,nil)
|
|
587
|
+
w = x.real
|
|
588
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
589
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
590
|
+
return test_result
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
def self.test_real?()
|
|
594
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
595
|
+
type_one = x.class.to_s
|
|
596
|
+
operation_type,bind = query(type_one+'#real?',x,nil)
|
|
597
|
+
w = x.real?
|
|
598
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
599
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
600
|
+
return test_result
|
|
601
|
+
end
|
|
602
|
+
|
|
603
|
+
def self.test_round()
|
|
604
|
+
x = gen_number(0.2,0.2,0.2,0,0,0.2,0,0.2)
|
|
605
|
+
type_one = x.class.to_s
|
|
606
|
+
operation_type,bind = query(type_one+'#round',x,nil)
|
|
607
|
+
w = x.round
|
|
608
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
609
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
610
|
+
return test_result
|
|
611
|
+
end
|
|
612
|
+
|
|
613
|
+
def self.test_round_arg()
|
|
614
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0,0.2)
|
|
615
|
+
type_one = x.class.to_s
|
|
616
|
+
if type_one=="BigDecimal"
|
|
617
|
+
y = gen_number(1,0,0,0,0,0,0,0)
|
|
618
|
+
type_two = y.class.to_s
|
|
619
|
+
elsif x.is_a?(Rational)
|
|
620
|
+
y = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
621
|
+
type_two = y.class.to_s
|
|
622
|
+
else
|
|
623
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0,0.2)
|
|
624
|
+
type_two = y.class.to_s
|
|
625
|
+
end
|
|
626
|
+
operation_type,bind = query(type_one+'#round',x,y)
|
|
627
|
+
w = x.round(y)
|
|
628
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
629
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
630
|
+
return test_result
|
|
631
|
+
end
|
|
632
|
+
|
|
633
|
+
def self.test_size()
|
|
634
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
635
|
+
type_one = x.class.to_s
|
|
636
|
+
operation_type,bind = query(type_one+'#size',x,nil)
|
|
637
|
+
w = x.size
|
|
638
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
639
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
640
|
+
return test_result
|
|
641
|
+
end
|
|
642
|
+
|
|
643
|
+
def self.test_to_c()
|
|
644
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
645
|
+
type_one = x.class.to_s
|
|
646
|
+
operation_type,bind = query(type_one+'#to_c',x,nil)
|
|
647
|
+
w = x.to_c
|
|
648
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
649
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
650
|
+
return test_result
|
|
651
|
+
end
|
|
652
|
+
|
|
653
|
+
def self.test_to_f()
|
|
654
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1,false,true)
|
|
655
|
+
type_one = x.class.to_s
|
|
656
|
+
operation_type,bind = query(type_one+'#to_f',x,nil)
|
|
657
|
+
w = x.to_f
|
|
658
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
659
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
660
|
+
return test_result
|
|
661
|
+
end
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
def self.test_to_i()
|
|
665
|
+
x = gen_number(0.2,0.2,0.1,0,0,0.2,0.2,0.1,false,true,true)
|
|
666
|
+
type_one = x.class.to_s
|
|
667
|
+
operation_type,bind = query(type_one+'#to_i',x,nil)
|
|
668
|
+
w = x.to_i
|
|
669
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
670
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
671
|
+
return test_result
|
|
672
|
+
end
|
|
673
|
+
|
|
674
|
+
def self.test_to_r()
|
|
675
|
+
x = gen_number(0.2,0.2,0.1,0,0,0.2,0.2,0.1,false,true,true)
|
|
676
|
+
type_one = x.class.to_s
|
|
677
|
+
operation_type,bind = query(type_one+'#to_r',x,nil)
|
|
678
|
+
w = x.to_r
|
|
679
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
680
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
681
|
+
return test_result
|
|
682
|
+
end
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
def self.test_to_s()
|
|
686
|
+
x = gen_number(0.2,0.2,0.1,0.1,0.1,0.1,0.1,0.1)
|
|
687
|
+
type_one = x.class.to_s
|
|
688
|
+
operation_type,bind = query(type_one+'#to_s',x,nil)
|
|
689
|
+
w = x.to_s
|
|
690
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
691
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
692
|
+
return test_result
|
|
693
|
+
end
|
|
694
|
+
|
|
695
|
+
def self.test_truncate()
|
|
696
|
+
x = gen_number(0.2,0.2,0.2,0,0,0.2,0,0.2)
|
|
697
|
+
type_one = x.class.to_s
|
|
698
|
+
operation_type,bind = query(type_one+'#truncate',x,nil)
|
|
699
|
+
w = x.truncate
|
|
700
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
701
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
702
|
+
return test_result
|
|
703
|
+
end
|
|
704
|
+
|
|
705
|
+
def self.test_zero?()
|
|
706
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.2,0.1,0.1)
|
|
707
|
+
type_one = x.class.to_s
|
|
708
|
+
operation_type,bind = query(type_one+'#zero?',x,nil)
|
|
709
|
+
w = x.zero?
|
|
710
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, nil)
|
|
711
|
+
print_error(x, nil, type_one, nil, operation_type.ret, new_ret) if !test_result
|
|
712
|
+
return test_result
|
|
713
|
+
end
|
|
714
|
+
|
|
715
|
+
def self.test_bitor()
|
|
716
|
+
x = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
717
|
+
type_one = x.class.to_s
|
|
718
|
+
y = gen_number(0.5,0.5,0,0,0,0,0,0)
|
|
719
|
+
type_two = y.class.to_s
|
|
720
|
+
operation_type,bind = query(type_one+'#|',x,y)
|
|
721
|
+
w = x|y
|
|
722
|
+
test_result,new_ret = operation_type.post_cond?(x, true, w, bind, y)
|
|
723
|
+
print_error(x, y, type_one, type_two, operation_type.ret, new_ret) if !test_result
|
|
724
|
+
return test_result
|
|
725
|
+
end
|
|
726
|
+
|
|
727
|
+
def self.print_error(arg1, arg2, type_one, type_two, extype, rec)
|
|
728
|
+
puts "First argument was #{arg1} (type: #{type_one})"
|
|
729
|
+
puts "Second argument was #{arg2} (type: #{type_two})" if arg2
|
|
730
|
+
puts "Result was #{rec}"
|
|
731
|
+
puts "Expected result type: #{extype}"
|
|
732
|
+
puts "Received result type: #{rec.class}"
|
|
733
|
+
end
|
|
734
|
+
|
|
735
|
+
def self.gen_fixnum()
|
|
736
|
+
return Random.rand(MIN_FIXNUM..MAX_FIXNUM)
|
|
737
|
+
end
|
|
738
|
+
|
|
739
|
+
def self.gen_bignum()
|
|
740
|
+
r = Random.rand()
|
|
741
|
+
if r<0.5
|
|
742
|
+
return Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
|
743
|
+
else
|
|
744
|
+
return -1*Random.rand(MAX_FIXNUM+1..MAX_FIXNUM*1000)
|
|
745
|
+
end
|
|
746
|
+
end
|
|
747
|
+
|
|
748
|
+
def self.gen_float(pos=false)
|
|
749
|
+
#return Float::MAX*Random.rand if pos
|
|
750
|
+
return 2**32*Random.rand if pos
|
|
751
|
+
r = Random.rand()
|
|
752
|
+
if r<0.5
|
|
753
|
+
return Float::MAX*Random.rand
|
|
754
|
+
else
|
|
755
|
+
return -1*Float::MAX*Random.rand
|
|
756
|
+
end
|
|
757
|
+
end
|
|
758
|
+
|
|
759
|
+
def self.gen_bigdec()
|
|
760
|
+
r = Random.rand()
|
|
761
|
+
if r<0.33
|
|
762
|
+
return BigDecimal.new(gen_fixnum())
|
|
763
|
+
elsif r<0.66
|
|
764
|
+
return BigDecimal.new(gen_bignum())
|
|
765
|
+
else
|
|
766
|
+
return BigDecimal.new(gen_float(),0)
|
|
767
|
+
end
|
|
768
|
+
end
|
|
769
|
+
|
|
770
|
+
def self.gen_complex(real=false,nonin=false)
|
|
771
|
+
if nonin
|
|
772
|
+
x = gen_number(0.25,0.25,0.1,0,0,0.3,0,0.1)
|
|
773
|
+
else
|
|
774
|
+
x = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
|
775
|
+
end
|
|
776
|
+
return Complex(x,0) if real
|
|
777
|
+
y = gen_number(0.2,0.2,0.1,0.05,0.05,0.3,0,0.1)
|
|
778
|
+
return Complex(x,y)
|
|
779
|
+
end
|
|
780
|
+
|
|
781
|
+
def self.gen_rational()
|
|
782
|
+
x = gen_fixnum()
|
|
783
|
+
y = gen_fixnum()
|
|
784
|
+
return Rational(x,y)
|
|
785
|
+
end
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
def self.gen_number(probFixnum,probBignum,probBigDec,probInf,probNAN,probFloat,probComplex,probRational,posfloat=false,real=false,noninfnan=false)
|
|
789
|
+
r = Random.rand()
|
|
790
|
+
if r<probFixnum then
|
|
791
|
+
#Fixnum type
|
|
792
|
+
x = gen_fixnum()
|
|
793
|
+
elsif r<(probFixnum+probBignum)
|
|
794
|
+
x = gen_bignum()
|
|
795
|
+
elsif r<(probFixnum+probBignum+probBigDec)
|
|
796
|
+
#BigDecimal type
|
|
797
|
+
x = gen_bigdec()
|
|
798
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf)
|
|
799
|
+
x=Float::INFINITY
|
|
800
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN)
|
|
801
|
+
x=Float::NAN
|
|
802
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat)
|
|
803
|
+
#Random Float type
|
|
804
|
+
x = gen_float(posfloat)
|
|
805
|
+
elsif r<(probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex)
|
|
806
|
+
x= gen_complex(real,noninfnan)
|
|
807
|
+
elsif (probFixnum+probBignum+probBigDec+probInf+probNAN+probFloat+probComplex+probRational)
|
|
808
|
+
x = gen_rational()
|
|
809
|
+
end
|
|
810
|
+
return x
|
|
811
|
+
end
|
|
812
|
+
|
|
813
|
+
def self.rounds(meth, num)
|
|
814
|
+
counter = 0
|
|
815
|
+
for i in 0..num
|
|
816
|
+
b = send(meth)
|
|
817
|
+
counter=counter+1 if !b
|
|
818
|
+
end
|
|
819
|
+
return counter
|
|
820
|
+
end
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
def self.query(q,x,y)
|
|
824
|
+
RDL.contract_switch.off {
|
|
825
|
+
if q =~ /^(\w+(#|\.))?(\w+(!|\?|=)?|!|~|\+|\*\*|-|\*|\/|%|<<|>>|&|\||\^|<|<=|=>|>|==|===|!=|=~|!~|<=>|\[\]|\[\]=)$/
|
|
826
|
+
klass = nil
|
|
827
|
+
klass_pref = nil
|
|
828
|
+
meth = nil
|
|
829
|
+
if q =~ /(.+)#(.+)/
|
|
830
|
+
klass = $1
|
|
831
|
+
klass_pref = "#{klass}#"
|
|
832
|
+
meth = $2.to_sym
|
|
833
|
+
elsif q =~ /(.+)\.(.+)/
|
|
834
|
+
klass_pref = "#{$1}."
|
|
835
|
+
klass = RDL::Util.add_singleton_marker($1)
|
|
836
|
+
meth = $2.to_sym
|
|
837
|
+
else
|
|
838
|
+
klass = self.class.to_s
|
|
839
|
+
klass_pref = "#{klass}#"
|
|
840
|
+
meth = q.to_sym
|
|
841
|
+
end
|
|
842
|
+
if RDL.info.has?(klass, meth, :type)
|
|
843
|
+
typs = RDL.info.get(klass, meth, :type)
|
|
844
|
+
typs.each { |t|
|
|
845
|
+
return [t, x.get_binding] if y.nil?
|
|
846
|
+
res, args, blk, bind = t.pre_cond?(blk, x, true, x.get_binding, y)
|
|
847
|
+
return [t, bind] if res
|
|
848
|
+
}
|
|
849
|
+
end
|
|
850
|
+
raise TypeError, "Method #{q} for argument type #{y.class} not found."
|
|
851
|
+
else
|
|
852
|
+
puts "Not implemented"
|
|
853
|
+
end
|
|
854
|
+
}
|
|
855
|
+
end
|
|
856
|
+
|
|
857
|
+
end
|
|
858
|
+
|
|
859
|
+
class Fixnum
|
|
860
|
+
|
|
861
|
+
def get_binding()
|
|
862
|
+
return binding
|
|
863
|
+
end
|
|
864
|
+
|
|
865
|
+
end
|
|
866
|
+
|
|
867
|
+
class Bignum
|
|
868
|
+
|
|
869
|
+
def get_binding()
|
|
870
|
+
return binding
|
|
871
|
+
end
|
|
872
|
+
|
|
873
|
+
end
|
|
874
|
+
|
|
875
|
+
class Rational
|
|
876
|
+
|
|
877
|
+
def get_binding
|
|
878
|
+
return binding
|
|
879
|
+
end
|
|
880
|
+
|
|
881
|
+
end
|
|
882
|
+
|
|
883
|
+
class BigDecimal
|
|
884
|
+
|
|
885
|
+
def get_binding
|
|
886
|
+
return binding
|
|
887
|
+
end
|
|
888
|
+
|
|
889
|
+
end
|
|
890
|
+
|
|
891
|
+
class Float
|
|
892
|
+
|
|
893
|
+
def get_binding
|
|
894
|
+
return binding
|
|
895
|
+
end
|
|
896
|
+
|
|
897
|
+
end
|
|
898
|
+
|
|
899
|
+
class Complex
|
|
900
|
+
|
|
901
|
+
def get_binding
|
|
902
|
+
return binding
|
|
903
|
+
end
|
|
904
|
+
|
|
905
|
+
end
|