This commit is contained in:
Todd Gruben 2018-11-26 15:05:43 -06:00
parent 0404354faa
commit f6d34b42ba
3 changed files with 37 additions and 39 deletions

View file

@ -3210,7 +3210,7 @@ func TestExecutor_Execute_Shift(t *testing.T) {
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Shift(Shift(Row(general=10)))`}); err != nil {
t.Fatal(err)
} else if columns := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(columns, []uint64{ShardWidth+1}) {
} else if columns := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(columns, []uint64{ShardWidth + 1}) {
t.Fatalf("unexpected columns: %+v", columns)
}
})
@ -3221,10 +3221,10 @@ func TestExecutor_Execute_Shift(t *testing.T) {
hldr := test.Holder{Holder: c[0].Server.Holder()}
hldr.SetBit("i", "general", 10, ShardWidth-2) //shardwidth -1
hldr.SetBit("i", "general", 10, ShardWidth-1) //shardwidth
hldr.SetBit("i", "general", 10, ShardWidth) //shardwidth +1
hldr.SetBit("i", "general", 10, ShardWidth) //shardwidth +1
hldr.SetBit("i", "general", 10, ShardWidth+2) //shardwidth +3
exp:=[]uint64{ ShardWidth-1,ShardWidth,ShardWidth+1,ShardWidth+3}
exp := []uint64{ShardWidth - 1, ShardWidth, ShardWidth + 1, ShardWidth + 3}
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Shift(Row(general=10))`}); err != nil {
t.Fatal(err)
} else if columns := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(columns, exp) {
@ -3232,8 +3232,8 @@ func TestExecutor_Execute_Shift(t *testing.T) {
}
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Shift(Shift(Row(general=10)))`}); err != nil {
t.Fatal(err)
} else if columns := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(columns,[]uint64{ ShardWidth,ShardWidth+1,ShardWidth+2,ShardWidth+4} ) {
t.Fatalf("unexpected columns: \n%+v\n%+v", columns,exp)
} else if columns := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(columns, []uint64{ShardWidth, ShardWidth + 1, ShardWidth + 2, ShardWidth + 4}) {
t.Fatalf("unexpected columns: \n%+v\n%+v", columns, exp)
}
})

View file

@ -124,7 +124,6 @@ func bitmapFirstBitSecoundRowSet() []uint64 {
return bitmap
}
func bitmapLastBitSet() []uint64 {
bitmap := make([]uint64, bitmapN)
bitmap[bitmapN-1] = 0x8000000000000000

View file

@ -3292,7 +3292,7 @@ func TestEquals(t *testing.T) {
func TestShiftArray(t *testing.T) {
a := &Container{
containerType: containerArray,
}
}
tests := []struct {
array []uint16
exp []uint16
@ -3307,7 +3307,7 @@ func TestShiftArray(t *testing.T) {
},
{
array: []uint16{1, 2, 3, 4, 5, 11, 12},
exp: []uint16{2, 3, 4, 5, 6, 12,13},
exp: []uint16{2, 3, 4, 5, 6, 12, 13},
},
{
array: []uint16{65535},
@ -3318,13 +3318,12 @@ func TestShiftArray(t *testing.T) {
for i, test := range tests {
a.array = test.array
a.n = int32(len(a.array))
ret,_ := shiftArray(a)
ret, _ := shiftArray(a)
if !reflect.DeepEqual(ret.array, test.exp) {
t.Fatalf("test #%v expected %v, but got %v", i, test.exp, ret.array)
}
}
}
}
func TestShiftBitmap(t *testing.T) {
a := &Container{
@ -3332,72 +3331,72 @@ func TestShiftBitmap(t *testing.T) {
}
tests := []struct {
bitmap []uint64
exp []uint64
exp []uint64
}{
{
bitmap:bitmapFirstBitSet() ,
exp: bitmapSecondBitSet(),
bitmap: bitmapFirstBitSet(),
exp: bitmapSecondBitSet(),
},
{
bitmap:bitmapLastBitSet() ,
exp: bitmapEmpty(),
bitmap: bitmapLastBitSet(),
exp: bitmapEmpty(),
},
{
bitmap:bitmapLastBitFirstRowSet() ,
exp: bitmapFirstBitSecoundRowSet (),
bitmap: bitmapLastBitFirstRowSet(),
exp: bitmapFirstBitSecoundRowSet(),
},
}
for i, test := range tests {
a.bitmap = test.bitmap
a.n = 1
ret,_ := shiftBitmap(a)
ret, _ := shiftBitmap(a)
if !reflect.DeepEqual(ret.bitmap, test.exp) {
t.Fatalf("test #%v expected %v, but got %v", i, test.exp, ret.bitmap)
}
}
}
}
func TestShiftRun(t *testing.T) {
a := &Container{
containerType: containerRun,
}
tests := []struct {
runs []interval16
n int32
en int32
runs []interval16
n int32
en int32
exp []interval16
carry bool
}{
{
runs: []interval16{{start: 5, last: 10}},
n: 5,
en: 5,
exp: []interval16{{start: 6, last: 11}},
n: 5,
en: 5,
exp: []interval16{{start: 6, last: 11}},
carry: false,
},
{
runs: []interval16{{start: 5, last:65535 }},
n: 65530,
en: 65529,
exp: []interval16{{start: 6, last: 65535}},
runs: []interval16{{start: 5, last: 65535}},
n: 65530,
en: 65529,
exp: []interval16{{start: 6, last: 65535}},
carry: true,
},
{
runs: []interval16{{start: 65535, last:65535 }},
n: 1,
en: 0,
exp: []interval16{},
carry: true,
runs: []interval16{{start: 65535, last: 65535}},
n: 1,
en: 0,
exp: []interval16{},
carry: true,
},
}
for i, test := range tests {
a.runs = test.runs
a.n = test.n
ret,c := shiftRun(a)
if !reflect.DeepEqual(ret.runs, test.exp) && c == test.carry && ret.n == test.en {
t.Fatalf("test #%v expected %v, but got %v %d", i, test.exp, ret.runs,ret.n)
ret, c := shiftRun(a)
if !reflect.DeepEqual(ret.runs, test.exp) && c == test.carry && ret.n == test.en {
t.Fatalf("test #%v expected %v, but got %v %d", i, test.exp, ret.runs, ret.n)
}
}
}
}