Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Francesconi committed Apr 19, 2022
1 parent c9d84aa commit e715f7e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
30 changes: 10 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,31 @@ go get github.com/francesconi/go-rampart
## Examples

```go
a := rampart.NewOrdInterval(2, 3)
b := rampart.NewOrdInterval(3, 7)
a := rampart.NewInterval(2, 3)
b := rampart.NewInterval(3, 7)
rel := a.Relate(b)
// rel: RelationMeets
```

```go
a := rampart.NewTimeInterval(
func compareTimes(t1, t2 time.Time) int {
return int(t1.Sub(t2))
}

a := rampart.NewIntervalFunc(
time.Date(2022, time.April, 1, 0, 0, 0, 0, time.UTC),
time.Date(2022, time.April, 8, 0, 0, 0, 0, time.UTC),
compareTimes,
)
b := rampart.NewTimeInterval(
b := rampart.NewIntervalFunc(
time.Date(2022, time.April, 6, 0, 0, 0, 0, time.UTC),
time.Date(2022, time.April, 15, 0, 0, 0, 0, time.UTC),
compareTimes,
)
rel := a.Relate(b)
// rel: RelationOverlaps
```

```go
func cmp(x, y int) int {
if x < y {
return -1
}
if x == y {
return 0
}
return 1
}
a := rampart.NewIntervalFunc(2, 3, cmp)
b := rampart.NewIntervalFunc(3, 7, cmp)
rel := a.Relate(b)
// rel: RelationMeets
```

![][interval relations]

[interval relations]: ./docs/interval-relations.svg
2 changes: 1 addition & 1 deletion rampart.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// Interval represents two values, the lesser and the greater.
// Both must be either of the same ordered type or time type.
// Both must be of the same type.
type Interval[T any] struct {
x, y T
cmp func(T, T) int
Expand Down
2 changes: 1 addition & 1 deletion rampart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
func TestTimeInterval(t *testing.T) {
now := time.Now()
a := NewIntervalFunc(now.Add(1000), now, func(t1, t2 time.Time) int { return int(t1.Sub(t2)) })
require.Equal(t, a.Lesser(), now)
require.Equal(t, now, a.Lesser())
}

func TestNewInterval(t *testing.T) {
Expand Down

0 comments on commit e715f7e

Please sign in to comment.