⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 difftestcode.vb

📁 an lcs algorithm for finding common string
💻 VB
字号:
#If DEBUG Then
Namespace We.See.Diff

    Public Class DiffTestCode

        Private Shared tested As New List(Of String)

        Public Shared Sub TestDiff()

            test1("", "abc")
            test1("aaa", "baaa")
            test1("aaabb", "bbaaa")
            test1("aaabb", "abbaa")
            test1("aaabbc", "acbbaa")
            test1("aaabbc", "abcbaa")
            ' test: move one char forward, another back, intersecting
            ' aabffggcccde -> aaffdggbccce

            Dim tests As String(,) = New String(,) {{"empty", "", ""}, _
                                                    {"add", "aaa", "aaabb"}, _
                                                    {"add2", "aaa", "aabab"}, _
                                                    {"remove", "cccdd", "ccc"}, _
                                                    {"remove2", "cccdd", "ccd"}, _
                                                    {"move", "eeeff", "eeffe"}, _
                                                    {"move2", "eeefF", "eeFfe"}, _
                                                    {"move2", "eeefF", "eFefe"}, _
                                                    {"replace", "ggggg", "ghhgg"}, _
                                                    {"replace2", "ggggg", "Hghgg"}, _
                                                    {"intersect", "aabffggcccde", "aaffdggbccce"}}

            Dim a As String
            Dim b As String

            For i As Integer = 0 To UBound(tests, 1)
                For j As Integer = 0 To UBound(tests, 1)
                    a = tests(i, 1) & tests(j, 1)
                    b = tests(i, 2) & tests(j, 2)
                    test1(a, b)
                    a = tests(i, 1) & tests(j, 2)
                    b = tests(i, 2) & tests(j, 1)
                    test1(a, b)
                Next
            Next

        End Sub

        Private Shared Function Split(ByVal value As String) As String()
            Return value.ToList.ConvertAll(Of String)(Function(x) x).ToArray
        End Function

        Private Shared Function Join(ByVal value As String()) As String
            Return String.Join("", value)
        End Function

        Private Shared Sub test1(ByVal a As String, ByVal b As String)
            test1b(Split(a), Split(b))
            test1b(Split(b), Split(a))
            Dim c As String() = Split(a)
            c.Reverse()
            Dim d As String() = Split(b)
            d.Reverse()
            test1b(c, d)
            test1b(d, c)
            test1b(Split(a), c)
            test1b(Split(b), c)
            test1b(Split(a), d)
            test1b(Split(b), d)
        End Sub

        Private Shared Sub test1b(ByVal a As String(), ByVal b As String())
            Try
                Dim test As String = Join(a) & "," & Join(b)
                If Not tested.Contains(test) Then
                    tested.Add(test)
                    test1(a, b)
                End If
            Catch ex As Exception
                Debug.WriteLine("ex:" & ex.Message)
            End Try
        End Sub


        Private Shared Sub test1(ByVal a As String(), ByVal b As String())

            Dim script As DiffScript(Of String)
            script = DiffEngine(Of String).MakeDiffScript(a, b)

            Dim r1 As List(Of String) = a.ToList
            Dim r2 As List(Of String) = a.ToList
            'Dim r3 As List(Of String) = a.ToList

            Dim firstprint As String = script.print

            script.ApplyTo(r1)
            script.Interpret()
            script.ApplyTo(r2)

            'script.Reverse() ' make sure the reversing of the diffscript does not affect the result
            'script.ApplyTo(r3)' (this is not supported)

            Debug.WriteLine(String.Format("{3} a:{0} b:{1} r:{2} d:{4}", Join(a), Join(b), Join(r2.ToArray), Join(r2.ToArray) = Join(b), script.print2))

            'Debug.WriteLine(Join(r1.ToArray))

            'Debug.WriteLine(Join(r2.ToArray))
            'Debug.WriteLine(Join(b))

            'Debug.WriteLine(firstprint)
            'Debug.WriteLine(script.print)

            'Debug.Assert(Join(r1.ToArray) = Join(b))
            'Debug.Assert(Join(r2.ToArray) = Join(b))

        End Sub

    End Class

End Namespace
#End If

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -