feat(Go-Tool):修改单测位置,添加lomuto查找第k小元素算法代码及其单测(分治法)

This commit is contained in:
huangzj
2020-08-18 17:29:42 +08:00
parent 3f0e3b27f7
commit fa58e1a97f
27 changed files with 322 additions and 251 deletions
+78
View File
@@ -0,0 +1,78 @@
/*
* @Author : huangzj
* @Time : 2020/4/30 14:55
* @Description 文件读取工具测试
*/
package file
import (
"encoding/json"
"fmt"
"testing"
)
func TestReadFileLineNum(t *testing.T) {
fmt.Print(ReadFileLineNum("F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest\\1\\11.txt"))
}
func TestReadFileLineNumExceptEmptyLine(t *testing.T) {
fmt.Println(ReadFileLineNumExceptEmptyLine("F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest\\1\\11.txt"))
}
func TestReadJsonFile(t *testing.T) {
content, _ := ReadJsonFile("F:\\Go个人代码\\src\\Go-Tool\\util\\file\\json_file_test_mode.json")
fmt.Println(content)
var testMode JsonTestMode
_ = json.Unmarshal([]byte(content), &testMode)
for _, r := range testMode.RareNumAward {
fmt.Println(r.Num)
fmt.Println()
for _, r1 := range r.Award {
fmt.Println(fmt.Sprintf("%d %d", r1[0], r1[1]))
}
}
}
//被读取Json文件的测试结构体
type JsonTestMode struct {
CandleLightingReward CandleLightingReward
Cake []Cake
RareNumAward []RareNumAward
CommonNumAward [][]int
DailyAwardPool [][]int
DailyExtraction []DailyExtraction
FinalAward [][]int
CandleNumStart int
CandleNumInterval int
DiamondNum int
ThemeId int
}
type CandleLightingReward struct {
Num int
AwardPool [][]int
}
type Cake struct {
Level int
CandleNum int
Award [][]int
}
type RareNumAward struct {
Num int
Award [][]int
}
type DailyExtraction struct {
Day int
Num int
}
+52
View File
@@ -0,0 +1,52 @@
/*
* @Author : huangzj
* @Time : 2020/4/30 14:56
* @Description 文件工具测试
*/
package file
import (
"fmt"
"testing"
)
var (
filePaths = [5]string{"F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest\\1\\11.txt",
"F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest\\2\\1\\11.txt",
"F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest\\2\\2222\\4\\4\\111.txt",
"F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest\\2\\2222\\4\\4\\4\\4\\1211.txt",
"F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest\\3\\11.txt"}
)
func TestGetAllFileNameFromDir(t *testing.T) {
s := GetAllFileNameFromDir("F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest")
for _, row := range s {
fmt.Print(row)
}
}
func TestGetAllEmptyDir(t *testing.T) {
_, s := GetAllEmptyDir("F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest")
for _, row := range s {
fmt.Print(fmt.Sprint(row, "\n\n"))
}
}
func TestGetAllDir(t *testing.T) {
_, s := GetAllDir("F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest")
for _, row := range s {
fmt.Print(row)
}
}
func TestGetAllNotEmptyDir(t *testing.T) {
_, s := GetAllNotEmptyDir("F:\\Go个人代码\\src\\Go-Tool\\test\\emptyDirTest")
for _, row := range s {
fmt.Print(row)
}
}
+7
View File
@@ -0,0 +1,7 @@
/*
* @Author : huangzj
* @Time : 2020/4/30 14:56
* @Description 文件写入工具测试
*/
package file
+194
View File
@@ -0,0 +1,194 @@
{
"CandleLightingReward": {
"Num": 1,
"AwardPool": [
[522, 1, 20],
[520, 1, 20],
[529, 1, 20],
[215, 1, 20],
[508, 1, 20]
]
},
"Cake": [{
"Level": 1,
"CandleNum": 600000,
"Award": [
[303, 1],
[221, 1],
[522, 1],
[520, 1],
[215, 1],
[505, 1]
]
}, {
"Level": 2,
"CandleNum": 400000,
"Award": [
[529, 4],
[221, 1],
[522, 1],
[520, 1],
[215, 1],
[505, 1]
]
}, {
"Level": 3,
"CandleNum": 200000,
"Award": [
[529, 3],
[221, 1],
[522, 1],
[520, 1],
[215, 1],
[505, 1]
]
}, {
"Level": 4,
"CandleNum": 150000,
"Award": [
[529, 2],
[221, 1],
[522, 1],
[520, 1],
[215, 1],
[505, 1]
]
}, {
"Level": 5,
"CandleNum": 100000,
"Award": [
[529, 2],
[221, 1],
[522, 1],
[520, 1],
[215, 1],
[505, 1]
]
}, {
"Level": 6,
"CandleNum": 50000,
"Award": [
[529, 1],
[221, 1],
[522, 1],
[520, 1],
[215, 1],
[505, 1]
]
}],
"RareNumAward": [{
"Num": 2,
"Award": [
[303, 1],
[220, 1],
[221, 1],
[522, 2],
[520, 2]
]
}, {
"Num": 22,
"Award": [
[303, 1],
[220, 1],
[221, 1],
[522, 3],
[520, 3]
]
}, {
"Num": 222,
"Award": [
[303, 2],
[220, 1],
[221, 1],
[522, 3],
[520, 3]
]
}, {
"Num": 2222,
"Award": [
[303, 2],
[220, 2],
[221, 2],
[522, 3],
[520, 3]
]
}, {
"Num": 22222,
"Award": [
[303, 2],
[220, 2],
[221, 3],
[522, 5],
[520, 5]
]
}, {
"Num": 222222,
"Award": [
[303, 3],
[220, 2],
[221, 3],
[522, 5],
[520, 5]
]
}, {
"Num": 2222222,
"Award": [
[581, 1],
[220, 3],
[221, 3],
[522, 5],
[520, 5]
]
}],
"CommonNumAward": [
[215, 2],
[522, 1],
[520, 1]
],
"DailyAwardPool": [
[522, 1, 13],
[520, 1, 13],
[529, 1, 13],
[215, 1, 13],
[221, 1, 13],
[236, 1, 11],
[505, 1, 11],
[506, 1, 10]
],
"DailyExtraction": [{
"Day": 1,
"Num": 1
}, {
"Day": 2,
"Num": 1
}, {
"Day": 3,
"Num": 2
}, {
"Day": 4,
"Num": 2
}, {
"Day": 5,
"Num": 2
}, {
"Day": 6,
"Num": 3
}, {
"Day": 7,
"Num": 3
}],
"FinalAward": [
[565, 2],
[303, 2],
[220, 1],
[522, 1],
[520, 1],
[301, 1],
[236, 1],
[221, 1]
],
"CandleNumStart": 3,
"CandleNumInterval": 10,
"DiamondNum": 40,
"ThemeId": 6
}