123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- package filer
- import (
- "fmt"
- "github.com/stretchr/testify/assert"
- "testing"
- )
- type IntervalInt int
- func (i IntervalInt) SetStartStop(start, stop int64) {
- }
- func (i IntervalInt) Clone() IntervalValue {
- return i
- }
- func TestIntervalList_Overlay(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(0, 100, 1, 1)
- list.Overlay(50, 150, 2, 2)
- list.Overlay(200, 250, 3, 3)
- list.Overlay(225, 250, 4, 4)
- list.Overlay(175, 210, 5, 5)
- list.Overlay(0, 25, 6, 6)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 6, list.Len())
- println()
- list.Overlay(50, 150, 7, 7)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 6, list.Len())
- }
- func TestIntervalList_Overlay2(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(50, 100, 1, 1)
- list.Overlay(0, 50, 2, 2)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- }
- func TestIntervalList_Overlay3(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(50, 100, 1, 1)
- assert.Equal(t, 1, list.Len())
- list.Overlay(0, 60, 2, 2)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 2, list.Len())
- }
- func TestIntervalList_Overlay4(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(50, 100, 1, 1)
- list.Overlay(0, 100, 2, 2)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 1, list.Len())
- }
- func TestIntervalList_Overlay5(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(50, 100, 1, 1)
- list.Overlay(0, 110, 2, 2)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 1, list.Len())
- }
- func TestIntervalList_Overlay6(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(50, 100, 1, 1)
- list.Overlay(50, 110, 2, 2)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 1, list.Len())
- }
- func TestIntervalList_Overlay7(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(50, 100, 1, 1)
- list.Overlay(50, 90, 2, 2)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 2, list.Len())
- }
- func TestIntervalList_Overlay8(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(50, 100, 1, 1)
- list.Overlay(60, 90, 2, 2)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 3, list.Len())
- }
- func TestIntervalList_Overlay9(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(50, 100, 1, 1)
- list.Overlay(60, 100, 2, 2)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 2, list.Len())
- }
- func TestIntervalList_Overlay10(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(50, 100, 1, 1)
- list.Overlay(60, 110, 2, 2)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 2, list.Len())
- }
- func TestIntervalList_Overlay11(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.Overlay(0, 100, 1, 1)
- list.Overlay(100, 110, 2, 2)
- list.Overlay(0, 90, 3, 3)
- list.Overlay(0, 80, 4, 4)
- list.Overlay(0, 90, 5, 5)
- list.Overlay(90, 90, 6, 6)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 3, list.Len())
- }
- func TestIntervalList_insertInterval1(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(50, 150, 2, 2)
- list.InsertInterval(200, 250, 3, 3)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 2, list.Len())
- }
- func TestIntervalList_insertInterval2(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(50, 150, 2, 2)
- list.InsertInterval(0, 25, 3, 3)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 2, list.Len())
- }
- func TestIntervalList_insertInterval3(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(50, 150, 2, 2)
- list.InsertInterval(200, 250, 4, 4)
- list.InsertInterval(0, 75, 3, 3)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 3, list.Len())
- }
- func TestIntervalList_insertInterval4(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(200, 250, 4, 4)
- list.InsertInterval(0, 225, 3, 3)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 2, list.Len())
- }
- func TestIntervalList_insertInterval5(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(200, 250, 4, 4)
- list.InsertInterval(0, 225, 5, 5)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 2, list.Len())
- }
- func TestIntervalList_insertInterval6(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(50, 150, 2, 2)
- list.InsertInterval(200, 250, 4, 4)
- list.InsertInterval(0, 275, 1, 1)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 5, list.Len())
- }
- func TestIntervalList_insertInterval7(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(50, 150, 2, 2)
- list.InsertInterval(200, 250, 4, 4)
- list.InsertInterval(75, 275, 1, 1)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 4, list.Len())
- }
- func TestIntervalList_insertInterval8(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(50, 150, 2, 2)
- list.InsertInterval(200, 250, 4, 4)
- list.InsertInterval(75, 275, 3, 3)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 4, list.Len())
- }
- func TestIntervalList_insertInterval9(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(50, 150, 2, 2)
- list.InsertInterval(200, 250, 4, 4)
- list.InsertInterval(50, 150, 3, 3)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 2, list.Len())
- }
- func TestIntervalList_insertInterval10(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(50, 100, 2, 2)
- list.InsertInterval(200, 300, 4, 4)
- list.InsertInterval(100, 200, 5, 5)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 3, list.Len())
- }
- func TestIntervalList_insertInterval11(t *testing.T) {
- list := NewIntervalList[IntervalInt]()
- list.InsertInterval(0, 64, 1, 1)
- list.InsertInterval(72, 136, 3, 3)
- list.InsertInterval(64, 128, 2, 2)
- list.InsertInterval(68, 72, 4, 4)
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 4, list.Len())
- }
- type IntervalStruct struct {
- x int
- start int64
- stop int64
- }
- func newIntervalStruct(i int) IntervalStruct {
- return IntervalStruct{
- x: i,
- }
- }
- func (i IntervalStruct) SetStartStop(start, stop int64) {
- i.start, i.stop = start, stop
- }
- func (i IntervalStruct) Clone() IntervalValue {
- return &IntervalStruct{
- x: i.x,
- start: i.start,
- stop: i.stop,
- }
- }
- func TestIntervalList_insertIntervalStruct(t *testing.T) {
- list := NewIntervalList[IntervalStruct]()
- list.InsertInterval(0, 64, 1, newIntervalStruct(1))
- list.InsertInterval(64, 72, 2, newIntervalStruct(2))
- list.InsertInterval(72, 136, 3, newIntervalStruct(3))
- list.InsertInterval(64, 68, 4, newIntervalStruct(4))
- for p := list.Front(); p != nil; p = p.Next {
- fmt.Printf("[%d,%d) %d %d\n", p.StartOffset, p.StopOffset, p.TsNs, p.Value)
- }
- assert.Equal(t, 4, list.Len())
- }
|