Diff

Differences From Artifact [ecd601a44e]:

To Artifact [76f99cbcd6]:


1
2
3



4
5
6
7
8
9
10
..
16
17
18
19
20
21
22
23
24

25
26
27
28
29
30

































































package fibonacci

import (



	"testing"
)

func TestNumbers(t *testing.T) {
	n := New(32)

	expected := []uint64{1, 1, 2, 3, 5, 8, 13, 21}
................................................................................
		}
	}
}

func TestCoding(t *testing.T) {
	n := New(32)

	for i := uint64(0); i < 1024; i++ {
		enc := n.Code(i)

		dec := n.Decode(enc)
		if i != dec {
			t.Errorf("Unexpected value for %d - enc is %b, dec is %d\n", i, enc, dec)
		}
	}
}




































































>
>
>







 







|
|
>
|





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package fibonacci

import (
	"bytes"
	"fmt"
	"io"
	"testing"
)

func TestNumbers(t *testing.T) {
	n := New(32)

	expected := []uint64{1, 1, 2, 3, 5, 8, 13, 21}
................................................................................
		}
	}
}

func TestCoding(t *testing.T) {
	n := New(32)

	for i := uint64(0); i < 4096; i++ {
		enc, _ := n.Code(i)
		//fmt.Printf("%d - %b, %d\n", i, enc, len)
		dec, _ := n.Decode(enc)
		if i != dec {
			t.Errorf("Unexpected value for %d - enc is %b, dec is %d\n", i, enc, dec)
		}
	}
}

func TestWriter0(t *testing.T) {
	var buf bytes.Buffer
	var w io.Writer = Writer(&buf)

	w.Write([]byte{0})
	w.Write(nil)
	for _, v := range buf.Bytes() {
		fmt.Printf("%s-", b2s(v))
	}
	fmt.Println()
}

func TestWriter1(t *testing.T) {
	var buf bytes.Buffer
	var w io.Writer = Writer(&buf)

	w.Write([]byte{0, 1})
	w.Write(nil)
	for _, v := range buf.Bytes() {
		fmt.Printf("%s-", b2s(v))
	}
	fmt.Println()
}

func TestWriter2(t *testing.T) {
	var buf bytes.Buffer
	var w io.Writer = Writer(&buf)

	w.Write([]byte{0, 1, 2})
	w.Write(nil)
	for _, v := range buf.Bytes() {
		fmt.Printf("%s-", b2s(v))
	}
	fmt.Println()
}

func TestWriter3(t *testing.T) {
	var buf bytes.Buffer
	var w io.Writer = Writer(&buf)

	var input []byte = make([]byte, 256)
	for i := 0; i < 256; i++ {
		input[i] = byte(i)
	}

	w.Write(input)
	w.Write(nil)
	for _, v := range buf.Bytes() {
		fmt.Printf("%s-", b2s(v))
	}
	fmt.Println()
}

func b2s(b byte) (result string) {
	for i := 0; i < 8; i++ {
		if b&1 > 0 {
			result += "1"
		} else {
			result += "0"
		}
		b >>= 1
	}
	return
}