package chunkenc import ( "fmt" "testing" ) func TestCumdelta(t *testing.T) { var ( fracDigits byte = 0 buf = make([]byte, minBufferSize) value float64 done bool ) c := NewReverseCumulativeDeltaCompressor(buf, 0, fracDigits) // c.Append(1.55) // c.Append(23) // c.Append(23) // c.Append(23) // c.Append(23.5) c.Append(130) c.Append(191) c.Append(248) c.Append(305) //fmt.Printf("pos: %d\n", c.pos) //fmt.Printf("%d\n", buf.Chunks()[0]) d := NewReverseCumulativeDeltaDecompressor(buf, c.Size(), fracDigits) for range 8 { value, done = d.NextValue() fmt.Println(value, done) } } func TestInsdelta(t *testing.T) { var ( fracDigits byte = 2 buf = make([]byte, minBufferSize) value float64 done bool ) c := NewReverseInstantDeltaCompressor(buf, 0, fracDigits) c.Append(-1.55) c.Append(23) //fmt.Printf("pos: %d\n", c.pos) //fmt.Printf("%d\n", buf.Chunks()[0]) c.Append(23) c.Append(23) c.Append(-23.5) //fmt.Printf("pos: %d\n", c.pos) //fmt.Printf("%d\n", buf.Chunks()[0]) d := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits) for range 8 { value, done = d.NextValue() fmt.Println(value, done) } } func TestTimeDelta(t *testing.T) { var ( buf = make([]byte, minBufferSize) value uint32 done bool ) c := NewReverseTimeDeltaCompressor(buf, 0) c.Append(10) //c.Append(131) //fmt.Printf("pos: %d\n", c.pos) //fmt.Printf("%d\n", buf.Chunks()[0]) c.Append(70) c.Append(130) c.Append(191) c.Append(248) c.Append(305) c.Append(330) c.Append(390) c.Append(450) // fmt.Printf("pos: %d\n", c.pos) // fmt.Printf("%d\n", buf.Chunks()[0]) //c.Sync() // bound := c.GetState() // fmt.Println("AFTER SYNC") // fmt.Printf("pos: %d\n", c.pos) // chunks := buf.Chunks() // if len(chunks) > 0 { // fmt.Printf("%d\n", chunks[0]) // } d := NewReverseTimeDeltaDecompressor(buf, c.Size()) // d.RestoreFromBound(bound) //d.RestoreFromEnd() for range 12 { value, done = d.NextValue() fmt.Println(value, done) } } func TestCumdeltaBound(t *testing.T) { var ( fracDigits byte = 0 buf = make([]byte, minBufferSize) value float64 done bool ) c := NewReverseCumulativeDeltaCompressor(buf, 0, fracDigits) // c.Append(1.55) // c.Append(23) // c.Append(23) // c.Append(23) // c.Append(23.5) c.Append(10) c.Append(70) c.Append(130) // fmt.Printf("pos: %d\n", c.pos) // fmt.Printf("%d\n", buf.Chunks()[0]) c.Append(191) // fmt.Printf("pos: %d\n", c.pos) // fmt.Printf("%d\n", buf.Chunks()[0]) c.Append(191) fmt.Printf("pos: %d\n", c.pos) fmt.Printf("%d\n", buf.Chunks()[0]) ////////////////////////// c.Lock() //fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H) c.Append(248) c.Append(305) fmt.Printf("pos: %d\n", c.pos) fmt.Printf("%d\n", buf.Chunks()[0]) d := NewReverseCumulativeDeltaDecompressor(buf, c.Size(), fracDigits) d.RestoreFromEnd() for range 8 { value, done = d.NextValue() fmt.Println(value, done) } //boundDecompressor := NewReverseCumulativeDeltaDecompressor(buf, c.Size(), fracDigits) //boundDecompressor.RestoreFromBound(bound) boundDecompressor := c.CreateDecompressor(fracDigits) fmt.Println("from bound:") for range 8 { value, done = boundDecompressor.NextValue() fmt.Println(value, done) } } func TestInsdeltaBound(t *testing.T) { var ( fracDigits byte = 0 buf = make([]byte, minBufferSize) value float64 done bool ) c := NewReverseInstantDeltaCompressor(buf, 0, fracDigits) // c.Append(1.55) // c.Append(23) // c.Append(23) // c.Append(23) // c.Append(23.5) c.Append(10) c.Append(70) c.Append(130) // fmt.Printf("pos: %d\n", c.pos) // fmt.Printf("%d\n", buf.Chunks()[0]) c.Append(191) // fmt.Printf("pos: %d\n", c.pos) // fmt.Printf("%d\n", buf.Chunks()[0]) c.Append(191) fmt.Printf("pos: %d\n", c.pos) fmt.Printf("%d\n", buf.Chunks()[0]) ////////////////////////// //bound := c.GetState() //fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H) c.Append(248) c.Append(305) fmt.Printf("pos: %d\n", c.pos) fmt.Printf("%d\n", buf.Chunks()[0]) d := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits) d.RestoreFromEnd() for range 8 { value, done = d.NextValue() fmt.Println(value, done) } boundDecompressor := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits) //boundDecompressor.RestoreFromBound(bound) fmt.Println("from bound:") for range 8 { value, done = boundDecompressor.NextValue() fmt.Println(value, done) } } func TestInsdeltaBound2(t *testing.T) { var ( fracDigits byte = 0 buf = make([]byte, minBufferSize) value float64 done bool ) c := NewReverseInstantDeltaCompressor(buf, 0, fracDigits) // c.Append(1.55) // c.Append(23) // c.Append(23) // c.Append(23) // c.Append(23.5) c.Append(305) c.Append(248) c.Append(191) // fmt.Printf("pos: %d\n", c.pos) // fmt.Printf("%d\n", buf.Chunks()[0]) c.Append(191) // fmt.Printf("pos: %d\n", c.pos) // fmt.Printf("%d\n", buf.Chunks()[0]) c.Append(130) fmt.Printf("pos: %d\n", c.pos) fmt.Printf("%d\n", buf.Chunks()[0]) ////////////////////////// //bound := c.GetState() //fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H) c.Append(70) c.Append(10) fmt.Printf("pos: %d\n", c.pos) fmt.Printf("%d\n", buf.Chunks()[0]) d := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits) d.RestoreFromEnd() for range 8 { value, done = d.NextValue() fmt.Println(value, done) } boundDecompressor := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits) //sboundDecompressor.RestoreFromBound(bound) fmt.Println("from bound:") for range 8 { value, done = boundDecompressor.NextValue() fmt.Println(value, done) } } func TestCap(t *testing.T) { a := make([]byte, 0, 10) fmt.Println("len:", len(a)) fmt.Println("cap:", cap(a)) a = append(a, 1) fmt.Println("after append:") fmt.Println("len:", len(a)) fmt.Println("cap:", cap(a)) fmt.Println("a:", a) a[1] = 55 fmt.Println("after []:") fmt.Println("len:", len(a)) fmt.Println("cap:", cap(a)) fmt.Println("a:", a) a = append(a, 2) fmt.Println("after 2nd append:") fmt.Println("len:", len(a)) fmt.Println("cap:", cap(a)) fmt.Println("a:", a) }