Sha256: ba2fef52227cf75ff419da2f117cb9312c0be5e8c8bf25c60a2d8ab7da4eeeaf

Contents?: true

Size: 1.39 KB

Versions: 164

Compression:

Stored size: 1.39 KB

Contents

module Tst
	def self.check(name, obj, test_string, expected_results, error_class)
		value = obj.instance_eval test_string
		unless (expected_results.class == Array ? expected_results.include?(value) : value == expected_results)
			message = "\n==============================\n"
			message += "=        Test Failed         =\n"
			message += "==============================\n\n"
			message += "Object Description: #{name}\n"
			message += "Object Value: #{obj.inspect}\n"
			message += "Test: #{test_string.inspect}\n" 
			message += "Expected Result:  #{expected_results}\n"
			message += "Actual Result: #{value.inspect}"
			message += "\n\n==============================="
			raise error_class.new(message)
		end
	end

	class TestProc < Proc
		alias :test :call
	end
	class MakeProc < Proc
		alias :with_result :call
	end
	
	#MakeProcs - used for making tests
	KIND_OF = MakeProc.new{|*klasses| TestProc.new{|obj, name=""| check(name, obj, klasses.inject(""){|str, klass| str << " or self.kind_of? #{klass.to_s}"}.sub(/^ or /, '') , true, TypeError)}}
	VALUE = MakeProc.new{|*values| TestProc.new{|obj, name=""| check(name, obj, "self", values, ArgumentError)}}

	#Some predefined tests
	FLOAT = KIND_OF.with_result(Float, Integer)
	FLOAT_STRICT = KIND_OF.with_result(Float)
	INT= INTEGER = KIND_OF.with_result(Integer)
	STRING = KIND_OF.with_result(String)
	FORTRAN_BOOL = VALUE.with_result(*String::FORTRAN_BOOLS)
end

Version data entries

164 entries across 164 versions & 1 rubygems

Version Path
coderunner-0.14.10 lib/coderunner/test.rb
coderunner-0.14.9 lib/coderunner/test.rb
coderunner-0.14.8 lib/coderunner/test.rb
coderunner-0.14.7 lib/coderunner/test.rb
coderunner-0.14.6 lib/coderunner/test.rb
coderunner-0.14.5 lib/coderunner/test.rb
coderunner-0.14.4 lib/coderunner/test.rb
coderunner-0.14.3 lib/coderunner/test.rb
coderunner-0.14.2 lib/coderunner/test.rb
coderunner-0.14.1 lib/coderunner/test.rb
coderunner-0.14.0 lib/coderunner/test.rb
coderunner-0.13.32 lib/coderunner/test.rb
coderunner-0.13.31 lib/coderunner/test.rb
coderunner-0.13.30 lib/coderunner/test.rb
coderunner-0.13.29 lib/coderunner/test.rb
coderunner-0.13.28 lib/coderunner/test.rb
coderunner-0.13.27 lib/coderunner/test.rb
coderunner-0.13.26 lib/coderunner/test.rb
coderunner-0.13.25 lib/coderunner/test.rb
coderunner-0.13.24 lib/coderunner/test.rb