Compare commits

...

11 Commits

Author SHA1 Message Date
jar3b
70763bfd95 feat: add go modules support 2021-07-15 11:45:53 +03:00
jar3b
313e6a6b16 fix: plot.New() call 2021-07-15 11:45:36 +03:00
daniel-gil
8a6e52a737 fixed references 2019-04-12 11:39:41 +02:00
Daniel Gil
3e69a488f6 Added an example in readme file for highInclusive false 2018-07-05 09:11:34 +02:00
Daniel Gil
e73c928dad renamed pkg from interval to intervals 2018-07-05 09:04:38 +02:00
Daniel Gil
7ab61f4312 fixed example 2018-07-03 12:25:38 +02:00
Daniel Gil
658f7dc53f refactor intervals repo in testcases and example (bitbucket -> github) 2018-07-03 12:22:24 +02:00
Daniel Gil
54e008c3e2 removed cover options from travis configuration 2018-07-03 12:04:13 +02:00
Daniel Gil
e7d0bf85e2 added .travis.yml file 2018-07-03 12:01:11 +02:00
Daniel Gil
81987af8d7 Added travis integration 2018-07-03 11:37:29 +02:00
Daniel Gil
59657e8ba8 moved CHANGELOG file to the root 2018-07-03 11:11:28 +02:00
28 changed files with 770 additions and 674 deletions

3
.travis.yml Normal file
View File

@ -0,0 +1,3 @@
language: go
go:
- '1.10'

11
CHANGELOG.md Normal file
View File

@ -0,0 +1,11 @@
# Changelog
## [0.1.1] - 2018-07-05
### Changed
- Renamed package name from 'interval' to 'intervals'
## [0.1.0] - 2018-07-03
- First release

View File

@ -1,6 +1,6 @@
The MIT License (MIT)
Copyright (c) 2018 centraldereservas.com
Copyright (c) 2018 daniel-gil
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@ -1,18 +1,18 @@
# intervals [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![GoDoc](https://godoc.org/github.com/centraldereservas/intervals?status.svg)](https://godoc.org/github.com/centraldereservas/intervals)
# intervals [![Build Status](https://travis-ci.org/daniel-gil/intervals.svg?branch=master)](https://travis-ci.org/daniel-gil/intervals) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![GoDoc](https://godoc.org/github.com/daniel-gil/intervals?status.svg)](https://godoc.org/github.com/daniel-gil/intervals)
Provides a helper to work with integer intervals detecting gaps, merged and overlapped sections.
## Installation
```sh
go get github.com/centraldereservas/intervals
go get github.com/daniel-gil/intervals
```
## Motivation
Why we need to have control over a list of intervals?
Because provider API's have product prices depending on the age, so they assign a price amount to different age bands.
Because the API providers have their product prices depending on the age, so they assign a price amount to different age bands.
As a result we have a bunch of age bands (with its corresponding price) which can have:
@ -46,7 +46,7 @@ API documentation is available on [godoc.org][doc].
To use this package the first thing we have to do is create an instance:
```go
intvls := interval.NewIntervals(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
intvls := intervals.New(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
```
where `minLow` and `maxHigh` are integers that defines the accepted integer space to work with, anything else outside will be rejected. The booleans `lowInclusive` and `highInclusive` indicates if the values of a range (low, high) are inclusive or not. The booleans `selfAdjustMinLow`and `selfAdjustMaxHigh` indicates that we do not need to specify the minLow or maxHigh in the constructor, but those values will be self adjusted automatically taking the lower and greatest value respectively of all intervals added.
@ -63,7 +63,7 @@ Once initialized, we can proced to add new intervals.
We can add intervals by passing an `Interval` object:
```go
intvl := &interval.Interval{Low: ageFrom, High: ageTo, Object: myObject}
intvl := &intervals.Interval{Low: ageFrom, High: ageTo, Object: myObject}
err := intvls.AddInterval(intvl)
if err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
@ -144,10 +144,13 @@ Output:
go run ./example/main.go
```
This example generates an output image file exposing the data analyzed:
The following image is an example where `lowInclusive` and `highInclusive` are both `true`:
![alt text](./example/out.png)
The next image is another example where `lowInclusive` is `true` but `highInclusive` is `false`:
![alt text](./example/out2.png)
## References
@ -158,5 +161,5 @@ This example generates an output image file exposing the data analyzed:
This project is under the [MIT License][mit].
[mit]: https://github.com/centraldereservas/intervals/blob/master/LICENSE
[doc]: https://godoc.org/github.com/centraldereservas/intervals
[mit]: https://github.com/daniel-gil/intervals/blob/master/LICENSE
[doc]: https://godoc.org/github.com/daniel-gil/intervals

