Diff

Differences From Artifact [efb3f6ccdb]:

To Artifact [8e70ad85db]:


3
4
5
6
7
8
9





















10
11
12
13
14
15
16

17
18
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


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






















func TestEncoder(t *testing.T) {
	var (
		input    []byte = []byte{1, 1, 0, 0}
		expected []byte = []byte{1, 0, 1, 0}

		buffer  bytes.Buffer
		encoder io.Writer = Encoder(&buffer)

	)

	count, err := encoder.Write(input)
	if count != len(input) {
		t.Error("Unexpected write count from encoder", count)
	}

	if err != nil {
		t.Error("Unexpected write error from encoder", err)

	}

	output := buffer.Bytes()

	// Diff the output against the expected result
	delta := diff.Diff(diff.D{Len1: len(expected), Len2: len(output),
		EqualFunc: func(i, j int) bool { return expected[i] == output[j] }})
	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
		t.Error("Differences detected ", delta)


	}
}

func TestDecoder(t *testing.T) {
	var (
		input    []byte = []byte{1, 0, 1, 0}
		expected []byte = []byte{1, 1, 0, 0}
		output   []byte = make([]byte, 4)

		reader  *bytes.Reader = bytes.NewReader(input)
		decoder io.Reader     = Decoder(reader)

	)

	count, err := decoder.Read(output)
	if count != len(output) {
		t.Error("Unexpected read count from decoder", count)
	}

	if err != nil {
		t.Error("Unexpected read error from decoder", err)

	}

	// Diff the output against the expected result
	delta := diff.Diff(diff.D{Len1: len(expected), Len2: len(output),
		EqualFunc: func(i, j int) bool { return expected[i] == output[j] }})
	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
		t.Error("Differences detected ", delta)
	}
}









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|

|
|
>
|
<
|
|
|
<
>
|
|
>
|
<
|

|
|
|
|
|
>
>
|
<
<
|
|
|
|
|

|
|
>
|
<
|
|
|
<
>
|
|
>
|
<
|
|
|
|
|
<
<
>
>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
import (
	diff "0dev.org/diff"
	"bytes"
	"io"
	"testing"
)

func TestMTF(t *testing.T) {
	var (
		data []byte = []byte{1, 1, 0, 0}

		input   *bytes.Reader = bytes.NewReader(data)
		encoder io.Reader     = Encoder(input)
		decoder io.Reader     = Decoder(encoder)

		output bytes.Buffer
	)

	io.Copy(&output, decoder)
	processed := output.Bytes()

	delta := diff.Diff(diff.D{Len1: len(data), Len2: len(processed),
		EqualFunc: func(i, j int) bool { return data[i] == processed[j] }})
	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
		t.Error("Differences detected ", delta)
	}
}

// func TestEncoder(t *testing.T) {
// 	var (
// 		input    []byte = []byte{1, 1, 0, 0}
// 		expected []byte = []byte{1, 0, 1, 0}

// 		buffer  bytes.Buffer
// 		encoder io.Writer = Encoder(&buffer)
// 	)


// 	count, err := encoder.Write(input)
// 	if count != len(input) {
// 		t.Error("Unexpected write count from encoder", count)

// 	}
// 	if err != nil {
// 		t.Error("Unexpected write error from encoder", err)
// 	}


// 	output := buffer.Bytes()

// 	// Diff the output against the expected result
// 	delta := diff.Diff(diff.D{Len1: len(expected), Len2: len(output),
// 		EqualFunc: func(i, j int) bool { return expected[i] == output[j] }})
// 	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
// 		t.Error("Differences detected ", delta)
// 	}
// }



// func TestDecoder(t *testing.T) {
// 	var (
// 		input    []byte = []byte{1, 0, 1, 0}
// 		expected []byte = []byte{1, 1, 0, 0}
// 		output   []byte = make([]byte, 4)

// 		reader  *bytes.Reader = bytes.NewReader(input)
// 		decoder io.Reader     = Decoder(reader)
// 	)


// 	count, err := decoder.Read(output)
// 	if count != len(output) {
// 		t.Error("Unexpected read count from decoder", count)

// 	}
// 	if err != nil {
// 		t.Error("Unexpected read error from decoder", err)
// 	}


// 	// Diff the output against the expected result
// 	delta := diff.Diff(diff.D{Len1: len(expected), Len2: len(output),
// 		EqualFunc: func(i, j int) bool { return expected[i] == output[j] }})
// 	if len(delta.Added) > 0 || len(delta.Removed) > 0 {
// 		t.Error("Differences detected ", delta)


// 	}
// }