diff --git a/MainTest.go b/MainTest.go index 590cb10..89531fa 100644 --- a/MainTest.go +++ b/MainTest.go @@ -6,64 +6,6 @@ package main -import ( - "Go-Tool/util/reflectM" - "fmt" - "math" - "reflect" -) - 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 + } diff --git a/SourceAnalysisAndTool/jdkContainer/testHeap/HeapTool.go b/SourceAnalysisAndTool/jdkContainer/testContainer/HeapTool.go similarity index 96% rename from SourceAnalysisAndTool/jdkContainer/testHeap/HeapTool.go rename to SourceAnalysisAndTool/jdkContainer/testContainer/HeapTool.go index 3d3afc6..7fe4549 100644 --- a/SourceAnalysisAndTool/jdkContainer/testHeap/HeapTool.go +++ b/SourceAnalysisAndTool/jdkContainer/testContainer/HeapTool.go @@ -4,7 +4,7 @@ * @Description: */ -package testHeap +package testContainer type Person struct { Name string //名字 diff --git a/SourceAnalysisAndTool/jdkContainer/testHeap/heap_test.go b/SourceAnalysisAndTool/jdkContainer/testContainer/heap_test.go similarity index 97% rename from SourceAnalysisAndTool/jdkContainer/testHeap/heap_test.go rename to SourceAnalysisAndTool/jdkContainer/testContainer/heap_test.go index 7690a3b..83d3ee9 100644 --- a/SourceAnalysisAndTool/jdkContainer/testHeap/heap_test.go +++ b/SourceAnalysisAndTool/jdkContainer/testContainer/heap_test.go @@ -4,7 +4,7 @@ * @Description: */ -package testHeap +package testContainer import ( "container/heap" diff --git a/SourceAnalysisAndTool/jdkContainer/testHeap/list_test.go b/SourceAnalysisAndTool/jdkContainer/testContainer/list_test.go similarity index 98% rename from SourceAnalysisAndTool/jdkContainer/testHeap/list_test.go rename to SourceAnalysisAndTool/jdkContainer/testContainer/list_test.go index 04d9bd9..7f2f4f2 100644 --- a/SourceAnalysisAndTool/jdkContainer/testHeap/list_test.go +++ b/SourceAnalysisAndTool/jdkContainer/testContainer/list_test.go @@ -4,7 +4,7 @@ * @Description:测试list.go包的元素 */ -package testHeap +package testContainer import ( "container/list" diff --git a/SourceAnalysisAndTool/jdkContainer/testHeap/ring_test.go b/SourceAnalysisAndTool/jdkContainer/testContainer/ring_test.go similarity index 98% rename from SourceAnalysisAndTool/jdkContainer/testHeap/ring_test.go rename to SourceAnalysisAndTool/jdkContainer/testContainer/ring_test.go index 7aa2586..14888a3 100644 --- a/SourceAnalysisAndTool/jdkContainer/testHeap/ring_test.go +++ b/SourceAnalysisAndTool/jdkContainer/testContainer/ring_test.go @@ -4,7 +4,7 @@ * @Description: */ -package testHeap +package testContainer import ( "container/ring" diff --git a/util/bitOperation/BitTool_test.go b/util/bitOperation/BitTool_test.go index f76d0fb..26a62b3 100644 --- a/util/bitOperation/BitTool_test.go +++ b/util/bitOperation/BitTool_test.go @@ -11,18 +11,7 @@ import ( "testing" ) -func TestBitTool(t *testing.T) { - JudgeIfEvenTest() - JudgeIfOddTest() - JudgeOneWithPositionTest() - JudgeOnlyOneBitWithOneTest() - JudgeWithEqualSymbolTest() - SetOneByPositionTest() - SetZeroBuPositionTest() - -} - -func SetZeroBuPositionTest() { +func TestSetZeroBuPosition(t *testing.T) { fmt.Println("设置某个位置上的元素为0") fmt.Println(fmt.Sprintf("原始: %16b", 1)) fmt.Println(fmt.Sprintf("结果:%16b", SetZeroBuPosition(1, 1))) @@ -42,7 +31,7 @@ func SetZeroBuPositionTest() { fmt.Println() } -func SetOneByPositionTest() { +func TestSetOneByPosition(t *testing.T) { fmt.Println("设置某个位置上的元素为1") fmt.Println(fmt.Sprintf("原始: %16b", 2)) fmt.Println(fmt.Sprintf("结果:%16b", SetOneByPosition(2, 1))) @@ -63,7 +52,7 @@ func SetOneByPositionTest() { fmt.Println() } -func JudgeWithEqualSymbolTest() { +func TestJudgeWithEqualSymbol(t *testing.T) { fmt.Println("判断两个数正负符号是否一致") fmt.Println(JudgeWithEqualSymbol(10, 20)) fmt.Println(JudgeWithEqualSymbol(10, -20)) @@ -72,7 +61,7 @@ func JudgeWithEqualSymbolTest() { fmt.Println() } -func JudgeOneWithPositionTest() { +func TestJudgeOneWithPosition(t *testing.T) { fmt.Println("判断二进制表示的某个位上是否为1") fmt.Println(fmt.Sprintf("%16b", 1)) fmt.Println(JudgeOneWithPosition(1, 1)) @@ -87,7 +76,7 @@ func JudgeOneWithPositionTest() { fmt.Println() } -func JudgeIfOddTest() { +func TestJudgeIfOdd(t *testing.T) { fmt.Println("奇数的判断") fmt.Println(JudgeIfOdd(1)) fmt.Println(JudgeIfOdd(2)) @@ -99,7 +88,7 @@ func JudgeIfOddTest() { fmt.Println() } -func JudgeIfEvenTest() { +func TestJudgeIfEven(t *testing.T) { fmt.Println("偶数的判断") fmt.Println(JudgeIfEven(1)) fmt.Println(JudgeIfEven(2)) @@ -111,7 +100,7 @@ func JudgeIfEvenTest() { fmt.Println() } -func JudgeOnlyOneBitWithOneTest() { +func TestJudgeOnlyOneBitWithOne(t *testing.T) { fmt.Println("判断二进制表示是不是只有一个位为1") fmt.Println(JudgeOnlyOneBitWithOne(1)) fmt.Println(JudgeOnlyOneBitWithOne(2)) diff --git a/util/bitStore/BitStoreTool_test.go b/util/bitStore/BitStoreTool_test.go index da2cce8..8dbead6 100644 --- a/util/bitStore/BitStoreTool_test.go +++ b/util/bitStore/BitStoreTool_test.go @@ -12,32 +12,6 @@ import ( "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) { gearMap := bitStore.FindAllGearMap() falseList := make([]int, 0) @@ -66,7 +40,7 @@ func getReceiveResult(bitStore *BitStore) { } } -func testOneThousand() { +func TestOneThousand(t *testing.T) { bitStore := NewBitStore(1000, nil) newStoreMap(bitStore) //初始化的校验 @@ -115,7 +89,7 @@ func testOneThousand() { getReceiveResult(bitStore) } -func testFiftyEight() { +func TestFiftyEight(t *testing.T) { bitStore := NewBitStore(58, nil) newStoreMap(bitStore) //初始化的校验 @@ -148,7 +122,7 @@ func testFiftyEight() { } } -func testThirtyThree() { +func TestThirtyThree(t *testing.T) { bitStore := NewBitStore(33, nil) newStoreMap(bitStore) //初始化的校验 @@ -175,7 +149,7 @@ func testThirtyThree() { } } -func testEighteen() { +func TestEighteen(t *testing.T) { bitStore := NewBitStore(18, nil) newStoreMap(bitStore) //初始化的校验 @@ -196,7 +170,7 @@ func testEighteen() { } } -func testTen() { +func TestTen(t *testing.T) { bitStore := NewBitStore(10, nil) newStoreMap(bitStore) //初始化的校验 @@ -215,7 +189,7 @@ func testTen() { } } -func testTwo() { +func TestTwo(t *testing.T) { bitStore := NewBitStore(2, nil) newStoreMap(bitStore) //初始化的校验 diff --git a/util/reflectM/FieldValueTool_test.go b/util/reflectM/FieldValueTool_test.go new file mode 100644 index 0000000..30af68d --- /dev/null +++ b/util/reflectM/FieldValueTool_test.go @@ -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 +} diff --git a/util/trie/Trie_test.go b/util/trie/Trie_test.go index 2f34d4b..3e7c567 100644 --- a/util/trie/Trie_test.go +++ b/util/trie/Trie_test.go @@ -11,14 +11,8 @@ import ( "testing" ) -func TestTrie(t *testing.T) { - commonTest() //常规功能测试 - sensitiveWordsTest() //敏感词汇屏蔽测试 - searchTrie() //查找前缀匹配的所有字符串 - searchTrieVague() //模糊查询前缀匹配的所有字符串 -} - -func searchTrieVague() { +//模糊查询前缀匹配的所有字符串 +func TestSearchTrieVague(t *testing.T) { fmt.Println() fmt.Println("模糊查询 查找前缀匹配的所有字符串") trie := New() @@ -34,7 +28,8 @@ func searchTrieVague() { } } -func searchTrie() { +//查找前缀匹配的所有字符串 +func TestSearchTrie(t *testing.T) { fmt.Println() fmt.Println("查找前缀匹配的所有字符串") trie := New() @@ -64,7 +59,8 @@ func searchTrie() { } -func sensitiveWordsTest() { +//敏感词汇屏蔽测试 +func TestSensitiveWordsTest(t *testing.T) { trie := New() trie.insert("粗话").insert("fuck").insert("fuckk").insert("脏话") s := "我是脏话,我是粗话,fuckk,fuck,fffuccck" @@ -80,7 +76,8 @@ func sensitiveWordsTest() { fmt.Println(word) } -func commonTest() { +//常规功能测试 +func TestCommonTest(t *testing.T) { trie := New() trie.insert("ABC").insert("AB").insert("ABE").insert("ABEX").insert("XYZ").insert("你").insert("你好").insert("你是谁") result := trie.Traverse()