From 4b542c3cee3aaeaa97e1ec5298b0f57bc6e88d41 Mon Sep 17 00:00:00 2001 From: Huangzj Date: Wed, 16 Dec 2020 15:29:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(Go-Tool)=EF=BC=9A2020/12/16=EF=BC=9A=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DbitStore=E8=B6=8A=E4=BD=8D=E6=BA=A2=E5=87=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 3 +++ util/bitStore/BitStoreTool.go | 2 +- util/bitStore/BitStoreTool_test.go | 38 ++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 088e7bd..aca102b 100644 --- a/readme.md +++ b/readme.md @@ -72,6 +72,9 @@ 2020/12/16: 添加YAML和结构体转换工具 +# 修复日志 +2020/12/16: 修复bitStore越位溢出的问题 + # mod vendor模式加载包 通过go mod的方式加载的github上面的包会有报红的问题,但是包本身是可以运行的,这样就是会有一个问题,如果你想要点击去看方法的内容,没办法做到 diff --git a/util/bitStore/BitStoreTool.go b/util/bitStore/BitStoreTool.go index 2f08ad1..238673f 100644 --- a/util/bitStore/BitStoreTool.go +++ b/util/bitStore/BitStoreTool.go @@ -72,7 +72,7 @@ func (bitStore *BitStore) checkGearRight(gear int) { //获取当前档位对应的数组长度(这边的length是从1开始的.) func (bitStore *BitStore) getGearListLength(gear int) int { - return (gear + bit - 1) / bit + return (gear + bit) / bit } //获取档位所在的二进制位置 diff --git a/util/bitStore/BitStoreTool_test.go b/util/bitStore/BitStoreTool_test.go index 8dbead6..153ad3e 100644 --- a/util/bitStore/BitStoreTool_test.go +++ b/util/bitStore/BitStoreTool_test.go @@ -9,6 +9,7 @@ package bitStore import ( "Go-Tool/util/sort" "fmt" + "math" "testing" ) @@ -203,3 +204,40 @@ func TestTwo(t *testing.T) { 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) + } +}