Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 38 lines (33 sloc) 1.08 KB
#!/usr/bin/env ruby
require File.join(File.dirname(__FILE__), 'rle.rb')
class RLE
def self.test(str, verbose = true, type = 'string', note = nil)
puts "Testing encoder/decoder with #{type}:"
puts " #{note}" if note
puts " Start: #{Time.now}"
ret = RLE.encode(str)
puts " Encoded: #{Time.now}"
dec = RLE.decode(ret)
puts " Decoded: #{Time.now}"
if dec == str
puts " Successfully decoded"
else
puts " Could not decode"
end
puts " encoded (#{ret.length}): #{ret.inspect}" if verbose
puts " decoded (#{dec.length}): #{dec.inspect}" if verbose
puts " original (#{str.length}): #{str.inspect}" if verbose
puts " difference: #{str.length - ret.length}"
puts
end
def self.test_file(file)
test(File.open(file, 'rb').read, false, "file", "Filename: #{file}")
end
end
RLE.test("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
RLE.test("ab")
RLE.test("\x02")
RLE.test("\x02 ")
RLE.test("\x02 .")
RLE.test("#{"\x02" * 15}#{" " * 15}")
RLE.test_file(File.join(File.dirname(__FILE__), 'lorem-ipsum.txt'))
Something went wrong with that request. Please try again.