Added check for valid interval in Add function. Added overlap testcases.
This commit is contained in:
11
add.go
11
add.go
@@ -1,8 +1,17 @@
|
||||
package interval
|
||||
|
||||
func (intvls *intervals) Add(itvl *Interval) {
|
||||
func (intvls *intervals) Add(itvl *Interval) error {
|
||||
low := intvls.getInclusiveLow(itvl.Low)
|
||||
high := intvls.getInclusiveHigh(itvl.High)
|
||||
|
||||
err := intvls.checkValidInterval(low, high)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
intvls.Intervals = append(intvls.Intervals, itvl)
|
||||
intvls.reset()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (intvls *intervals) reset() {
|
||||
|
||||
Reference in New Issue
Block a user