Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
package mathUtil
|
||||
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
// 判断传入的byte型数组是否连续
|
||||
func IsContinuous_byte(list []byte) bool {
|
||||
if len(list) == 0 || len(list) == 1 {
|
||||
return true
|
||||
}
|
||||
|
||||
list_int64 := make([]int64, len(list), len(list))
|
||||
for i, v := range list {
|
||||
list_int64[i] = int64(v)
|
||||
}
|
||||
|
||||
return IsContinuous_int64(list_int64)
|
||||
}
|
||||
|
||||
// 判断传入的int型数组是否连续
|
||||
func IsContinuous_int(list []int) bool {
|
||||
if len(list) == 0 || len(list) == 1 {
|
||||
return true
|
||||
}
|
||||
|
||||
list_int64 := make([]int64, len(list), len(list))
|
||||
for i, v := range list {
|
||||
list_int64[i] = int64(v)
|
||||
}
|
||||
|
||||
return IsContinuous_int64(list_int64)
|
||||
}
|
||||
|
||||
// 判断传入的int型数组是否连续
|
||||
func IsContinuous_int32(list []int32) bool {
|
||||
if len(list) == 0 || len(list) == 1 {
|
||||
return true
|
||||
}
|
||||
|
||||
list_int64 := make([]int64, len(list), len(list))
|
||||
for i, v := range list {
|
||||
list_int64[i] = int64(v)
|
||||
}
|
||||
|
||||
return IsContinuous_int64(list_int64)
|
||||
}
|
||||
|
||||
// 判断传入的int型数组是否连续
|
||||
func IsContinuous_int64(list []int64) bool {
|
||||
if len(list) == 0 || len(list) == 1 {
|
||||
return true
|
||||
}
|
||||
|
||||
if int64(len(list)) != list[len(list)-1]-list[0]+1 {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < len(list)-1; i++ {
|
||||
if list[i]+1 != list[i+1] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// 判断区间是否连续
|
||||
func IsContinuous_Region(list []*IntRegion) bool {
|
||||
if len(list) == 0 || len(list) == 1 {
|
||||
return true
|
||||
}
|
||||
|
||||
sort.Slice(list, func(i, j int) bool { return list[i].Lower < list[j].Lower })
|
||||
|
||||
for i := 0; i < len(list)-1; i++ {
|
||||
if list[i].IsSorted() == false || list[i+1].IsSorted() == false {
|
||||
return false
|
||||
}
|
||||
|
||||
if list[i].Upper+1 != list[i+1].Lower {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// 判断传入的概率是否全覆盖
|
||||
func IsOddFullConvered(list []*IntRegion, min, max int) bool {
|
||||
if len(list) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if list[0].Lower != min || list[len(list)-1].Upper != max {
|
||||
return false
|
||||
}
|
||||
|
||||
sort.Slice(list, func(i, j int) bool { return list[i].Lower < list[j].Lower })
|
||||
|
||||
for i := 0; i < len(list)-1; i++ {
|
||||
if list[i].IsSorted() == false || list[i+1].IsSorted() == false {
|
||||
return false
|
||||
}
|
||||
|
||||
if list[i].Upper+1 != list[i+1].Lower {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func IsDistinct_byte(list []byte) (result bool) {
|
||||
if len(list) == 0 || len(list) == 1 {
|
||||
result = true
|
||||
return
|
||||
}
|
||||
|
||||
list_int64 := make([]int64, len(list), len(list))
|
||||
for i, v := range list {
|
||||
list_int64[i] = int64(v)
|
||||
}
|
||||
|
||||
return IsDistinct_int64(list_int64)
|
||||
}
|
||||
|
||||
func IsDistinct_int(list []int) (result bool) {
|
||||
if len(list) == 0 || len(list) == 1 {
|
||||
result = true
|
||||
return
|
||||
}
|
||||
|
||||
list_int64 := make([]int64, len(list), len(list))
|
||||
for i, v := range list {
|
||||
list_int64[i] = int64(v)
|
||||
}
|
||||
|
||||
return IsDistinct_int64(list_int64)
|
||||
}
|
||||
|
||||
func IsDistinct_int32(list []int32) (result bool) {
|
||||
if len(list) == 0 || len(list) == 1 {
|
||||
result = true
|
||||
return
|
||||
}
|
||||
|
||||
list_int64 := make([]int64, len(list), len(list))
|
||||
for i, v := range list {
|
||||
list_int64[i] = int64(v)
|
||||
}
|
||||
|
||||
return IsDistinct_int64(list_int64)
|
||||
}
|
||||
|
||||
// 判断int64数组是否内容唯一
|
||||
func IsDistinct_int64(list []int64) (result bool) {
|
||||
if len(list) == 0 || len(list) == 1 {
|
||||
result = true
|
||||
return
|
||||
}
|
||||
|
||||
sort.Slice(list, func(i, j int) bool { return list[i] < list[j] })
|
||||
|
||||
for i := 0; i < len(list)-1; i++ {
|
||||
if list[i] == list[i+1] {
|
||||
result = false
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
result = true
|
||||
return
|
||||
}
|
||||
|
||||
//// 将int转成uint类型(因goutil指定go版本过低,不支持泛型,未实际加入;要使用的人取消注释,并指定允许泛型的go版本)
|
||||
//// 应用场景:atomic.AddUint64 想减1时
|
||||
////
|
||||
//// x := uint64(1000)
|
||||
//// y := int64(-1)
|
||||
//// atomic.AddUint64(&x, intToUint[int64, uint64](y))
|
||||
//func intToUint[T1 int8 | int16 | int32 | int64 | int, T2 uint8 | uint16 | uint32 | uint64 | uint](x T1) T2 {
|
||||
// // 写到函数内,两种方式都可以;若直接使用,只能使用^T2(-x - 1);若使用T2(x)方式,x为负值时转为uint类语法检查无法通过
|
||||
// return ^T2(-x - 1)
|
||||
// // return T2(x)
|
||||
//}
|
||||
@@ -0,0 +1,53 @@
|
||||
package stringUtil
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBase64Encode(t *testing.T) {
|
||||
greeting := "Hello world"
|
||||
encoded := Base64Encode(greeting)
|
||||
decoded, err := Base64Decode(encoded)
|
||||
if err != nil {
|
||||
t.Errorf("There should be no error, but now there is one:%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if greeting != decoded {
|
||||
t.Errorf("Expected %s, but got %s", greeting, decoded)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestBase64Encode2(t *testing.T) {
|
||||
greeting := []byte("Hello world")
|
||||
encoded := Base64Encode2(greeting)
|
||||
decoded, err := Base64Decode2(encoded)
|
||||
if err != nil {
|
||||
t.Errorf("There should be no error, but now there is one:%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if isEqual(greeting, decoded) == false {
|
||||
t.Errorf("Expected %s, but got %s", greeting, decoded)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func isEqual(s1, s2 []byte) bool {
|
||||
if s1 == nil || s2 == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
if len(s1) != len(s2) {
|
||||
return false
|
||||
}
|
||||
|
||||
for i := 0; i < len(s1); i++ {
|
||||
if s1[i] != s2[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package impl_console
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInfoLog(t *testing.T) {
|
||||
log := NewLogger()
|
||||
log.DebugLog("Debug test")
|
||||
log.InfoLog("Info test")
|
||||
log.WarnLog("Warn test")
|
||||
log.ErrorLog("Error test")
|
||||
log.FatalLog("Fatal test")
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package managecenterMgr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func init() {
|
||||
manageCenterDataSwitchObj := &ManageCenterDataSwitch{
|
||||
AllDataSwitch: true,
|
||||
}
|
||||
Start("https://managecenterapi-sd3.7qule.com/", manageCenterDataSwitchObj)
|
||||
|
||||
item, exist := GetAreaLabelDBByGroupId(82)
|
||||
if exist {
|
||||
fmt.Printf("%v", item)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPartner(t *testing.T) {
|
||||
partnerList := GetPartnerList()
|
||||
fmt.Printf("PartnerList count:%v\n", len(partnerList))
|
||||
if len(partnerList) == 0 {
|
||||
t.Errorf("There is no partner.")
|
||||
return
|
||||
}
|
||||
|
||||
firstPartner := partnerList[0]
|
||||
_, exist := GetPartner(firstPartner.Id)
|
||||
if !exist {
|
||||
t.Errorf("Partner with Id:%d should exist, but now it doesn't.", firstPartner.Id)
|
||||
return
|
||||
}
|
||||
|
||||
_, exist = GetPartnerByAlias(firstPartner.Alias)
|
||||
if !exist {
|
||||
t.Errorf("Partner with Alias:%s should exist, but now it doesn't.", firstPartner.Alias)
|
||||
return
|
||||
}
|
||||
|
||||
_, exist, err := GetOtherConfigInfo(firstPartner.Id, "LoginHandler")
|
||||
if err != nil {
|
||||
t.Errorf("There should no error for Partner:%d, but now there is one:%v", err, firstPartner.Id)
|
||||
return
|
||||
}
|
||||
if !exist {
|
||||
t.Errorf("Partner with Id:%d should have an other config named LoginHandler, but now there isn't.", firstPartner.Id)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer(t *testing.T) {
|
||||
serverGroupList := GetServerGroupList()
|
||||
if len(serverGroupList) == 0 {
|
||||
t.Errorf("There is no ServerGroup.")
|
||||
return
|
||||
}
|
||||
firstServerGroup := serverGroupList[0]
|
||||
|
||||
serverList := GetServerListByGroupId(firstServerGroup.Id)
|
||||
fmt.Printf("There are %d servers of GroupId:%d\n", len(serverList), firstServerGroup.Id)
|
||||
|
||||
firstServer := serverList[0]
|
||||
serverList = GetServerListByPartnerId(firstServer.PartnerId)
|
||||
fmt.Printf("There are %d servers of PartnerId:%d\n", len(serverList), firstServer.PartnerId)
|
||||
|
||||
_, exist := GetServerItem(firstServer.PartnerId, firstServer.Id)
|
||||
if !exist {
|
||||
t.Errorf("There is no server with PartnerId:%d, ServerId:%d.", firstServer.PartnerId, firstServer.Id)
|
||||
return
|
||||
}
|
||||
|
||||
distinctServerIdList := GetDistinctServerIdList()
|
||||
fmt.Printf("There are %d distinct ServerId\n", len(distinctServerIdList))
|
||||
}
|
||||
|
||||
func TestServerGroup(t *testing.T) {
|
||||
serverGroupList := GetServerGroupList()
|
||||
if len(serverGroupList) == 0 {
|
||||
t.Errorf("There is no ServerGroup.")
|
||||
return
|
||||
}
|
||||
|
||||
firstServerGroup := serverGroupList[0]
|
||||
_, exist := GetServerGroupItem(firstServerGroup.Id)
|
||||
if !exist {
|
||||
t.Errorf("The ServerGroup with Id:%d should exist, but now it doesn't.", firstServerGroup.Id)
|
||||
return
|
||||
}
|
||||
|
||||
serverList := GetServerListByGroupId(firstServerGroup.Id)
|
||||
if len(serverList) == 0 {
|
||||
t.Errorf("There is no server of ServerGroupId:%d", firstServerGroup.Id)
|
||||
return
|
||||
}
|
||||
firstServer := serverList[0]
|
||||
_, _, exist = GetServerGroup(firstServer.PartnerId, firstServer.Id)
|
||||
if !exist {
|
||||
t.Errorf("The ServerGroup with PartnerId:%d, ServerId:%d should exist, but now it doesn't.", firstServer.PartnerId, firstServer.Id)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceVersion(t *testing.T) {
|
||||
list := GetResourceVersionList()
|
||||
fmt.Printf("There are %d resource versions.\n", len(list))
|
||||
}
|
||||
|
||||
func TestUserWhiteList(t *testing.T) {
|
||||
fmt.Printf("There are %d whiteLists.\n", len(whiteListMap))
|
||||
if len(whiteListMap) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var partnerId int32
|
||||
var userId string
|
||||
for _, v := range whiteListMap {
|
||||
for _, _v := range v {
|
||||
partnerId = _v.PartnerId
|
||||
userId = _v.UserId
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
expected := true
|
||||
got := IsInWhiteList(partnerId, userId)
|
||||
if got != expected {
|
||||
t.Errorf("Expected to get %t, but got %t", expected, got)
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user