Esempio n. 1
0
func diffLineSet(orgLines, newLines []string, format string) {
	sort.Strings(orgLines)
	sort.Strings(newLines)

	_, matA, matB := ed.EditDistanceFFull(len(orgLines), len(newLines), func(iA, iB int) int {
		return tm.DiffOfStrings(orgLines[iA], newLines[iB], 4000)
	}, ed.ConstCost(1000), ed.ConstCost(1000))

	for i, j := 0, 0; i < len(orgLines) || j < len(newLines); {
		switch {
		case j >= len(newLines) || i < len(orgLines) && matA[i] < 0:
			showDelLine(fmt.Sprintf(format, orgLines[i]))
			i++
		case i >= len(orgLines) || j < len(newLines) && matB[j] < 0:
			showInsLine(fmt.Sprintf(format, newLines[j]))
			j++
		default:
			if strings.TrimSpace(orgLines[i]) != strings.TrimSpace(newLines[j]) {
				showDiffLine(fmt.Sprintf(format, orgLines[i]), fmt.Sprintf(format, newLines[j]))
			} // if
			i++
			j++
		}
	} // for i, j
}
Esempio n. 2
0
func TestGreedyMatch(t *testing.T) {
	_, _, matA, matB := GreedyMatch(2, 2, func(iA, iB int) int {
		if iA == 1 && iB == 0 {
			return 1
		} // if

		return 40
	}, ed.ConstCost(10), ed.ConstCost(10))

	if !villa.IntSlice(matA).Equals([]int{-1, 0}) {
		t.Errorf("matA should be [-1, 0]")
	} // if
	if !villa.IntSlice(matB).Equals([]int{1, -1}) {
		t.Errorf("matA should be [1, -1]")
	} // if
}