feat(Go-Tool):包方法重构
This commit is contained in:
+1
-59
@@ -6,64 +6,6 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
|
||||||
"Go-Tool/util/reflectM"
|
|
||||||
"fmt"
|
|
||||||
"math"
|
|
||||||
"reflect"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//fmt.Println(util.Crc32Mode("ewqeqweqw", 4))
|
|
||||||
//fmt.Println(util.Crc32Mode("sdasdsa", 4))
|
|
||||||
//fmt.Println(util.Crc32Mode("dasdsadasdas", 4))
|
|
||||||
//fmt.Println(util.Crc32Mode("321321312", 4))
|
|
||||||
//fmt.Println(util.Crc32Mode("dsadas", 4))
|
|
||||||
//fmt.Println(util.Crc32Mode("dasd23132131", 4))
|
|
||||||
//fmt.Println(util.Crc32Mode("eqwewqewqd4312312", 4))
|
|
||||||
//fmt.Println(util.Crc32Mode("3123213dasdasdas", 4))
|
|
||||||
//fmt.Println(util.Crc32Mode("312321dfdsfsdg", 4))
|
|
||||||
//fmt.Println(util.Crc32Mode("ewqrewrqwe", 4))
|
|
||||||
fmt.Println(int(math.Ceil(1.1)))
|
|
||||||
fmt.Println(int(math.Ceil(1.6)))
|
|
||||||
fmt.Println(int(math.Floor(1.1)))
|
|
||||||
fmt.Println(int(math.Floor(1.6)))
|
|
||||||
//testReflect()
|
|
||||||
}
|
|
||||||
|
|
||||||
func testReflect() {
|
|
||||||
entity := Entity{
|
|
||||||
Num: 1,
|
|
||||||
S: "1223",
|
|
||||||
T: make(map[string]string),
|
|
||||||
}
|
|
||||||
structMap := reflectM.GetStructFieldTypeMap(entity)
|
|
||||||
fmt.Println("根据结构体获取Map结构")
|
|
||||||
for key, val := range structMap {
|
|
||||||
fmt.Println(fmt.Sprintf("结构体属性,key: %v ,value: %v ", key, val))
|
|
||||||
}
|
|
||||||
|
|
||||||
strMap := reflectM.GetPtrFieldTypeMap(&entity)
|
|
||||||
fmt.Println("根据结构体的指针对象获取Map结构")
|
|
||||||
for key, val := range strMap {
|
|
||||||
fmt.Println(fmt.Sprintf("结构体属性,key: %v ,value: %v ", key, val))
|
|
||||||
}
|
|
||||||
|
|
||||||
ptrList := reflectM.GetPtrTypeFieldNameList(reflect.TypeOf(&entity))
|
|
||||||
fmt.Println("根据结构体指针类型获取对应的属性名")
|
|
||||||
for _, val := range ptrList {
|
|
||||||
fmt.Println(fmt.Sprintf("字段名:%s ", val))
|
|
||||||
}
|
|
||||||
|
|
||||||
structList := reflectM.GetStructTypeFieldNameList(reflect.TypeOf(entity))
|
|
||||||
fmt.Println("根据结构体类型获取对应所有字段名称")
|
|
||||||
for _, val := range structList {
|
|
||||||
fmt.Println(fmt.Sprintf("字段名:%s ", val))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Entity struct {
|
|
||||||
Num int
|
|
||||||
S string
|
|
||||||
T map[string]string
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package testHeap
|
package testContainer
|
||||||
|
|
||||||
type Person struct {
|
type Person struct {
|
||||||
Name string //名字
|
Name string //名字
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package testHeap
|
package testContainer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
* @Description:测试list.go包的元素
|
* @Description:测试list.go包的元素
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package testHeap
|
package testContainer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
* @Description:
|
* @Description:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package testHeap
|
package testContainer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/ring"
|
"container/ring"
|
||||||
@@ -11,18 +11,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBitTool(t *testing.T) {
|
func TestSetZeroBuPosition(t *testing.T) {
|
||||||
JudgeIfEvenTest()
|
|
||||||
JudgeIfOddTest()
|
|
||||||
JudgeOneWithPositionTest()
|
|
||||||
JudgeOnlyOneBitWithOneTest()
|
|
||||||
JudgeWithEqualSymbolTest()
|
|
||||||
SetOneByPositionTest()
|
|
||||||
SetZeroBuPositionTest()
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetZeroBuPositionTest() {
|
|
||||||
fmt.Println("设置某个位置上的元素为0")
|
fmt.Println("设置某个位置上的元素为0")
|
||||||
fmt.Println(fmt.Sprintf("原始: %16b", 1))
|
fmt.Println(fmt.Sprintf("原始: %16b", 1))
|
||||||
fmt.Println(fmt.Sprintf("结果:%16b", SetZeroBuPosition(1, 1)))
|
fmt.Println(fmt.Sprintf("结果:%16b", SetZeroBuPosition(1, 1)))
|
||||||
@@ -42,7 +31,7 @@ func SetZeroBuPositionTest() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetOneByPositionTest() {
|
func TestSetOneByPosition(t *testing.T) {
|
||||||
fmt.Println("设置某个位置上的元素为1")
|
fmt.Println("设置某个位置上的元素为1")
|
||||||
fmt.Println(fmt.Sprintf("原始: %16b", 2))
|
fmt.Println(fmt.Sprintf("原始: %16b", 2))
|
||||||
fmt.Println(fmt.Sprintf("结果:%16b", SetOneByPosition(2, 1)))
|
fmt.Println(fmt.Sprintf("结果:%16b", SetOneByPosition(2, 1)))
|
||||||
@@ -63,7 +52,7 @@ func SetOneByPositionTest() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
func JudgeWithEqualSymbolTest() {
|
func TestJudgeWithEqualSymbol(t *testing.T) {
|
||||||
fmt.Println("判断两个数正负符号是否一致")
|
fmt.Println("判断两个数正负符号是否一致")
|
||||||
fmt.Println(JudgeWithEqualSymbol(10, 20))
|
fmt.Println(JudgeWithEqualSymbol(10, 20))
|
||||||
fmt.Println(JudgeWithEqualSymbol(10, -20))
|
fmt.Println(JudgeWithEqualSymbol(10, -20))
|
||||||
@@ -72,7 +61,7 @@ func JudgeWithEqualSymbolTest() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
func JudgeOneWithPositionTest() {
|
func TestJudgeOneWithPosition(t *testing.T) {
|
||||||
fmt.Println("判断二进制表示的某个位上是否为1")
|
fmt.Println("判断二进制表示的某个位上是否为1")
|
||||||
fmt.Println(fmt.Sprintf("%16b", 1))
|
fmt.Println(fmt.Sprintf("%16b", 1))
|
||||||
fmt.Println(JudgeOneWithPosition(1, 1))
|
fmt.Println(JudgeOneWithPosition(1, 1))
|
||||||
@@ -87,7 +76,7 @@ func JudgeOneWithPositionTest() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
func JudgeIfOddTest() {
|
func TestJudgeIfOdd(t *testing.T) {
|
||||||
fmt.Println("奇数的判断")
|
fmt.Println("奇数的判断")
|
||||||
fmt.Println(JudgeIfOdd(1))
|
fmt.Println(JudgeIfOdd(1))
|
||||||
fmt.Println(JudgeIfOdd(2))
|
fmt.Println(JudgeIfOdd(2))
|
||||||
@@ -99,7 +88,7 @@ func JudgeIfOddTest() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
func JudgeIfEvenTest() {
|
func TestJudgeIfEven(t *testing.T) {
|
||||||
fmt.Println("偶数的判断")
|
fmt.Println("偶数的判断")
|
||||||
fmt.Println(JudgeIfEven(1))
|
fmt.Println(JudgeIfEven(1))
|
||||||
fmt.Println(JudgeIfEven(2))
|
fmt.Println(JudgeIfEven(2))
|
||||||
@@ -111,7 +100,7 @@ func JudgeIfEvenTest() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
func JudgeOnlyOneBitWithOneTest() {
|
func TestJudgeOnlyOneBitWithOne(t *testing.T) {
|
||||||
fmt.Println("判断二进制表示是不是只有一个位为1")
|
fmt.Println("判断二进制表示是不是只有一个位为1")
|
||||||
fmt.Println(JudgeOnlyOneBitWithOne(1))
|
fmt.Println(JudgeOnlyOneBitWithOne(1))
|
||||||
fmt.Println(JudgeOnlyOneBitWithOne(2))
|
fmt.Println(JudgeOnlyOneBitWithOne(2))
|
||||||
|
|||||||
@@ -12,32 +12,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBitStore(t *testing.T) {
|
|
||||||
//fmt.Println("测试2档的情况")
|
|
||||||
//testTwo()
|
|
||||||
//fmt.Println()
|
|
||||||
//
|
|
||||||
//fmt.Println("测试10档的情况")
|
|
||||||
//testTen()
|
|
||||||
//fmt.Println()
|
|
||||||
//
|
|
||||||
//fmt.Println("测试18档的情况")
|
|
||||||
//testEighteen()
|
|
||||||
//fmt.Println()
|
|
||||||
|
|
||||||
//fmt.Println("测试33档的情况")
|
|
||||||
//testThirtyThree()
|
|
||||||
//fmt.Println()
|
|
||||||
|
|
||||||
//fmt.Println("测试58档的情况")
|
|
||||||
//testFiftyEight()
|
|
||||||
//fmt.Println()
|
|
||||||
|
|
||||||
fmt.Println("测试1000档的情况")
|
|
||||||
testOneThousand()
|
|
||||||
fmt.Println()
|
|
||||||
}
|
|
||||||
|
|
||||||
func newStoreMap(bitStore *BitStore) {
|
func newStoreMap(bitStore *BitStore) {
|
||||||
gearMap := bitStore.FindAllGearMap()
|
gearMap := bitStore.FindAllGearMap()
|
||||||
falseList := make([]int, 0)
|
falseList := make([]int, 0)
|
||||||
@@ -66,7 +40,7 @@ func getReceiveResult(bitStore *BitStore) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testOneThousand() {
|
func TestOneThousand(t *testing.T) {
|
||||||
bitStore := NewBitStore(1000, nil)
|
bitStore := NewBitStore(1000, nil)
|
||||||
|
|
||||||
newStoreMap(bitStore) //初始化的校验
|
newStoreMap(bitStore) //初始化的校验
|
||||||
@@ -115,7 +89,7 @@ func testOneThousand() {
|
|||||||
getReceiveResult(bitStore)
|
getReceiveResult(bitStore)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testFiftyEight() {
|
func TestFiftyEight(t *testing.T) {
|
||||||
bitStore := NewBitStore(58, nil)
|
bitStore := NewBitStore(58, nil)
|
||||||
|
|
||||||
newStoreMap(bitStore) //初始化的校验
|
newStoreMap(bitStore) //初始化的校验
|
||||||
@@ -148,7 +122,7 @@ func testFiftyEight() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testThirtyThree() {
|
func TestThirtyThree(t *testing.T) {
|
||||||
bitStore := NewBitStore(33, nil)
|
bitStore := NewBitStore(33, nil)
|
||||||
|
|
||||||
newStoreMap(bitStore) //初始化的校验
|
newStoreMap(bitStore) //初始化的校验
|
||||||
@@ -175,7 +149,7 @@ func testThirtyThree() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEighteen() {
|
func TestEighteen(t *testing.T) {
|
||||||
bitStore := NewBitStore(18, nil)
|
bitStore := NewBitStore(18, nil)
|
||||||
|
|
||||||
newStoreMap(bitStore) //初始化的校验
|
newStoreMap(bitStore) //初始化的校验
|
||||||
@@ -196,7 +170,7 @@ func testEighteen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testTen() {
|
func TestTen(t *testing.T) {
|
||||||
bitStore := NewBitStore(10, nil)
|
bitStore := NewBitStore(10, nil)
|
||||||
|
|
||||||
newStoreMap(bitStore) //初始化的校验
|
newStoreMap(bitStore) //初始化的校验
|
||||||
@@ -215,7 +189,7 @@ func testTen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testTwo() {
|
func TestTwo(t *testing.T) {
|
||||||
bitStore := NewBitStore(2, nil)
|
bitStore := NewBitStore(2, nil)
|
||||||
|
|
||||||
newStoreMap(bitStore) //初始化的校验
|
newStoreMap(bitStore) //初始化的校验
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* @Author : huangzj
|
||||||
|
* @Time : 2020/12/16 11:51
|
||||||
|
* @Description:
|
||||||
|
*/
|
||||||
|
|
||||||
|
package reflectM
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReflect(t *testing.T) {
|
||||||
|
entity := Entity{
|
||||||
|
Num: 1,
|
||||||
|
S: "1223",
|
||||||
|
T: make(map[string]string),
|
||||||
|
}
|
||||||
|
structMap := GetStructFieldTypeMap(entity)
|
||||||
|
fmt.Println("根据结构体获取Map结构")
|
||||||
|
for key, val := range structMap {
|
||||||
|
fmt.Println(fmt.Sprintf("结构体属性,key: %v ,value: %v ", key, val))
|
||||||
|
}
|
||||||
|
|
||||||
|
strMap := GetPtrFieldTypeMap(&entity)
|
||||||
|
fmt.Println("根据结构体的指针对象获取Map结构")
|
||||||
|
for key, val := range strMap {
|
||||||
|
fmt.Println(fmt.Sprintf("结构体属性,key: %v ,value: %v ", key, val))
|
||||||
|
}
|
||||||
|
|
||||||
|
ptrList := GetPtrTypeFieldNameList(reflect.TypeOf(&entity))
|
||||||
|
fmt.Println("根据结构体指针类型获取对应的属性名")
|
||||||
|
for _, val := range ptrList {
|
||||||
|
fmt.Println(fmt.Sprintf("字段名:%s ", val))
|
||||||
|
}
|
||||||
|
|
||||||
|
structList := GetStructTypeFieldNameList(reflect.TypeOf(entity))
|
||||||
|
fmt.Println("根据结构体类型获取对应所有字段名称")
|
||||||
|
for _, val := range structList {
|
||||||
|
fmt.Println(fmt.Sprintf("字段名:%s ", val))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Entity struct {
|
||||||
|
Num int
|
||||||
|
S string
|
||||||
|
T map[string]string
|
||||||
|
}
|
||||||
+8
-11
@@ -11,14 +11,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTrie(t *testing.T) {
|
//模糊查询前缀匹配的所有字符串
|
||||||
commonTest() //常规功能测试
|
func TestSearchTrieVague(t *testing.T) {
|
||||||
sensitiveWordsTest() //敏感词汇屏蔽测试
|
|
||||||
searchTrie() //查找前缀匹配的所有字符串
|
|
||||||
searchTrieVague() //模糊查询前缀匹配的所有字符串
|
|
||||||
}
|
|
||||||
|
|
||||||
func searchTrieVague() {
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("模糊查询 查找前缀匹配的所有字符串")
|
fmt.Println("模糊查询 查找前缀匹配的所有字符串")
|
||||||
trie := New()
|
trie := New()
|
||||||
@@ -34,7 +28,8 @@ func searchTrieVague() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func searchTrie() {
|
//查找前缀匹配的所有字符串
|
||||||
|
func TestSearchTrie(t *testing.T) {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("查找前缀匹配的所有字符串")
|
fmt.Println("查找前缀匹配的所有字符串")
|
||||||
trie := New()
|
trie := New()
|
||||||
@@ -64,7 +59,8 @@ func searchTrie() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func sensitiveWordsTest() {
|
//敏感词汇屏蔽测试
|
||||||
|
func TestSensitiveWordsTest(t *testing.T) {
|
||||||
trie := New()
|
trie := New()
|
||||||
trie.insert("粗话").insert("fuck").insert("fuckk").insert("脏话")
|
trie.insert("粗话").insert("fuck").insert("fuckk").insert("脏话")
|
||||||
s := "我是脏话,我是粗话,fuckk,fuck,fffuccck"
|
s := "我是脏话,我是粗话,fuckk,fuck,fffuccck"
|
||||||
@@ -80,7 +76,8 @@ func sensitiveWordsTest() {
|
|||||||
fmt.Println(word)
|
fmt.Println(word)
|
||||||
}
|
}
|
||||||
|
|
||||||
func commonTest() {
|
//常规功能测试
|
||||||
|
func TestCommonTest(t *testing.T) {
|
||||||
trie := New()
|
trie := New()
|
||||||
trie.insert("ABC").insert("AB").insert("ABE").insert("ABEX").insert("XYZ").insert("你").insert("你好").insert("你是谁")
|
trie.insert("ABC").insert("AB").insert("ABE").insert("ABEX").insert("XYZ").insert("你").insert("你好").insert("你是谁")
|
||||||
result := trie.Traverse()
|
result := trie.Traverse()
|
||||||
|
|||||||
Reference in New Issue
Block a user