feat(Go-Tool):包方法重构
This commit is contained in:
@@ -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))
|
||||
|
||||
@@ -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) //初始化的校验
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user