Compare commits
No commits in common. "master" and "v0.1.0" have entirely different histories.
@ -1,3 +0,0 @@
|
||||
language: go
|
||||
go:
|
||||
- '1.10'
|
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,11 +0,0 @@
|
||||
# Changelog
|
||||
|
||||
## [0.1.1] - 2018-07-05
|
||||
|
||||
### Changed
|
||||
|
||||
- Renamed package name from 'interval' to 'intervals'
|
||||
|
||||
## [0.1.0] - 2018-07-03
|
||||
|
||||
- First release
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 daniel-gil
|
||||
Copyright (c) 2018 centraldereservas.com
|
||||
|
||||
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:
|
||||
|
||||
|
19
README.md
19
README.md
@ -1,18 +1,18 @@
|
||||
# intervals [](https://travis-ci.org/daniel-gil/intervals) [](https://opensource.org/licenses/MIT) [](https://godoc.org/github.com/daniel-gil/intervals)
|
||||
# intervals [](https://opensource.org/licenses/MIT) [](https://godoc.org/github.com/centraldereservas/intervals)
|
||||
|
||||
Provides a helper to work with integer intervals detecting gaps, merged and overlapped sections.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
go get github.com/daniel-gil/intervals
|
||||
go get github.com/centraldereservas/intervals
|
||||
```
|
||||
|
||||
## Motivation
|
||||
|
||||
Why we need to have control over a list of intervals?
|
||||
|
||||
Because the API providers have their product prices depending on the age, so they assign a price amount to different age bands.
|
||||
Because provider API's have 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 := intervals.New(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
|
||||
intvls := interval.NewIntervals(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 := &intervals.Interval{Low: ageFrom, High: ageTo, Object: myObject}
|
||||
intvl := &interval.Interval{Low: ageFrom, High: ageTo, Object: myObject}
|
||||
err := intvls.AddInterval(intvl)
|
||||
if err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
@ -144,13 +144,10 @@ Output:
|
||||
go run ./example/main.go
|
||||
```
|
||||
|
||||
The following image is an example where `lowInclusive` and `highInclusive` are both `true`:
|
||||
This example generates an output image file exposing the data analyzed:
|
||||
|
||||

|
||||
|
||||
The next image is another example where `lowInclusive` is `true` but `highInclusive` is `false`:
|
||||
|
||||

