/examples/bench/tests.bf

https://github.com/FabianM/brainfuck · Brainfuck · 68 lines · 50 code · 18 blank · 0 comment · 11 complexity · 30406397e618704fd7e0555270c378a4 MD5 · raw file

  1. Here are some little programs for testing brainfuck implementations.
  2. >,>+++++++++,>+++++++++++[<++++++<++++++<+>>>-]<<.>.<<-.>.>.<<.
  3. This is for testing i/o; give it a return followed by an EOF. (Try it both
  4. with file input--a file consisting only of one blank line--and with
  5. keyboard input, i.e. hit return and then ctrl-d (Unix) or ctrl-z
  6. (Windows).)
  7. It should give two lines of output; the two lines should be identical, and
  8. should be lined up one over the other. If that doesn't happen, ten is not
  9. coming through as newline on output.
  10. The content of the lines tells how input is being processed; each line
  11. should be two uppercase letters.
  12. Anything with O in it means newline is not coming through as ten on input.
  13. LK means newline input is working fine, and EOF leaves the cell unchanged
  14. (which I recommend).
  15. LB means newline input is working fine, and EOF translates as 0.
  16. LA means newline input is working fine, and EOF translates as -1.
  17. Anything else is fairly unexpected.
  18. ++++[>++++++<-]>[>+++++>+++++++<<-]>>++++<[[>[[>>+<<-]<]>>>-]>-[>+>+<<-]>]
  19. +++++[>+++++++<<++>-]>.<<.
  20. Goes to cell 30000 and reports from there with a #. (Verifies that the
  21. array is big enough.)
  22. These next two test the array bounds checking. Bounds checking is not
  23. essential, and in a high-level implementation it is likely to introduce
  24. extra overhead. In a low-level implementation you can get bounds checking
  25. for free by using the OS's own memory protections; this is the best
  26. solution, which may require making the array size a multiple of the page
  27. size.
  28. Anyway. These two programs measure the "real" size of the array, in some
  29. sense, in cells left and right of the initial cell respectively. They
  30. output the result in unary; the easiest thing is to direct them to a file
  31. and measure its size, or (on Unix) pipe the output to wc. If bounds
  32. checking is present and working, the left should measure 0 and the right
  33. should be the array size minus one.
  34. +[<+++++++++++++++++++++++++++++++++.]
  35. +[>+++++++++++++++++++++++++++++++++.]
  36. []++++++++++[>++++++++++++++++++>+++++++>+<<<-]A;?@![#>>+<<]>[>++<[-]]>.>.
  37. Tests for several obscure problems. Should output an H.
  38. +++++[>+++++++>++<<-]>.>.[
  39. Should ideally give error message "unmatched [" or the like, and not give
  40. any output. Not essential.
  41. +++++[>+++++++>++<<-]>.>.][
  42. Should ideally give error message "unmatched ]" or the like, and not give
  43. any output. Not essential.
  44. My pathological program rot13.b is good for testing the response to deep
  45. brackets; the input "~mlk zyx" should produce the output "~zyx mlk".
  46. For an overall stress test, and also to check whether the output is
  47. monospaced as it ideally should be, I would use Linus Akesson's game of
  48. life and/or my numwarp.b.
  49. Daniel B Cristofani (cristofdathevanetdotcom)
  50. http://www.hevanet.com/cristofd/brainfuck/