feat(Go-Tool):2020/12/16: 修复bitStore越位溢出的问题

This commit is contained in:
Huangzj
2020-12-16 15:29:37 +08:00
parent ed5a3d19ed
commit 4b542c3cee
3 changed files with 42 additions and 1 deletions
+3
View File
@@ -72,6 +72,9 @@
2020/12/16: 添加YAML和结构体转换工具 2020/12/16: 添加YAML和结构体转换工具
# 修复日志
2020/12/16 修复bitStore越位溢出的问题
# mod vendor模式加载包 # mod vendor模式加载包
通过go mod的方式加载的github上面的包会有报红的问题,但是包本身是可以运行的,这样就是会有一个问题,如果你想要点击去看方法的内容,没办法做到 通过go mod的方式加载的github上面的包会有报红的问题,但是包本身是可以运行的,这样就是会有一个问题,如果你想要点击去看方法的内容,没办法做到
+1 -1
View File
@@ -72,7 +72,7 @@ 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 - 1) / bit return (gear + bit) / bit
} }
//获取档位所在的二进制位置 //获取档位所在的二进制位置
+38
View File
@@ -9,6 +9,7 @@ package bitStore
import ( import (
"Go-Tool/util/sort" "Go-Tool/util/sort"
"fmt" "fmt"
"math"
"testing" "testing"
) )
@@ -203,3 +204,40 @@ func TestTwo(t *testing.T) {
fmt.Println(fmt.Sprintf("当前map的key为%d,当前map的value为%v", key, value)) fmt.Println(fmt.Sprintf("当前map的key为%d,当前map的value为%v", key, value))
} }
} }
//测试溢出
func TestOverflow(t *testing.T) {
bitStore := NewBitStore(31, nil)
for i := 1; i <= 31; i++ {
bitStore.ReceiveByGear(i)
}
fmt.Println(fmt.Sprintf("MaxInt32 = %v", math.MaxInt32))
for _, r := range bitStore.GearPickList {
fmt.Println(r)
}
bitStore = NewBitStore(32, nil)
for i := 1; i <= 32; i++ {
bitStore.ReceiveByGear(i)
}
for _, r := range bitStore.GearPickList {
fmt.Println(r)
}
bitStore = NewBitStore(33, nil)
for i := 1; i <= 33; i++ {
bitStore.ReceiveByGear(i)
}
fmt.Println("数组信息")
for _, r := range bitStore.GearPickList {
fmt.Println(r)
}
for key, value := range bitStore.FindAllGearMap() {
fmt.Println(key, value)
}
}