|
||||
|
||||
## References
|
||||
|
||||
@ -161,5 +158,5 @@ The next image is another example where `lowInclusive` is `true` but `highInclus
|
||||
|
||||
This project is under the [MIT License][mit].
|
||||
|
||||
[mit]: https://github.com/daniel-gil/intervals/blob/master/LICENSE
|
||||
[doc]: https://godoc.org/github.com/daniel-gil/intervals
|
||||
[mit]: https://github.com/centraldereservas/intervals/blob/master/LICENSE
|
||||
[doc]: https://godoc.org/github.com/centraldereservas/intervals
|
1182
demo_test.go
1182
demo_test.go
File diff suppressed because it is too large
Load Diff
4
example/CHANGELOG.md
Normal file
4
example/CHANGELOG.md
Normal file
@ -0,0 +1,4 @@
|
||||
# Changelog
|
||||
|
||||
## [0.0.1] - 2018-06-28
|
||||
- First commit
|
@ -6,7 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/daniel-gil/intervals"
|
||||
"bitbucket.org/differenttravel/interval"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -20,9 +20,9 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("could not read %s: %v", filename, err)
|
||||
}
|
||||
intvls := initIntervals(xys)
|
||||
ip := intervals.NewPlot(intvls.IsLowInclusive(), intvls.IsHighInclusive())
|
||||
err = ip.PlotData("out.png", intvls, true, true, true, true)
|
||||
intervals := initIntervals(xys)
|
||||
ip := interval.NewPlot(intervals.IsLowInclusive(), intervals.IsHighInclusive())
|
||||
err = ip.PlotData("out.png", intervals, 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) intervals.Intervals {
|
||||
func initIntervals(xys []xy) interval.Intervals {
|
||||
// initialize Intervals
|
||||
minLow := MinX
|
||||
maxHigh := MaxX
|
||||
@ -67,13 +67,14 @@ func initIntervals(xys []xy) intervals.Intervals {
|
||||
highInclusive := true
|
||||
selfAdjustMinLow := false
|
||||
selfAdjustMaxHigh := true
|
||||
intvls := intervals.New(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
|
||||
intervals := interval.NewIntervals(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
|
||||
|
||||
for _, xy := range xys {
|
||||
err := intvls.AddInterval(&intervals.Interval{Low: xy.x, High: xy.y})
|
||||
err := intervals.AddInterval(&interval.Interval{Low: xy.x, High: xy.y})
|
||||
if err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
}
|
||||
return intvls
|
||||
intervals.Sort()
|
||||
return intervals
|
||||
}
|
||||
|
BIN
example/out2.png
BIN
example/out2.png
Binary file not shown.
Before Width: | Height: | Size: 40 KiB |
36
find_test.go
36
find_test.go
@ -1,13 +1,13 @@
|
||||
package intervals_test
|
||||
package interval_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/daniel-gil/intervals"
|
||||
"bitbucket.org/differenttravel/interval"
|
||||
)
|
||||
|
||||
func initIntervalsForDemo001() intervals.Intervals {
|
||||
func initIntervalsForDemo001() interval.Intervals {
|
||||
// initialize Intervals
|
||||
minLow := 0
|
||||
maxHigh := 100
|
||||
@ -15,28 +15,28 @@ func initIntervalsForDemo001() intervals.Intervals {
|
||||
highInclusive := true
|
||||
selfAdjustMinLow := false
|
||||
selfAdjustMaxHigh := true
|
||||
itvls := intervals.New(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
|
||||
itvls := interval.NewIntervals(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
|
||||
|
||||
// add new intervals
|
||||
if err := itvls.AddInterval(&intervals.Interval{Low: 5, High: 7}); err != nil {
|
||||
if err := itvls.AddInterval(&interval.Interval{Low: 5, High: 7}); err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
if err := itvls.AddInterval(&intervals.Interval{Low: 2, High: 4}); err != nil {
|
||||
if err := itvls.AddInterval(&interval.Interval{Low: 2, High: 4}); err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
if err := itvls.AddInterval(&intervals.Interval{Low: 3, High: 6}); err != nil {
|
||||
if err := itvls.AddInterval(&interval.Interval{Low: 3, High: 6}); err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
if err := itvls.AddInterval(&intervals.Interval{Low: 18, High: 20}); err != nil {
|
||||
if err := itvls.AddInterval(&interval.Interval{Low: 18, High: 20}); err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
if err := itvls.AddInterval(&intervals.Interval{Low: 20, High: 30}); err != nil {
|
||||
if err := itvls.AddInterval(&interval.Interval{Low: 20, High: 30}); err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
if err := itvls.AddInterval(&intervals.Interval{Low: 25, High: 28}); err != nil {
|
||||
if err := itvls.AddInterval(&interval.Interval{Low: 25, High: 28}); err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
if err := itvls.AddInterval(&intervals.Interval{Low: 30, High: 32}); err != nil {
|
||||
if err := itvls.AddInterval(&interval.Interval{Low: 30, High: 32}); err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
return itvls
|
||||
@ -45,17 +45,17 @@ func initIntervalsForDemo001() intervals.Intervals {
|
||||
// matches for value=2
|
||||
func buildFindDemo001() demo {
|
||||
itvls := initIntervalsForDemo001()
|
||||
matches := []intervals.Interval{}
|
||||
matches = append(matches, intervals.Interval{Low: 2, High: 4})
|
||||
matches := []interval.Interval{}
|
||||
matches = append(matches, interval.Interval{Low: 2, High: 4})
|
||||
return demo{Intervals: itvls, ExpectedFindMatches: matches, ValueToFind: 2}
|
||||
}
|
||||
|
||||
// matches for value=4
|
||||
func buildFindDemo002() demo {
|
||||
itvls := initIntervalsForDemo001()
|
||||
matches := []intervals.Interval{}
|
||||
matches = append(matches, intervals.Interval{Low: 2, High: 4})
|
||||
matches = append(matches, intervals.Interval{Low: 3, High: 6})
|
||||
matches := []interval.Interval{}
|
||||
matches = append(matches, interval.Interval{Low: 2, High: 4})
|
||||
matches = append(matches, interval.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 intervals.Intervals
|
||||
expectedMatches []intervals.Interval
|
||||
intvls interval.Intervals
|
||||
expectedMatches []interval.Interval
|
||||
}{
|
||||
{name: "demo001", valueToFind: demo001.ValueToFind, intvls: demo001.Intervals, expectedMatches: demo001.ExpectedFindMatches},
|
||||
{name: "demo002", valueToFind: demo002.ValueToFind, intvls: demo002.Intervals, expectedMatches: demo002.ExpectedFindMatches},
|
||||
|
@ -1,9 +1,9 @@
|
||||
package intervals_test
|
||||
package interval_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/daniel-gil/intervals"
|
||||
"bitbucket.org/differenttravel/interval"
|
||||
)
|
||||
|
||||
func TestGaps(t *testing.T) {
|
||||
@ -67,8 +67,8 @@ func TestGaps(t *testing.T) {
|
||||
demo312 := buildIntervalsDemo312()
|
||||
tt := []struct {
|
||||
name string
|
||||
intvls intervals.Intervals
|
||||
expectedGaps []intervals.Interval
|
||||
intvls interval.Intervals
|
||||
expectedGaps []interval.Interval
|
||||
}{
|
||||
{name: "demo001", intvls: demo001.Intervals, expectedGaps: demo001.ExpectedGaps},
|
||||
{name: "demo002", intvls: demo002.Intervals, expectedGaps: demo002.ExpectedGaps},
|
||||
|
2
get.go
2
get.go
@ -1,4 +1,4 @@
|
||||
package intervals
|
||||
package interval
|
||||
|
||||
func (intvls *intervals) GetIntervals() []*Interval {
|
||||
// sort intervals (if necessary)
|
||||
|
9
go.mod
9
go.mod
@ -1,9 +0,0 @@
|
||||
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
78
go.sum
@ -1,78 +0,0 @@
|
||||
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=
|
@ -1,4 +1,4 @@
|
||||
package intervals
|
||||
package interval
|
||||
|
||||
import "fmt"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package intervals
|
||||
package interval
|
||||
|
||||
import "fmt"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
package intervals
|
||||
package interval
|
||||
|
||||
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 New(defaultMinLow, defaultMaxHigh, defaultLowInclusive, defaultHighInclusive, defaultSelfAdjustMinLow, defaultSelfAdjustMaxHigh)
|
||||
return NewIntervals(defaultMinLow, defaultMaxHigh, defaultLowInclusive, defaultHighInclusive, defaultSelfAdjustMinLow, defaultSelfAdjustMaxHigh)
|
||||
}
|
||||
|
||||
// New is a constructor that returns an instance of the Intervals interface
|
||||
func New(minLow, maxHigh int, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh bool) Intervals {
|
||||
// NewIntervals is a constructor that returns an instance of the Intervals interface
|
||||
func NewIntervals(minLow, maxHigh int, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh bool) Intervals {
|
||||
return &intervals{
|
||||
MinLow: minLow,
|
||||
MaxHigh: maxHigh,
|
||||
|
@ -1,9 +1,9 @@
|
||||
package intervals_test
|
||||
package interval_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/daniel-gil/intervals"
|
||||
"bitbucket.org/differenttravel/interval"
|
||||
)
|
||||
|
||||
func TestMerge(t *testing.T) {
|
||||
@ -67,8 +67,8 @@ func TestMerge(t *testing.T) {
|
||||
demo312 := buildIntervalsDemo312()
|
||||
tt := []struct {
|
||||
name string
|
||||
intvls intervals.Intervals
|
||||
expectedMerges []intervals.Interval
|
||||
intvls interval.Intervals
|
||||
expectedMerges []interval.Interval
|
||||
}{
|
||||
{name: "demo001", intvls: demo001.Intervals, expectedMerges: demo001.ExpectedMerges},
|
||||
{name: "demo002", intvls: demo002.Intervals, expectedMerges: demo002.ExpectedMerges},
|
||||
|
@ -1,4 +1,4 @@
|
||||
package intervals
|
||||
package interval
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -1,9 +1,9 @@
|
||||
package intervals_test
|
||||
package interval_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/daniel-gil/intervals"
|
||||
"bitbucket.org/differenttravel/interval"
|
||||
)
|
||||
|
||||
func TestOverlapped(t *testing.T) {
|
||||
@ -67,8 +67,8 @@ func TestOverlapped(t *testing.T) {
|
||||
demo312 := buildIntervalsDemo312()
|
||||
tt := []struct {
|
||||
name string
|
||||
intvls intervals.Intervals
|
||||
expectedOverlaps []intervals.Interval
|
||||
intvls interval.Intervals
|
||||
expectedOverlaps []interval.Interval
|
||||
}{
|
||||
{name: "demo001", intvls: demo001.Intervals, expectedOverlaps: demo001.ExpectedOverlaps},
|
||||
{name: "demo002", intvls: demo002.Intervals, expectedOverlaps: demo002.ExpectedOverlaps},
|
||||
|
7
plot.go
7
plot.go
@ -1,4 +1,4 @@
|
||||
package intervals
|
||||
package interval
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -178,7 +178,10 @@ func (ip *intervalPlot) AlignPlots(plotItems []*Superplot, minLow, maxHigh int)
|
||||
}
|
||||
|
||||
func (ip *intervalPlot) CreatePlot(title string, xys plotter.XYs, plotType PlotType) (*Superplot, error) {
|
||||
p := plot.New()
|
||||
p, err := plot.New()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not create plot: %v", err)
|
||||
}
|
||||
|
||||
// Draw a grid behind the data
|
||||
p.Add(plotter.NewGrid())
|
||||
|
@ -1,10 +1,10 @@
|
||||
package intervals_test
|
||||
package interval_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/daniel-gil/intervals"
|
||||
"bitbucket.org/differenttravel/interval"
|
||||
)
|
||||
|
||||
func TestReport(t *testing.T) {
|
||||
@ -14,41 +14,41 @@ func TestReport(t *testing.T) {
|
||||
highInclusive := true
|
||||
selfAdjustMinLow := false
|
||||
selfAdjustMaxHigh := true
|
||||
itvls := intervals.New(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
|
||||
itvls := interval.NewIntervals(minLow, maxHigh, lowInclusive, highInclusive, selfAdjustMinLow, selfAdjustMaxHigh)
|
||||
|
||||
var err error
|
||||
err = itvls.AddInterval(&intervals.Interval{Low: 5, High: 7})
|
||||
err = itvls.AddInterval(&interval.Interval{Low: 5, High: 7})
|
||||
if err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
err = itvls.AddInterval(&intervals.Interval{Low: 2, High: 4})
|
||||
err = itvls.AddInterval(&interval.Interval{Low: 2, High: 4})
|
||||
if err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
err = itvls.AddInterval(&intervals.Interval{Low: 3, High: 6})
|
||||
err = itvls.AddInterval(&interval.Interval{Low: 3, High: 6})
|
||||
if err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
err = itvls.AddInterval(&intervals.Interval{Low: 18, High: 20})
|
||||
err = itvls.AddInterval(&interval.Interval{Low: 18, High: 20})
|
||||
if err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
err = itvls.AddInterval(&intervals.Interval{Low: 20, High: 30})
|
||||
err = itvls.AddInterval(&interval.Interval{Low: 20, High: 30})
|
||||
if err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
err = itvls.AddInterval(&intervals.Interval{Low: 25, High: 28})
|
||||
err = itvls.AddInterval(&interval.Interval{Low: 25, High: 28})
|
||||
if err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
err = itvls.AddInterval(&intervals.Interval{Low: 30, High: 32})
|
||||
err = itvls.AddInterval(&interval.Interval{Low: 30, High: 32})
|
||||
if err != nil {
|
||||
fmt.Printf("invalid interval discarded: %v\n", err)
|
||||
}
|
||||
|
||||
tt := []struct {
|
||||
name string
|
||||
itvls intervals.Intervals
|
||||
itvls interval.Intervals
|
||||
}{
|
||||
{name: "normal case", itvls: itvls},
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user