fix(parser/diff): pyMod
This commit is contained in:
		
							parent
							
								
									372bac8f4b
								
							
						
					
					
						commit
						2f94bd30ed
					
				|  | @ -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
 | ||||||
|  |  | ||||||
|  | @ -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"}}}, | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user