SHARE
TWEET

Untitled

a guest Dec 3rd, 2015 149 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Run with the program you want to test as the first argument. Uses the test cases verbatim from the question.
  2.  
  3. test_cases = <<END
  4. e -> e
  5. o -> o
  6.  
  7. +ee -> e
  8. +eo -> o
  9. +oe -> o
  10. +oo -> e
  11. *ee -> e
  12. *eo -> e
  13. *oe -> e
  14. *oo -> o
  15.  
  16. +e+ee -> e
  17. +e+eo -> o
  18. +e+oe -> o
  19. +e+oo -> e
  20. +e*ee -> e
  21. +e*eo -> e
  22. +e*oe -> e
  23. +e*oo -> o
  24.  
  25. +o+ee -> o
  26. +o+eo -> e
  27. +o+oe -> e
  28. +o+oo -> o
  29. +o*ee -> o
  30. +o*eo -> o
  31. +o*oe -> o
  32. +o*oo -> e
  33.  
  34. *e+ee -> e
  35. *e+eo -> e
  36. *e+oe -> e
  37. *e+oo -> e
  38. *e*ee -> e
  39. *e*eo -> e
  40. *e*oe -> e
  41. *e*oo -> e
  42.  
  43. *o+ee -> e
  44. *o+eo -> o
  45. *o+oe -> o
  46. *o+oo -> e
  47. *o*ee -> e
  48. *o*eo -> e
  49. *o*oe -> e
  50. *o*oo -> o
  51.  
  52. ++eee -> e
  53. ++eeo -> o
  54. ++eoe -> o
  55. ++eoo -> e
  56. ++oee -> o
  57. ++oeo -> e
  58. ++ooe -> e
  59. ++ooo -> o
  60.  
  61. +*eee -> e
  62. +*eeo -> o
  63. +*eoe -> e
  64. +*eoo -> o
  65. +*oee -> e
  66. +*oeo -> o
  67. +*ooe -> o
  68. +*ooo -> e
  69.  
  70. *+eee -> e
  71. *+eeo -> e
  72. *+eoe -> e
  73. *+eoo -> o
  74. *+oee -> e
  75. *+oeo -> o
  76. *+ooe -> e
  77. *+ooo -> e
  78.  
  79. **eee -> e
  80. **eeo -> e
  81. **eoe -> e
  82. **eoo -> e
  83. **oee -> e
  84. **oeo -> e
  85. **ooe -> e
  86. **ooo -> o
  87.  
  88. +e+e+e+ee -> e
  89. +o+o+o+oo -> o
  90. *e*e*e*ee -> e
  91. *o*o*o*oo -> o
  92. +e+o+e+oe -> e
  93. +o+e+o+eo -> o
  94. *e*o*e*oe -> e
  95. *o*e*o*eo -> e
  96. +e*e+e*ee -> e
  97. +o*o+o*oo -> o
  98. *e+e*e+ee -> e
  99. *o+o*o+oo -> o
  100.  
  101. +**++*+*eeoeeooee -> e
  102. +**++*+***eooeoeooeoe -> e
  103. +**+***+**++**+eooeoeeoeeoeooeo -> o
  104.  
  105. +e*o*e**eoe -> e
  106. +*e+e+o+e**eeoe -> e
  107. **o++*ee*++eoe*eo+eoo -> o
  108. END
  109.  
  110. tests = test_cases.gsub("\n\n","\n").split("\n").map{|s| s.split(" -> ")}
  111.  
  112. name = ARGV[0] || 'even-odd.rb'
  113.  
  114. tests.each do |test,expect|
  115.   puts "#{test} -> #{expect}"
  116.   io = IO.popen("ruby #{name}",'w+')
  117.   io.puts test
  118.   if expect != io.gets.chomp
  119.     puts "failed on #{test}, expected #{expect}"
  120.     exit
  121.   end
  122. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top