go/brainfuck

log tags | changeset raw browse | file diff annotate file log raw

view bf_test.go @ 2:ddcf4bca3fd6

Capitalized
author yiyus@1936
date Tue Nov 24 20:31:30 2009 +0100 (2009-11-24 ago)
parents fb4dee2a5872
children

1 // Copyright 2009 JGL
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package brainfuck
7 import (
8 "fmt";
9 "strings";
10 "testing";
11 )
13 func TestHelloWorld(t *testing.T) {
14 prog := strings.Bytes("\
15 ++++++++++[>+++++++>++++++++++>+++>+<<<<-]\
16 >++.>+.+++++++..+++.>++.<<+++++++++++++++.\
17 >.+++.------.--------.>+.>.!");
18 bf := BrainFucker(prog, 30000);
19 for {
20 b, ok := <-bf.Out;
21 if !ok {
22 return;
23 }
24 fmt.Print(string(b));
25 }
26 }
28 func TestAddition(t *testing.T) {
29 prog := strings.Bytes(",>++++++[<-------->-],[<+>-]<.");
30 bf := BrainFucker(prog, 30000);
31 bi := "43";
32 i := 0;
33 for {
34 oki := i<len(bi);
35 if oki {
36 bf.In <- bi[i];
37 i++;
38 }
39 b, oko := <-bf.Out;
40 if oko {
41 fmt.Print(string(b));
42 }
43 if !oki && !oko {
44 break;
45 }
46 }
47 }