Skip to content

Instantly share code, notes, and snippets.

@icem
Created May 12, 2011 17:47
Show Gist options
  • Save icem/969050 to your computer and use it in GitHub Desktop.
Save icem/969050 to your computer and use it in GitHub Desktop.
# Script for testing disk drive
# Usage: ruby random_stream_test.rb filepath [ size ]
FILENAME = ARGV.first
n = ARGV.last.to_i || 1000
puts "Start writing #{n} lines to file '#{FILENAME}'..."
File.open(FILENAME, "w") do |file|
n.times do
str = ''
100000.times { str << 97 + rand(26) } #Generation long random string
file.puts str
file.puts str.hash
end
end
puts "Start reading with veryfying..."
File.open(FILENAME, "r") do |file|
counter = 0
hash = nil
while (line = file.gets)
counter+=1
if (counter.even?)
print(hash == line.to_i ? "+" : "-")
else
hash = line.strip.hash
end
end
puts "\nSize ok" if counter == 2*n
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment