Added check for valid interval in Add function. Added overlap testcases.

This commit is contained in:
Daniel Gil
2018-05-30 17:16:04 +02:00
parent 5128012518
commit 98c89357f5
7 changed files with 825 additions and 211 deletions

11
add.go
View File

@@ -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() {