module RubyQC FixnumMax = 2 ** (0.size * 8 - 2) - 1 FixnumMin = - FixnumMax - 1 FixnumSuc = FixnumMax + 1 BignumMax = FixnumMax * 10 BignumMin = FixnumMin * 10 end ### ### default implementation ### module Kernel def rubyqc self end end class Class def rubyqc new end end ### ### class level implementation ### class NilClass def self.rubyqc nil end end class TrueClass def self.rubyqc true end end class FalseClass def self.rubyqc false end end class Proc def self.rubyqc lambda{ Class.rubyqc.rubyqc } end end class Method def self.rubyqc obj = Class.rubyqc.rubyqc obj.method(obj.methods.sample) end end class UnboundMethod def self.rubyqc klass = Class.rubyqc klass.instance_method(klass.instance_methods.sample) end end # TODO class Binding def self.rubyqc binding end end # TODO class Symbol def self.rubyqc String.rubyqc.to_sym end end class Encoding def self.rubyqc list.sample end end # TODO class Dir def self.rubyqc Dir.open(__dir__) end end class File def self.rubyqc File.open(__FILE__) end end class IO def self.rubyqc pipe.sample end end # TODO class String def self.rubyqc /.*/.rubyqc end end class Regexp def self.rubyqc new(String.rubyqc) end end class MatchData def self.rubyqc String.rubyqc.match(Regexp.rubyqc) end end class Class def self.rubyqc Object.constants.map{ |name| unless [:Class, :BasicObject, :Data, :Config, :RubyVM, :TracePoint].include?(name) const_get(name) end }.select{ |const| const.kind_of?(Class) }.sample end end # TODO: why? # class Object # def self.rubyqc # Class.rubyqc.rubyqc # end # end class Fixnum def self.rubyqc (RubyQC::FixnumMin..RubyQC::FixnumMax).rubyqc end end class Bignum def self.rubyqc case (0..1).rubyqc when 0 (RubyQC::BignumMin...RubyQC::FixnumMin).rubyqc when 1 (RubyQC::FixnumSuc...RubyQC::BignumMax).rubyqc else raise "huh?" end end end class Integer def self.rubyqc [Bignum, Fixnum].sample.rubyqc end end class Complex def self.rubyqc Fixnum.rubyqc + Fixnum.rubyqc.i end end class Rational def self.rubyqc Rational(Fixnum.rubyqc, Fixnum.rubyqc) end end class Range def self.rubyqc new(*[Fixnum.rubyqc, Fixnum.rubyqc].sort) end end class Enumerator def self.rubyqc Array.rubyqc.to_enum end end # TODO class Float def self.rubyqc rand end end class Thread::SizedQueue def self.rubyqc new(rand(0..100)) end end class Fiber def self.rubyqc new(&Proc.rubyqc) end end class Thread def self.rubyqc new(&Proc.rubyqc) end end class SignalException def self.rubyqc new(rand(0..32)) end end class SystemCallError def self.rubyqc new(rand(1..106)) end end class Struct def self.rubyqc new(Symbol.rubyqc) end end ### ### instance level implementation ### class Array def rubyqc map(&:rubyqc) end end class Hash def rubyqc inject({}){ |r, (k, v)| r[k] = v.rubyqc; r } end end class Range def rubyqc rand(self.begin..self.end) end end # TODO class Regexp def rubyqc 'rubyqc...' end end