Diff

Differences From Artifact [0734e0cdf2]:

To Artifact [33c293fd3b]:


1
2
3

4
5
6
7
8
9
10
..
32
33
34
35
36
37
38
39

40
41
42
43


44
45
46
47
48
49
50
..
73
74
75
76
77
78
79
















80
81
82
83
84
85
86
87
88
89
90
91
92
package fibonacci

import (

	"bytes"
	"io"
	"strings"
	"testing"
)

func TestNumbers(t *testing.T) {
................................................................................
		}
		if encLen != decLen {
			t.Errorf("Unexpected difference between encoded and decoded lengths.", encLen, decLen)
		}
	}
}

func TestWriter(t *testing.T) {

	var buf bytes.Buffer
	var w io.Writer = Writer(&buf)
	var input []byte = make([]byte, 256)
	var fib Numbers = New(16)



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

	// Write the input
	count, err := w.Write(input)
................................................................................
		c, l := fib.Code(uint64(v))
		vs := u2s(c, l)
		if loc := strings.Index(output, vs); loc != 0 {
			t.Fatal("Unexpected location for", i, "value", vs)
		}
		output = output[len(vs):]
	}
















}

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



>







 







|
>
|
|
|
<
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>













1
2
3
4
5
6
7
8
9
10
11
..
33
34
35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
52
53
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package fibonacci

import (
	diff "0dev.org/diff"
	"bytes"
	"io"
	"strings"
	"testing"
)

func TestNumbers(t *testing.T) {
................................................................................
		}
		if encLen != decLen {
			t.Errorf("Unexpected difference between encoded and decoded lengths.", encLen, decLen)
		}
	}
}

func TestWriterReader(t *testing.T) {
	var (
		buf   bytes.Buffer
		w     io.Writer = Writer(&buf)
		input []byte    = make([]byte, 256)

		fib   Numbers   = New(16)
	)

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

	// Write the input
	count, err := w.Write(input)
................................................................................
		c, l := fib.Code(uint64(v))
		vs := u2s(c, l)
		if loc := strings.Index(output, vs); loc != 0 {
			t.Fatal("Unexpected location for", i, "value", vs)
		}
		output = output[len(vs):]
	}

	var (
		in  *bytes.Reader = bytes.NewReader(buf.Bytes())
		r   io.Reader     = Reader(in)
		out bytes.Buffer
	)
	io.Copy(&out, r)
	decoded := out.Bytes()

	delta := diff.Diff(diff.D{Len1: len(decoded), Len2: len(input), EqualFunc: func(i, j int) bool {
		return decoded[i] == input[j]
	}})

	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
		t.Error("Differences detected ", delta)
	}
}

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