Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1-liner bugfix for Interval Set #4481

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

1-liner bugfix for Interval Set #4481

wants to merge 1 commit into from

Conversation

Guttz
Copy link

@Guttz Guttz commented Dec 6, 2023

I'm pretty sure this is a bug. Checked the python implementation and it looked similar. None of them have tests though.

This change is necessary or else the last else if will never be executed and the function returns wrong results for some cases. For example, the following tests will fail without this change, even though they are correct:

TestRemoveRangeSameStart() {
	i := antlr.NewIntervalSet()
	i.addInterval(antlr.NewInterval(1, 10))
	i.removeRange(antlr.NewInterval(1, 7))

	suite.Len(i.intervals, 1)
	suite.Equal(7, i.intervals[0].Start)
	suite.Equal(10, i.intervals[0].Stop)
}
TestRemoveRangeOverStartBound() {
	i := antlr.NewIntervalSet()
	i.addInterval(antlr.NewInterval(5, 15))

	i.removeRange(antlr.NewInterval(1, 10))
	suite.Len(i.intervals, 1)
	suite.Equal(10, i.intervals[0].Start)
	suite.Equal(15, i.intervals[0].Stop)
}

This is necessary or else the last else if will never be executed and the function returns wrong results for some cases. For example, these tests will not run without this change:

TestRemoveRangeSameStart() {
	i := NewIntervalSet()
	i.addInterval(antlr.NewInterval(1, 10))
	i.removeRange(antlr.NewInterval(1, 7))

	suite.Len(i.intervals, 1)
	suite.Equal(7, i.intervals[0].Start)
	suite.Equal(10, i.intervals[0].Stop)
}

TestRemoveRangeOverStartBound() {
	i := NewIntervalSet()
	i.addInterval(antlr.NewInterval(5, 15))

	i.removeRange(antlr.NewInterval(1, 10))
	suite.Len(i.intervals, 1)
	suite.Equal(10, i.intervals[0].Start)
	suite.Equal(15, i.intervals[0].Stop)
}


Signed-off-by: Gustavo de Morais <gustavopguto@gmail.com>
@Guttz Guttz changed the title Bugfix for Interval Set 1-liner bugfix for Interval Set Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant