Skip to content

Commit

Permalink
Merge pull request #31 from WGrape/testing
Browse files Browse the repository at this point in the history
feat: add new packages
  • Loading branch information
WGrape committed May 30, 2023
2 parents 1ea9b6f + 8f8ed41 commit ebf3511
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 27 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ jobs:
- run: bash start.sh ../../../
working-directory: ${{env.working-directory}}

code_check:
runs-on: ubuntu-latest
env:
working-directory: .github/workflows/deploy
steps:
- uses: actions/checkout@v1
- run: bash code_check.sh ../../../
working-directory: ${{env.working-directory}}
# code_check:
# runs-on: ubuntu-latest
# env:
# working-directory: .github/workflows/deploy
# steps:
# - uses: actions/checkout@v1
# - run: bash code_check.sh ../../../
# working-directory: ${{env.working-directory}}

unit_test:
runs-on: ubuntu-latest
Expand Down
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,20 @@ Since this project consists of individual ```package```, there is almost no code

## Package list

| package | description | api |
|-----------------|----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| safego | Package safego provides a series of security behaviors. | [document](https://pkg.go.dev/github.com/WGrape/golib/safego) |
| permutation | Package permutation provides many algorithms about permutation and combination. | [document](https://pkg.go.dev/github.com/WGrape/golib/permutation) |
| http | The http package provides efficient and high-performance network operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/http) |
| package | description | api |
|-----------------|---------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| safego | Package safego provides a series of security behaviors. | [document](https://pkg.go.dev/github.com/WGrape/golib/safego) |
| permutation | Package permutation provides many algorithms about permutation and combination. | [document](https://pkg.go.dev/github.com/WGrape/golib/permutation) |
| http | The http package provides efficient and high-performance network operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/http) |
| redis | Package redis provides advanced operations, such as ```Cache Penetration, Cache Breakdown, Cache Avalanche```. | [document](https://pkg.go.dev/github.com/WGrape/golib/redis) |
| desensitization | Package desensitization provides data desensitization support. | [document](https://pkg.go.dev/github.com/WGrape/golib/desensitization) |
| time | Package time provides functionality for measuring and displaying time more efficiently. | [document](https://pkg.go.dev/github.com/WGrape/golib/time) |
| array | Package array provides functionality for measuring and displaying array more efficiently. | [document](https://pkg.go.dev/github.com/WGrape/golib/array) |
| convert | Package convert provides simpler conversion between int, float, and string. | [document](https://pkg.go.dev/github.com/WGrape/golib/convert) |
| set | Package set provides simpler set operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/set) |
| math | Package math provides simpler math operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/math) |
| system | Package system provides an interface to interact with the linux system. | [document](https://pkg.go.dev/github.com/WGrape/golib/system) |
| string | Package string provides an interface to process string in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/string) |
| slice | Package slice provides an interface to process slice in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/slice) |
| frontend | Package frontend provides an interface to work with front-end colleagues in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/frontend) |
| desensitization | Package desensitization provides data desensitization support. | [document](https://pkg.go.dev/github.com/WGrape/golib/desensitization) |
| time | Package time provides functionality for measuring and displaying time more efficiently. | [document](https://pkg.go.dev/github.com/WGrape/golib/time) |
| array | Package array provides functionality for measuring and displaying array more efficiently. | [document](https://pkg.go.dev/github.com/WGrape/golib/array) |
| binary | Package binary provides some operations of binary number and decimal number. | [document](https://pkg.go.dev/github.com/WGrape/golib/binary) |
| convert | Package convert provides simpler conversion between int, float, and string. | [document](https://pkg.go.dev/github.com/WGrape/golib/convert) |
| set | Package set provides simpler set operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/set) |
| math | Package math provides simpler math operations. | [document](https://pkg.go.dev/github.com/WGrape/golib/math) |
| system | Package system provides an interface to interact with the linux system. | [document](https://pkg.go.dev/github.com/WGrape/golib/system) |
| string | Package string provides an interface to process string in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/string) |
| slice | Package slice provides an interface to process slice in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/slice) |
| frontend | Package frontend provides an interface to work with front-end colleagues in the simpler way. | [document](https://pkg.go.dev/github.com/WGrape/golib/frontend) |
9 changes: 5 additions & 4 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ func (strategy *UseStrategy) getCombinationList(propertyList []string) []string
| desensitization | desensitization包提供数据脱敏支持 | [文档](https://pkg.go.dev/github.com/WGrape/golib/desensitization) |
| time | time包提供了更高效的时间处理操作 | [文档](https://pkg.go.dev/github.com/WGrape/golib/time) |
| array | array包提供了更高效的数组操作 | [文档](https://pkg.go.dev/github.com/WGrape/golib/array) |
| binary | binary包提供了更高效的十进制数字和二进制相关的操作. | [document](https://pkg.go.dev/github.com/WGrape/golib/binary) |
| convert | convert包提供了更加简单的整型、浮点型、字符串类型之间的转换 | [文档](https://pkg.go.dev/github.com/WGrape/golib/convert) |
| set | set包提供了更加简单的集合运算操作 | [文档](https://pkg.go.dev/github.com/WGrape/golib/set) |
| math | math包提供了更加简单的关于数学计算相关的操作 | [文档](https://pkg.go.dev/github.com/WGrape/golib/math) |
| system | system包提供了与Linux交互的接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/system) |
| string | string包提供了更简单的String处理接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/string) |
| slice | slice包提供了更简单的Slice处理接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/slice) |
| frontend | frontend包提供了与前端交互工作时更简单的接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/frontend) |
| system | system包提供了与Linux交互的接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/system) |
| string | string包提供了更简单的String处理接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/string) |
| slice | slice包提供了更简单的Slice处理接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/slice) |
| frontend | frontend包提供了与前端交互工作时更简单的接口 | [文档](https://pkg.go.dev/github.com/WGrape/golib/frontend) |
18 changes: 18 additions & 0 deletions array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,24 @@ func ShuffleUInt8Slice(s []uint8) {
rand.Shuffle(len(s), func(i, j int) { s[i], s[j] = s[j], s[i] })
}

// PopOneInt Pop one int element in the slice
func PopOneInt(arr []int) (int, []int) {
if len(arr) < 1 {
return -1, nil
}
var element = arr[len(arr)-1]
return element, arr[0 : len(arr)-1]
}

// Reverse Return the new reverse array.
func Reverse(arr []int) []int {
var newArr []int
for i := len(arr) - 1; i >= 0; i-- {
newArr = append(newArr, arr[i])
}
return newArr
}

// IsStringsEqual return bool means the two arrays are equal or not.
func IsStringsEqual(arr1 []string, arr2 []string) bool {
if (arr1 == nil) != (arr2 == nil) {
Expand Down
25 changes: 25 additions & 0 deletions array/array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package array

import (
"fmt"
"reflect"
"testing"
)

Expand Down Expand Up @@ -174,3 +175,27 @@ func TestShuffleUInt8Slice(t *testing.T) {
ShuffleUInt8Slice(s)
fmt.Println(s)
}

// TestPopOneInt Test the function PopOneInt
func TestPopOneInt(t *testing.T) {
var (
e int
list = []int{1, 3, 4, 6, 7}
)
if e, list = PopOneInt(list); e != 7 {
t.Fail()
return
}
if !reflect.DeepEqual(list, []int{1, 3, 4, 6}) {
t.Fail()
return
}
}

// TestReverse Test the function Reverse
func TestReverse(t *testing.T) {
if !reflect.DeepEqual(Reverse([]int{1, 2, 3, 4, 5}), []int{5, 4, 3, 2, 1}) {
t.Fail()
return
}
}
30 changes: 30 additions & 0 deletions binary/binary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2022 The golib Authors. All rights reserved.
// Use of this source code is governed by a BSD-style(https://en.wikipedia.org/wiki/BSD_licenses)
// license that can be found in the LICENSE file.

// Package binary provides some operations of binary number and decimal number.
package binary

import "fmt"

// DecimalNumberToBinary Return a binary array.
func DecimalNumberToBinary(num int) ([]int, []string, string) {
var (
binary []int
binaryString []string
str string
)

for num != 0 {
var (
bit = num % 2
bitStr = fmt.Sprintf("%d", bit)
)
binary = append([]int{bit}, binary...)
binaryString = append([]string{bitStr}, binaryString...)
str = bitStr + str
num = num / 2
}

return binary, binaryString, str
}
15 changes: 15 additions & 0 deletions binary/binary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package binary

import (
"reflect"
"testing"
)

// TestDecimalNumberToBinary Test the function DecimalNumberToBinary
func TestDecimalNumberToBinary(t *testing.T) {
var intArr, strArr, str = DecimalNumberToBinary(4)
if !reflect.DeepEqual(intArr, []int{1, 0, 0}) || !reflect.DeepEqual(strArr, []string{"1", "0", "0"}) || str != "100" {
t.Fail()
return
}
}
18 changes: 18 additions & 0 deletions permutation/subset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package permutation

// Subsets Given an integer array nums of unique elements, return all possible subsets.
func Subsets(nums []int) [][]int {
var result [][]int
for _, num := range nums {
var newSubsets [][]int
for _, item := range result {
tempItem := make([]int, len(item))
copy(tempItem, item)
newSubsets = append(newSubsets, append(tempItem, num))
}
result = append(result, newSubsets...)
result = append(result, []int{num})
}
result = append(result, []int{})
return result
}
12 changes: 12 additions & 0 deletions permutation/subset_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package permutation

import (
"testing"
)

func TestSubsets(t *testing.T) {
if len(Subsets([]int{0, 1, 3, 5, 9})) != 32 {
t.Fail()
return
}
}

0 comments on commit ebf3511

Please sign in to comment.