feat(Go-Tool):修复bitstore移位问题,修改单测
This commit is contained in:
@@ -13,6 +13,7 @@ import "fmt"
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
bit = 32
|
bit = 32
|
||||||
|
realBit = 31
|
||||||
)
|
)
|
||||||
|
|
||||||
type BitStore struct {
|
type BitStore struct {
|
||||||
@@ -72,12 +73,12 @@ func (bitStore *BitStore) checkGearRight(gear int) {
|
|||||||
|
|
||||||
//获取当前档位对应的数组长度(这边的length是从1开始的.)
|
//获取当前档位对应的数组长度(这边的length是从1开始的.)
|
||||||
func (bitStore *BitStore) getGearListLength(gear int) int {
|
func (bitStore *BitStore) getGearListLength(gear int) int {
|
||||||
return (gear + bit) / bit
|
return ((gear - 1) + (bit - 1)) / (bit - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取档位所在的二进制位置
|
//获取档位所在的二进制位置
|
||||||
func (bitStore *BitStore) getGearPosition(gear, length int) int {
|
func (bitStore *BitStore) getGearPosition(gear, length int) int {
|
||||||
return (gear - bit*(length-1)) - 1
|
return gear - (bit-1)*(length-1) - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bitStore *BitStore) getSizeOrInit() int {
|
func (bitStore *BitStore) getSizeOrInit() int {
|
||||||
@@ -90,8 +91,8 @@ func (bitStore *BitStore) getSizeOrInit() int {
|
|||||||
func (bitStore *BitStore) fullListDeal(listSize int, length int) map[int]bool {
|
func (bitStore *BitStore) fullListDeal(listSize int, length int) map[int]bool {
|
||||||
resultMap := make(map[int]bool, 0)
|
resultMap := make(map[int]bool, 0)
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length; i++ {
|
||||||
for j := 0; j < bit && bitStore.MaxGear > i*bit+j; j++ {
|
for j := 0; j < bit-1 && bitStore.MaxGear > i*(bit-1)+j; j++ {
|
||||||
resultMap[i*bit+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0
|
resultMap[i*(bit-1)+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resultMap
|
return resultMap
|
||||||
@@ -100,13 +101,13 @@ func (bitStore *BitStore) fullListDeal(listSize int, length int) map[int]bool {
|
|||||||
func (bitStore *BitStore) shortListDeal(listSize, length int) map[int]bool {
|
func (bitStore *BitStore) shortListDeal(listSize, length int) map[int]bool {
|
||||||
resultMap := make(map[int]bool, 0)
|
resultMap := make(map[int]bool, 0)
|
||||||
for i := 0; i < listSize; i++ {
|
for i := 0; i < listSize; i++ {
|
||||||
for j := 0; j < bit; j++ {
|
for j := 0; j < (bit - 1); j++ {
|
||||||
resultMap[i*bit+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0
|
resultMap[i*(bit-1)+j+1] = (bitStore.GearPickList[i] & (1 << uint(j))) > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i := listSize; i < length; i++ {
|
for i := listSize; i < length; i++ {
|
||||||
for j := 0; j < bit && bitStore.MaxGear > i*bit+j; j++ {
|
for j := 0; j < (bit-1) && bitStore.MaxGear > i*(bit-1)+j; j++ {
|
||||||
resultMap[i*bit+j+1] = false
|
resultMap[i*(bit-1)+j+1] = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resultMap
|
return resultMap
|
||||||
|
|||||||
@@ -47,25 +47,35 @@ func TestOneThousand(t *testing.T) {
|
|||||||
newStoreMap(bitStore) //初始化的校验
|
newStoreMap(bitStore) //初始化的校验
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
bitStore.ReceiveByGear(3)
|
bitStore.ReceiveByGear(1)
|
||||||
fmt.Println(fmt.Sprintf("这个时候领取结果 3应该返回true,结果是:%v", bitStore.IsGearReceive(3)))
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0]))
|
||||||
|
fmt.Println(fmt.Sprintf("这个时候领取结果 1应该返回true,结果是:%v", bitStore.IsGearReceive(3)))
|
||||||
bitStore.ReceiveByGear(8)
|
bitStore.ReceiveByGear(8)
|
||||||
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0]))
|
||||||
fmt.Println(fmt.Sprintf("这个时候领取结果 8应该返回true,结果是:%v", bitStore.IsGearReceive(8)))
|
fmt.Println(fmt.Sprintf("这个时候领取结果 8应该返回true,结果是:%v", bitStore.IsGearReceive(8)))
|
||||||
bitStore.ReceiveByGear(16)
|
bitStore.ReceiveByGear(16)
|
||||||
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0]))
|
||||||
fmt.Println(fmt.Sprintf("这个时候领取结果 16应该返回true,结果是:%v", bitStore.IsGearReceive(16)))
|
fmt.Println(fmt.Sprintf("这个时候领取结果 16应该返回true,结果是:%v", bitStore.IsGearReceive(16)))
|
||||||
bitStore.ReceiveByGear(18)
|
bitStore.ReceiveByGear(18)
|
||||||
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0]))
|
||||||
fmt.Println(fmt.Sprintf("这个时候领取结果 18应该返回true,结果是:%v", bitStore.IsGearReceive(18)))
|
fmt.Println(fmt.Sprintf("这个时候领取结果 18应该返回true,结果是:%v", bitStore.IsGearReceive(18)))
|
||||||
bitStore.ReceiveByGear(27)
|
bitStore.ReceiveByGear(27)
|
||||||
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[0]))
|
||||||
fmt.Println(fmt.Sprintf("这个时候领取结果 27应该返回true,结果是:%v", bitStore.IsGearReceive(27)))
|
fmt.Println(fmt.Sprintf("这个时候领取结果 27应该返回true,结果是:%v", bitStore.IsGearReceive(27)))
|
||||||
bitStore.ReceiveByGear(32)
|
bitStore.ReceiveByGear(32)
|
||||||
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1]))
|
||||||
fmt.Println(fmt.Sprintf("这个时候领取结果 32应该返回true,结果是:%v", bitStore.IsGearReceive(32)))
|
fmt.Println(fmt.Sprintf("这个时候领取结果 32应该返回true,结果是:%v", bitStore.IsGearReceive(32)))
|
||||||
bitStore.ReceiveByGear(33)
|
bitStore.ReceiveByGear(33)
|
||||||
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1]))
|
||||||
fmt.Println(fmt.Sprintf("这个时候领取结果 33应该返回true,结果是:%v", bitStore.IsGearReceive(33)))
|
fmt.Println(fmt.Sprintf("这个时候领取结果 33应该返回true,结果是:%v", bitStore.IsGearReceive(33)))
|
||||||
bitStore.ReceiveByGear(53)
|
bitStore.ReceiveByGear(53)
|
||||||
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1]))
|
||||||
fmt.Println(fmt.Sprintf("这个时候领取结果 53应该返回true,结果是:%v", bitStore.IsGearReceive(53)))
|
fmt.Println(fmt.Sprintf("这个时候领取结果 53应该返回true,结果是:%v", bitStore.IsGearReceive(53)))
|
||||||
bitStore.ReceiveByGear(44)
|
bitStore.ReceiveByGear(44)
|
||||||
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1]))
|
||||||
fmt.Println(fmt.Sprintf("这个时候领取结果 44应该返回true,结果是:%v", bitStore.IsGearReceive(44)))
|
fmt.Println(fmt.Sprintf("这个时候领取结果 44应该返回true,结果是:%v", bitStore.IsGearReceive(44)))
|
||||||
bitStore.ReceiveByGear(48)
|
bitStore.ReceiveByGear(48)
|
||||||
|
fmt.Println(fmt.Sprintf("%b", bitStore.GearPickList[1]))
|
||||||
|
|
||||||
fmt.Println(fmt.Sprintf("判断当前数组是否动态增长,当前数组长度为:%d", len(bitStore.GearPickList)))
|
fmt.Println(fmt.Sprintf("判断当前数组是否动态增长,当前数组长度为:%d", len(bitStore.GearPickList)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user