-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruby_check.rb
More file actions
47 lines (36 loc) · 959 Bytes
/
ruby_check.rb
File metadata and controls
47 lines (36 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Ruby_check
srand
# Generators for handled types
# @params obj: Sample object with constraints bound to eigenclass
def Fixnum_gen(obj)
return rand(obj.instance_variable_get(:@domain))
end
def Float_gen(obj)
return rand() * Fixnum_gen(obj)
end
def Char_gen(obj)
return rand(obj.instance_variable_get(:@charset)).chr
end
def String_gen(obj)
tempStr = ""
rand(obj.instance_variable_get(:@len_domain)).times {tempStr += Char_gen(obj)}
return tempStr
end
def Numeric_gen(obj)
case rand(2)
when 0 then return Fixnum_gen(obj)
when 1 then return Float_gen(obj)
end
end
def Symbol_gen(obj)
return String_gen(obj).to_sym
end
def respond_to?(method)
super.respond_to?
end
# Handles generators for user-defined or non-primitive types
def method_missing(method, sym, *x, &blk)
kInstance = sym.to_s.split('::').inject(Object) {|parent,child| parent.const_get(child)}
return kInstance.new(*x,&blk)
end
end