Evgenii Stratonikov
f2e5dead7e
All checks were successful
ci/woodpecker/push/pre-commit Pipeline was successful
1. In redo() we save the old state. 2. If we do redo() for the same operation twice, the old state will be overritten with the new one. 3. This in turn affects undo() and subsequent isAncestor() check. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
70 lines
1.2 KiB
Go
70 lines
1.2 KiB
Go
package pilorama
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_removeDuplicatesInPlace(t *testing.T) {
|
|
testCases := []struct {
|
|
before []int
|
|
after []int
|
|
}{
|
|
{
|
|
before: []int{},
|
|
after: []int{},
|
|
},
|
|
{
|
|
before: []int{1},
|
|
after: []int{1},
|
|
},
|
|
{
|
|
before: []int{1, 2},
|
|
after: []int{1, 2},
|
|
},
|
|
{
|
|
before: []int{1, 2, 3},
|
|
after: []int{1, 2, 3},
|
|
},
|
|
{
|
|
before: []int{1, 1, 2},
|
|
after: []int{1, 2},
|
|
},
|
|
{
|
|
before: []int{1, 2, 2},
|
|
after: []int{1, 2},
|
|
},
|
|
{
|
|
before: []int{1, 2, 2, 3},
|
|
after: []int{1, 2, 3},
|
|
},
|
|
{
|
|
before: []int{1, 1, 1},
|
|
after: []int{1},
|
|
},
|
|
{
|
|
before: []int{1, 1, 2, 2},
|
|
after: []int{1, 2},
|
|
},
|
|
{
|
|
before: []int{1, 1, 1, 2, 3, 3, 3},
|
|
after: []int{1, 2, 3},
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
ops := make([]*Move, len(tc.before))
|
|
for i := range ops {
|
|
ops[i] = &Move{Meta: Meta{Time: Timestamp(tc.before[i])}}
|
|
}
|
|
|
|
expected := make([]*Move, len(tc.after))
|
|
for i := range expected {
|
|
expected[i] = &Move{Meta: Meta{Time: Timestamp(tc.after[i])}}
|
|
}
|
|
|
|
actual := removeDuplicatesInPlace(ops)
|
|
require.Equal(t, expected, actual, "%d", tc.before)
|
|
}
|
|
}
|