source: trunk/Examples/Others/tests.b

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