require 'stringio'
require 'timeout'
require "./run.rb"

special_things = '$ ! > , : ; ] } } { f F m M i I e E nil del superpad implicit input version type show set let del = 1,2,3 0,0 1,2,,3,4 "asdf" "" 1000'.split

all = ["\n",*' '..'~'] + special_things*3 + 'i I e E m M f F > > > > > > > > >, >, >, >,, >,, >,,'.split * 20

# todo idea: take all tests and make larger programs that are almost correct
# todo check that value matches type

n = 2000000

7.upto(10){|program_size|
  ([all.size**program_size,n].min).times{|i|
    input = ["","\n","ab12","12","1 2","1 2\n3","c","ab\n\n2"].sample

    program = program_size.times.map{ all.sample }*(rand(2)==1 ? "" : " ")
    $stdout = StringIO.new("")
    begin
      STDERR.puts "program: " + program
      STDERR.puts "input: " + input
      Timeout::timeout(0.01) {
        run_and_do_io(program, StringIO.new(input), false, false)
      }
    rescue IogiiError,Timeout::Error => e
#       STDERR.puts e.message
    rescue => e
      STDERR.puts "failed, program was:"
      STDERR.puts program
      raise e
    end
  }
}

STDOUT.puts "pass fuzz test"