2
add.go
View File

@ -1,4 +1,4 @@
package interval
package intervals
import "math"

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +0,0 @@
# Changelog
## [0.0.1] - 2018-06-28
- First commit

View File

@ -6,7 +6,7 @@ import (
"log"
"os"
"bitbucket.org/differenttravel/interval"
"github.com/daniel-gil/intervals"
)
const (
@ -20,9 +20,9 @@ func main() {
if err != nil {
log.Fatalf("could not read %s: %v", filename, err)
}
intervals := initIntervals(xys)
ip := interval.NewPlot(intervals.IsLowInclusive(), intervals.IsHighInclusive())
err = ip.PlotData("out.png", intervals, true, true, true, true)
intvls := initIntervals(xys)
ip := intervals.NewPlot(intvls.IsLowInclusive(), intvls.IsHighInclusive())
err = ip.PlotData("out.png", intvls, true, true, true, true)
if err != nil {
log.Fatalf("could not plot data: %v", err)
}
@ -59,7 +59,7 @@ func readData(path string) ([]xy, error) {
return xys, nil
}
func initIntervals(xys []xy) interval.Intervals {
func initIntervals(xys []xy) intervals.Intervals {
// initialize Intervals
minLow := MinX
maxHigh := MaxX
@ -67,14 +67,13 @@ func initIntervals(xys []xy) interval.Intervals {
highInclusive := true
selfAdjustMinLow := false
selfAdjustMaxHigh := true
intervals := interval.NewIntervals(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
intvls := intervals.New(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
for _, xy := range xys {
err := intervals.AddInterval(&interval.Interval{Low: xy.x, High: xy.y})
err := intvls.AddInterval(&intervals.Interval{Low: xy.x, High: xy.y})
if err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
}
intervals.Sort()
return intervals
return intvls
}

BIN
example/out2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

View File

@ -1,4 +1,4 @@
package interval
package intervals
import "fmt"

View File

@ -1,13 +1,13 @@
package interval_test
package intervals_test
import (
"fmt"
"testing"
"bitbucket.org/differenttravel/interval"
"github.com/daniel-gil/intervals"
)
func initIntervalsForDemo001() interval.Intervals {
func initIntervalsForDemo001() intervals.Intervals {
// initialize Intervals
minLow := 0
maxHigh := 100
@ -15,28 +15,28 @@ func initIntervalsForDemo001() interval.Intervals {
highInclusive := true
selfAdjustMinLow := false
selfAdjustMaxHigh := true
itvls := interval.NewIntervals(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
itvls := intervals.New(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
// add new intervals
if err := itvls.AddInterval(&interval.Interval{Low: 5, High: 7}); err != nil {
if err := itvls.AddInterval(&intervals.Interval{Low: 5, High: 7}); err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
if err := itvls.AddInterval(&interval.Interval{Low: 2, High: 4}); err != nil {
if err := itvls.AddInterval(&intervals.Interval{Low: 2, High: 4}); err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
if err := itvls.AddInterval(&interval.Interval{Low: 3, High: 6}); err != nil {
if err := itvls.AddInterval(&intervals.Interval{Low: 3, High: 6}); err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
if err := itvls.AddInterval(&interval.Interval{Low: 18, High: 20}); err != nil {
if err := itvls.AddInterval(&intervals.Interval{Low: 18, High: 20}); err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
if err := itvls.AddInterval(&interval.Interval{Low: 20, High: 30}); err != nil {
if err := itvls.AddInterval(&intervals.Interval{Low: 20, High: 30}); err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
if err := itvls.AddInterval(&interval.Interval{Low: 25, High: 28}); err != nil {
if err := itvls.AddInterval(&intervals.Interval{Low: 25, High: 28}); err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
if err := itvls.AddInterval(&interval.Interval{Low: 30, High: 32}); err != nil {
if err := itvls.AddInterval(&intervals.Interval{Low: 30, High: 32}); err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
return itvls
@ -45,17 +45,17 @@ func initIntervalsForDemo001() interval.Intervals {
// matches for value=2
func buildFindDemo001() demo {
itvls := initIntervalsForDemo001()
matches := []interval.Interval{}
matches = append(matches, interval.Interval{Low: 2, High: 4})
matches := []intervals.Interval{}
matches = append(matches, intervals.Interval{Low: 2, High: 4})
return demo{Intervals: itvls, ExpectedFindMatches: matches, ValueToFind: 2}
}
// matches for value=4
func buildFindDemo002() demo {
itvls := initIntervalsForDemo001()
matches := []interval.Interval{}
matches = append(matches, interval.Interval{Low: 2, High: 4})
matches = append(matches, interval.Interval{Low: 3, High: 6})
matches := []intervals.Interval{}
matches = append(matches, intervals.Interval{Low: 2, High: 4})
matches = append(matches, intervals.Interval{Low: 3, High: 6})
return demo{Intervals: itvls, ExpectedFindMatches: matches, ValueToFind: 4}
}
@ -66,8 +66,8 @@ func TestFindIntervalsForValue(t *testing.T) {
tt := []struct {
name string
valueToFind int
intvls interval.Intervals
expectedMatches []interval.Interval
intvls intervals.Intervals
expectedMatches []intervals.Interval
}{
{name: "demo001", valueToFind: demo001.ValueToFind, intvls: demo001.Intervals, expectedMatches: demo001.ExpectedFindMatches},
{name: "demo002", valueToFind: demo002.ValueToFind, intvls: demo002.Intervals, expectedMatches: demo002.ExpectedFindMatches},

View File

@ -1,4 +1,4 @@
package interval
package intervals
import "fmt"

View File

@ -1,9 +1,9 @@
package interval_test
package intervals_test
import (
"testing"
"bitbucket.org/differenttravel/interval"
"github.com/daniel-gil/intervals"
)
func TestGaps(t *testing.T) {
@ -67,8 +67,8 @@ func TestGaps(t *testing.T) {
demo312 := buildIntervalsDemo312()
tt := []struct {
name string
intvls interval.Intervals
expectedGaps []interval.Interval
intvls intervals.Intervals
expectedGaps []intervals.Interval
}{
{name: "demo001", intvls: demo001.Intervals, expectedGaps: demo001.ExpectedGaps},
{name: "demo002", intvls: demo002.Intervals, expectedGaps: demo002.ExpectedGaps},

2
get.go
View File

@ -1,4 +1,4 @@
package interval
package intervals
func (intvls *intervals) GetIntervals() []*Interval {
// sort intervals (if necessary)

9
go.mod Normal file
View File

@ -0,0 +1,9 @@
module github.com/jar3b/intervals
go 1.16
require (
github.com/centraldereservas/intervals v0.1.1 // indirect
github.com/daniel-gil/intervals v0.1.1
gonum.org/v1/plot v0.9.0
)

78
go.sum Normal file
View File

@ -0,0 +1,78 @@
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
gioui.org v0.0.0-20210308172011-57750fc8a0a6/go.mod h1:RSH6KIUZ0p2xy5zHDxgAM4zumjgTw83q2ge/PI+yyw8=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af h1:wVe6/Ea46ZMeNkQjjBW6xcqyQA/j5e0D6GytH95g0gQ=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/centraldereservas/intervals v0.1.1 h1:8ryM0HiLkIcNCRJ6+DDagWWJ/jPzXUaYf5QX84oqHqg=
github.com/centraldereservas/intervals v0.1.1/go.mod h1:xZYNveYaK5s2cLqkcHvQ1bd9+7kKpcEcRwGDh3Qtb6Q=
github.com/daniel-gil/intervals v0.1.1 h1:oJfuUu/5xhM15x+gkwImCin+TN8BxFwHn1cPs7Et2PM=
github.com/daniel-gil/intervals v0.1.1/go.mod h1:5ejQsLKIoitOzKemPh+gptLk/UHn4omE8N+tGhV6aQ8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/go-fonts/dejavu v0.1.0 h1:JSajPXURYqpr+Cu8U9bt8K+XcACIHWqWrvWCKyeFmVQ=
github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g=
github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks=
github.com/go-fonts/liberation v0.1.1 h1:wBrPaMkrXFBW3qXpXAjiKljdVUMxn9bX2ia3XjPHoik=
github.com/go-fonts/liberation v0.1.1/go.mod h1:K6qoJYypsmfVjWg8KOVDQhLc8UDgIK2HYqyqAO9z7GY=
github.com/go-fonts/stix v0.1.0/go.mod h1:w/c1f0ldAUlJmLBvlbkvVXLAD+tAMqobIIQpmnUIzUY=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07 h1:OTlfMvwR1rLyf9goVmXfuS5AJn80+Vmj4rTf4n46SOs=
github.com/go-latex/latex v0.0.0-20210118124228-b3d85cf34e07/go.mod h1:CO1AlKB2CSIqUrmQPqA0gdRIlnLEY0gK5JGjh37zN5U=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/phpdave11/gofpdf v1.4.2 h1:KPKiIbfwbvC/wOncwhrpRdXVj2CZTCFlw4wnoyjtHfQ=
github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2dXMnm1mY=
github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfFZQK844Gfx8o5WFuvpxWRwnSoipWe/p622j1v06w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3 h1:n9HxLrNxWWtEb1cA950nuEEj3QnKbtsCJ6KjcgisNUs=
golang.org/x/exp v0.0.0-20191002040644-a1355ae1e2c3/go.mod h1:NOZ3BPKG0ec/BKJQgnvsSFpcKLM5xXVWnvZS97DWHgE=
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200430140353-33d19683fad8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210216034530-4410531fe030 h1:lP9pYkih3DUSC641giIXa2XqfTIbbbRr0w2EOTA7wHA=
golang.org/x/image v0.0.0-20210216034530-4410531fe030/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210304124612-50617c2ba197/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190927191325-030b2cf1153e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.0.0-20180816165407-929014505bf4/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/gonum v0.8.2 h1:CCXrcPKiGGotvnN6jfUsKk4rRqm7q09/YbKb5xCEvtM=
gonum.org/v1/gonum v0.8.2/go.mod h1:oe/vMfY3deqTw+1EZJhuvEW2iwGF1bW9wwu7XCu0+v0=
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b/go.mod h1:Wt8AAjI+ypCyYX3nZBvf6cAIx93T+c/OS2HFAYskSZc=
gonum.org/v1/plot v0.9.0 h1:3sEo36Uopv1/SA/dMFFaxXoL5XyikJ9Sf2Vll/k6+2E=
gonum.org/v1/plot v0.9.0/go.mod h1:3Pcqqmp6RHvJI72kgb8fThyUnav364FOsdDo2aGW5lY=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=

View File

@ -1,4 +1,4 @@
package interval
package intervals
import "fmt"

View File

@ -1,4 +1,4 @@
package interval
package intervals
import "fmt"

View File

@ -1,4 +1,4 @@
package interval
package intervals
import (
"math"
@ -77,11 +77,11 @@ func (itvls *intervals) String() string {
// NewIntervalsDefault is a constructor that returns an instance of the Intervals interface with default values
func NewIntervalsDefault() Intervals {
return NewIntervals(defaultMinLow, defaultMaxHigh, defaultLowInclusive, defaultHighInclusive, defaultSelfAdjustMinLow, defaultSelfAdjustMaxHigh)
return New(defaultMinLow, defaultMaxHigh, defaultLowInclusive, defaultHighInclusive, defaultSelfAdjustMinLow, defaultSelfAdjustMaxHigh)
}
// NewIntervals is a constructor that returns an instance of the Intervals interface
func NewIntervals(minLow, maxHigh int, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh bool) Intervals {
// New is a constructor that returns an instance of the Intervals interface
func New(minLow, maxHigh int, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh bool) Intervals {
return &intervals{
MinLow: minLow,
MaxHigh: maxHigh,

View File

@ -1,4 +1,4 @@
package interval
package intervals
import "fmt"

View File

@ -1,9 +1,9 @@
package interval_test
package intervals_test
import (
"testing"
"bitbucket.org/differenttravel/interval"
"github.com/daniel-gil/intervals"
)
func TestMerge(t *testing.T) {
@ -67,8 +67,8 @@ func TestMerge(t *testing.T) {
demo312 := buildIntervalsDemo312()
tt := []struct {
name string
intvls interval.Intervals
expectedMerges []interval.Interval
intvls intervals.Intervals
expectedMerges []intervals.Interval
}{
{name: "demo001", intvls: demo001.Intervals, expectedMerges: demo001.ExpectedMerges},
{name: "demo002", intvls: demo002.Intervals, expectedMerges: demo002.ExpectedMerges},

View File

@ -1,4 +1,4 @@
package interval
package intervals
import (
"fmt"

View File

@ -1,9 +1,9 @@
package interval_test
package intervals_test
import (
"testing"
"bitbucket.org/differenttravel/interval"
"github.com/daniel-gil/intervals"
)
func TestOverlapped(t *testing.T) {
@ -67,8 +67,8 @@ func TestOverlapped(t *testing.T) {
demo312 := buildIntervalsDemo312()
tt := []struct {
name string
intvls interval.Intervals
expectedOverlaps []interval.Interval
intvls intervals.Intervals
expectedOverlaps []intervals.Interval
}{
{name: "demo001", intvls: demo001.Intervals, expectedOverlaps: demo001.ExpectedOverlaps},
{name: "demo002", intvls: demo002.Intervals, expectedOverlaps: demo002.ExpectedOverlaps},

View File

@ -1,4 +1,4 @@
package interval
package intervals
import (
"fmt"
@ -178,10 +178,7 @@ func (ip *intervalPlot) AlignPlots(plotItems []*Superplot, minLow, maxHigh int)
}
func (ip *intervalPlot) CreatePlot(title string, xys plotter.XYs, plotType PlotType) (*Superplot, error) {
p, err := plot.New()
if err != nil {
return nil, fmt.Errorf("could not create plot: %v", err)
}
p := plot.New()
// Draw a grid behind the data
p.Add(plotter.NewGrid())

View File

@ -1,4 +1,4 @@
package interval
package intervals
import "fmt"

View File

@ -1,10 +1,10 @@
package interval_test
package intervals_test
import (
"fmt"
"testing"
"bitbucket.org/differenttravel/interval"
"github.com/daniel-gil/intervals"
)
func TestReport(t *testing.T) {
@ -14,41 +14,41 @@ func TestReport(t *testing.T) {
highInclusive := true
selfAdjustMinLow := false
selfAdjustMaxHigh := true
itvls := interval.NewIntervals(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
itvls := intervals.New(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
var err error
err = itvls.AddInterval(&interval.Interval{Low: 5, High: 7})
err = itvls.AddInterval(&intervals.Interval{Low: 5, High: 7})
if err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
err = itvls.AddInterval(&interval.Interval{Low: 2, High: 4})
err = itvls.AddInterval(&intervals.Interval{Low: 2, High: 4})
if err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
err = itvls.AddInterval(&interval.Interval{Low: 3, High: 6})
err = itvls.AddInterval(&intervals.Interval{Low: 3, High: 6})
if err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
err = itvls.AddInterval(&interval.Interval{Low: 18, High: 20})
err = itvls.AddInterval(&intervals.Interval{Low: 18, High: 20})
if err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
err = itvls.AddInterval(&interval.Interval{Low: 20, High: 30})
err = itvls.AddInterval(&intervals.Interval{Low: 20, High: 30})
if err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
err = itvls.AddInterval(&interval.Interval{Low: 25, High: 28})
err = itvls.AddInterval(&intervals.Interval{Low: 25, High: 28})
if err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
err = itvls.AddInterval(&interval.Interval{Low: 30, High: 32})
err = itvls.AddInterval(&intervals.Interval{Low: 30, High: 32})
if err != nil {
fmt.Printf("invalid interval discarded: %v\n", err)
}
tt := []struct {
name string
itvls interval.Intervals
itvls intervals.Intervals
}{
{name: "normal case", itvls: itvls},
}

View File

@ -1,4 +1,4 @@
package interval
package intervals
import "sort"

View File

@ -1,4 +1,4 @@
package interval
package intervals
func min(a, b int) int {
if a < b {