fix(parser/diff): pyMod
All checks were successful
submodules sync / sync (push) Successful in 41s
build / build (push) Successful in 1m46s
build / trigger-build-image (push) Successful in 9s

This commit is contained in:
张泊明518370910136 2025-03-26 20:30:21 -04:00
parent 372bac8f4b
commit 2f94bd30ed
GPG Key ID: D47306D7062CDA9D
2 changed files with 6 additions and 3 deletions

View File

@ -119,11 +119,13 @@ func diffInternal(e, f []any, equals func(any, any) bool, i, j int) []Op {
* e.g -1%3 = 2. * e.g -1%3 = 2.
* In golang it matches the sign of the numerator. * In golang it matches the sign of the numerator.
* See https://en.wikipedia.org/wiki/Modulo_operation#Variants_of_the_definition * See https://en.wikipedia.org/wiki/Modulo_operation#Variants_of_the_definition
* Since we always have a positive denominator here, we can emulate the
* pyMod x%y as (x+y) % y
*/ */
func pyMod(x, y int) int { func pyMod(x, y int) int {
return (x + y) % y mod := x % y
if mod < 0 {
mod += y
}
return mod
} }
// Let us map element in same way as in // Let us map element in same way as in

View File

@ -18,6 +18,7 @@ func TestDiff(t *t.T) {
testCases := []TestCase{ testCases := []TestCase{
{[]string{}, []string{}, []Op{}}, {[]string{}, []string{}, []Op{}},
{[]string{}, []string{"foo"}, []Op{{OpInsert, 0, 0, "foo"}}}, {[]string{}, []string{"foo"}, []Op{{OpInsert, 0, 0, "foo"}}},
{[]string{"foo"}, []string{}, []Op{{OpDelete, 0, -1, "foo"}}},
{[]string{"foo", "bar", "baz"}, []string{"foo", "bar", "baz"}, []Op{}}, {[]string{"foo", "bar", "baz"}, []string{"foo", "bar", "baz"}, []Op{}},
{[]string{"foo", "bar", "baz"}, []string{"foo", "baz"}, []Op{{OpDelete, 1, -1, "bar"}}}, {[]string{"foo", "bar", "baz"}, []string{"foo", "baz"}, []Op{{OpDelete, 1, -1, "bar"}}},
{[]string{"baz"}, []string{"foo", "baz"}, []Op{{OpInsert, 0, 0, "foo"}}}, {[]string{"baz"}, []string{"foo", "baz"}, []Op{{OpInsert, 0, 0, "foo"}}},