brainfuck: cleanup tests.

db4
John Benediktsson 2014-12-26 19:20:11 -08:00
parent 167f4e789c
commit b2dec21d3e
1 changed files with 53 additions and 32 deletions

View File

@ -1,9 +1,10 @@
! Copyright (C) 2009 John Benediktsson ! Copyright (C) 2009 John Benediktsson
! See http://factorcode.org/license.txt for BSD license ! See http://factorcode.org/license.txt for BSD license
USING: brainfuck kernel io.streams.string math math.parser math.ranges USING: brainfuck io.streams.string kernel literals math
quotations sequences tools.test ; math.parser math.ranges sequences tools.test ;
IN: brainfuck.tests
IN: brainfuck
[ "+" run-brainfuck ] must-infer [ "+" run-brainfuck ] must-infer
@ -11,54 +12,74 @@ IN: brainfuck.tests
! Hello World! ! Hello World!
[ "Hello World!\n" ] [ """++++++++++[>+++++++>++++++++++>+++>+<<<<-] { "Hello World!\n" } [
>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++. """
------.--------.>+.>.""" get-brainfuck ] unit-test ++++++++++[>+++++++>++++++++++>+++>+<<<<-]
>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.
------.--------.>+.>.
""" get-brainfuck
] unit-test
! Addition (single-digit) ! Addition (single-digit)
[ "8" ] [ "35" [ ",>++++++[<-------->-],[<+>-]<." { "8" } [
get-brainfuck ] with-string-reader ] unit-test "35" [
",>++++++[<-------->-],[<+>-]<." get-brainfuck
] with-string-reader
] unit-test
! Multiplication (single-digit) ! Multiplication (single-digit)
[ "8\0" ] [ "24" [ """,>,>++++++++[<------<------>>-] { "8\0" } [
<<[>[>+>+<<-]>>[<<+>>-]<<<-] "24" [
>>>++++++[<++++++++>-],<.>.""" """
get-brainfuck ] with-string-reader ] unit-test ,>,>++++++++[<------<------>>-]
<<[>[>+>+<<-]>>[<<+>>-]<<<-]
>>>++++++[<++++++++>-],<.>.
""" get-brainfuck
] with-string-reader
] unit-test
! Division (single-digit, integer) ! Division (single-digit, integer)
[ "3" ] [ "62" [ """,>,>++++++[-<--------<-------->>] { "3" } [
<<[ "62" [
>[->+>+<<] """
>[-<<- ,>,>++++++[-<--------<-------->>]
[>]>>>[<[>>>-<<<[-]]>>]<<] <<[
>>>+ >[->+>+<<]
<<[-<<+>>] >[-<<-
<<<] [>]>>>[<[>>>-<<<[-]]>>]<<]
>[-]>>>>[-<<<<<+>>>>>] >>>+
<<<<++++++[-<++++++++>]<.""" <<[-<<+>>]
get-brainfuck ] with-string-reader ] unit-test <<<]
>[-]>>>>[-<<<<<+>>>>>]
<<<<++++++[-<++++++++>]<.
""" get-brainfuck
] with-string-reader
] unit-test
! Uppercase ! Uppercase
[ "A" ] [ "a\n" [ ",----------[----------------------.,----------]" { "A" } [ "a\n" [ ",----------[----------------------.,----------]"
get-brainfuck ] with-string-reader ] unit-test get-brainfuck ] with-string-reader ] unit-test
! cat ! cat
[ "ABC" ] [ "ABC\0" [ ",[.,]" get-brainfuck ] with-string-reader ] unit-test { "ABC" } [ "ABC\0" [ ",[.,]" get-brainfuck ] with-string-reader ] unit-test
! Squares of numbers from 0 to 100 ! Squares of numbers from 0 to 100
100 [0,b] [ dup * number>string ] map "\n" join "\n" append 1quotation ${ 100 [0,b] [ dup * number>string ] map "\n" join "\n" append }
[ """++++[>+++++<-]>[<+++++>-]+<+[ [
>[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+ """
>>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<] ++++[>+++++<-]>[<+++++>-]+<+[
<<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++> >[>+>+<<-]++>>[<<+>>-]>>>[-]++>[-]+
[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]""" >>>+[[-]++++++>>>]<<<[[<++++++++<++>>-]+<.<[>----<-]<]
get-brainfuck ] unit-test <<[>>>>>[>>>[-]+++++++++<[>-<-]+++++++++>
[-[<->-]+[<<<]]<[>+<-]>]<<-]<<-]
""" get-brainfuck
] unit-test
! fun with numbers: 2 + 2 = 5 ! fun with numbers: 2 + 2 = 5