Diff

Differences From Artifact [6f1c8e9901]:

To Artifact [210041c492]:


1
2
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

1
2
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



-
-
+
+



+





+




+




-
+
-
-





-
-
+
+
+
+
+
+
+
+
-
-


-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+

-
-
-
+
+
+
-
-
+
+

-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
+
+
+
-
-
+
+
-
+
package diff

import (
	bits "0dev.org/bits"
	"fmt"
	_ "0dev.org/bits"
	_ "fmt"
	"testing"
)

// A diff.Interface implementation for testing purposes
type diffSlice struct {
	first  []rune
	second []rune
}

// Required per diff.Interface
func (d diffSlice) Len() (int, int) {
	return len(d.first), len(d.second)
}

// Required per diff.Interface
func (d diffSlice) Equal(i, j int) bool {
	return d.first[i] == d.second[j]
}

func TestLCS(t *testing.T) {
func TestDiff(t *testing.T) {
	fmt.Println("")

	data := diffSlice{
		[]rune("abcdefgh"),
		[]rune("abbcedfh"),
	}

	fmt.Println(Diff(data))

	result := Diff(data)
	if len(result.Added) != 2 ||
		result.Added[0].From != 2 || result.Added[0].Length != 3 ||
		result.Added[1].From != 5 || result.Added[1].Length != 6 ||
		result.Removed[0].From != 3 || result.Removed[0].Length != 4 ||
		result.Removed[1].From != 6 || result.Removed[1].Length != 7 {
		t.Error("Unexpected diff results", result)
	}
	// first, second, total := LCS(data)
	// fmt.Println(first, second, total)
}

func TestWTF(t *testing.T) {
	data := diffSlice{
		[]rune("abcdefgh"),
		[]rune("abbcedfh"),
	}
// func TestWTF(t *testing.T) {
// 	data := diffSlice{
// 		[]rune("abcdefgh"),
// 		[]rune("abbcedfh"),
// 	}


	var len1, len2 int = data.Len()
	var mat matrix = matrix{v: bits.NewBool(uint(len1 * len2)), lenX: len1, lenY: len2}
// 	var len1, len2 int = data.Len()
// 	var mat matrix = matrix{v: bits.NewBool(uint(len1 * len2)), lenX: len1, lenY: len2}

	for i := 0; i < len1; i++ {
		for j := 0; j < len2; j++ {
			mat.v.Poke(mat.at(i, j), data.Equal(i, j))
// 	for i := 0; i < len1; i++ {
// 		for j := 0; j < len2; j++ {
// 			mat.v.Poke(mat.at(i, j), data.Equal(i, j))
		}
	}
// 		}
// 	}

	debugPrint(box{5, 5, 6, 6}, mat)
	debugPrint(box{5, 5, 7, 7}, mat)
	debugPrint(box{5, 5, 8, 8}, mat)
}
// 	debugPrint(box{5, 5, 6, 6}, mat) // visual debugging as its finest
// 	debugPrint(box{5, 5, 7, 7}, mat)
// 	debugPrint(box{5, 5, 8, 8}, mat) // ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN.
// }


func debugPrint(bounds box, mat matrix) {
	// Debug print
	fmt.Printf("-%d-%d--%d-%d--\n", bounds.x, bounds.y, bounds.lenX, bounds.lenY)
	for i := bounds.x; i < bounds.lenX; i++ {
		fmt.Print("| ")
		for j := bounds.y; j < bounds.lenY; j++ {
			//if vector.Peek(uint(j + (i * bounds.lenY))) {
			if mat.v.Peek(mat.at(i, j)) {
				fmt.Print("\\")
			} else {
				fmt.Print(".")
// func debugPrint(bounds box, mat matrix) {
// 	// Debug print
// 	fmt.Printf("-%d-%d--%d-%d--\n", bounds.x, bounds.y, bounds.lenX, bounds.lenY)
// 	for i := bounds.x; i < bounds.lenX; i++ {
// 		fmt.Print("| ")
// 		for j := bounds.y; j < bounds.lenY; j++ {
// 			//if vector.Peek(uint(j + (i * bounds.lenY))) {
// 			if mat.v.Peek(mat.at(i, j)) {
// 				fmt.Print("\\")
// 			} else {
// 				fmt.Print(".")
			}
		}
		fmt.Println(" |")
// 			}
// 		}
// 		fmt.Println(" |")
	}
	fmt.Println("------------")
// 	}
// 	fmt.Println("------------")
}
// }