mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-08 14:42:27 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b05a6dd6f | ||
|
|
d21c101caf | ||
|
|
bf49db60d9 | ||
|
|
d57fa3b603 | ||
|
|
b3a29ce82d | ||
|
|
1d8a37d6e8 | ||
|
|
ef2d8e14b0 | ||
|
|
0cbb3dd97e | ||
|
|
38a7f9423f | ||
|
|
2c0ab9e922 |
@@ -4,7 +4,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/duke-git/lancet/releases)
|
[](https://github.com/duke-git/lancet/releases)
|
||||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||||
@@ -233,6 +233,7 @@ import "github.com/duke-git/lancet/v2/fileutil"
|
|||||||
|
|
||||||
- [ClearFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#ClearFile)
|
- [ClearFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#ClearFile)
|
||||||
- [CreateFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#CreateFile)
|
- [CreateFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#CreateFile)
|
||||||
|
- [CreateDir](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#CreateDir)
|
||||||
- [CopyFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#CopyFile)
|
- [CopyFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#CopyFile)
|
||||||
- [FileMode](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#FileMode)
|
- [FileMode](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#FileMode)
|
||||||
- [MiMeType](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#MiMeType)
|
- [MiMeType](https://github.com/duke-git/lancet/blob/main/docs/fileutil.md#MiMeType)
|
||||||
@@ -370,6 +371,8 @@ import "github.com/duke-git/lancet/v2/slice"
|
|||||||
- [DifferenceWith](https://github.com/duke-git/lancet/blob/main/docs/slice.md#DifferenceWith)
|
- [DifferenceWith](https://github.com/duke-git/lancet/blob/main/docs/slice.md#DifferenceWith)
|
||||||
- [DeleteAt](https://github.com/duke-git/lancet/blob/main/docs/slice.md#DeleteAt)
|
- [DeleteAt](https://github.com/duke-git/lancet/blob/main/docs/slice.md#DeleteAt)
|
||||||
- [Drop](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Drop)
|
- [Drop](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Drop)
|
||||||
|
- [Equal](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Equal)
|
||||||
|
- [EqualWith](https://github.com/duke-git/lancet/blob/main/docs/slice.md#EqualWith)
|
||||||
- [Every](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Every)
|
- [Every](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Every)
|
||||||
- [Filter](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Filter)
|
- [Filter](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Filter)
|
||||||
- [Find](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Find)
|
- [Find](https://github.com/duke-git/lancet/blob/main/docs/slice.md#Find)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
|
|
||||||

|

|
||||||
[](https://github.com/duke-git/lancet/releases)
|
[](https://github.com/duke-git/lancet/releases)
|
||||||
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
[](https://pkg.go.dev/github.com/duke-git/lancet/v2)
|
||||||
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
[](https://goreportcard.com/report/github.com/duke-git/lancet/v2)
|
||||||
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
[](https://github.com/duke-git/lancet/actions/workflows/codecov.yml)
|
||||||
@@ -231,6 +231,7 @@ import "github.com/duke-git/lancet/v2/fileutil"
|
|||||||
|
|
||||||
- [ClearFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#ClearFile)
|
- [ClearFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#ClearFile)
|
||||||
- [CreateFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#CreateFile)
|
- [CreateFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#CreateFile)
|
||||||
|
- [CreateDir](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#CreateDir)
|
||||||
- [CopyFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#CopyFile)
|
- [CopyFile](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#CopyFile)
|
||||||
- [FileMode](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#FileMode)
|
- [FileMode](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#FileMode)
|
||||||
- [MiMeType](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#MiMeType)
|
- [MiMeType](https://github.com/duke-git/lancet/blob/main/docs/fileutil_zh-CN.md#MiMeType)
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ import (
|
|||||||
// CircularQueue implements circular queue with slice,
|
// CircularQueue implements circular queue with slice,
|
||||||
// last index of CircularQueue don't contain value, so acturl capacity is capacity - 1
|
// last index of CircularQueue don't contain value, so acturl capacity is capacity - 1
|
||||||
type CircularQueue[T any] struct {
|
type CircularQueue[T any] struct {
|
||||||
data []T
|
data []T
|
||||||
front int
|
front int
|
||||||
rear int
|
rear int
|
||||||
capacity int
|
capacity int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCircularQueue return a empty CircularQueue pointer
|
// NewCircularQueue return a empty CircularQueue pointer
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ func (q *LinkedQueue[T]) IsEmpty() bool {
|
|||||||
return q.length == 0
|
return q.length == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Enqueue put element into queue
|
// Enqueue put element into queue
|
||||||
func (q *LinkedQueue[T]) Enqueue(value T) {
|
func (q *LinkedQueue[T]) Enqueue(value T) {
|
||||||
newNode := datastructure.NewQueueNode(value)
|
newNode := datastructure.NewQueueNode(value)
|
||||||
|
|||||||
@@ -21,18 +21,20 @@ import (
|
|||||||
## Index
|
## Index
|
||||||
- [ClearFile](#ClearFile)
|
- [ClearFile](#ClearFile)
|
||||||
- [CreateFile](#CreateFile)
|
- [CreateFile](#CreateFile)
|
||||||
|
- [CreateDir](#CreateDir)
|
||||||
- [CopyFile](#CopyFile)
|
- [CopyFile](#CopyFile)
|
||||||
- [FileMode](#FileMode)
|
- [FileMode](#FileMode)
|
||||||
- [MiMeType](#MiMeType)
|
- [MiMeType](#MiMeType)
|
||||||
- [IsExist](#IsExist)
|
- [IsExist](#IsExist)
|
||||||
- [IsLink](#IsLink)
|
- [IsLink](#IsLink)
|
||||||
- [IsDir](#IsDir)
|
- [IsDir](#IsDir)
|
||||||
|
|
||||||
- [ListFileNames](#ListFileNames)
|
- [ListFileNames](#ListFileNames)
|
||||||
- [RemoveFile](#RemoveFile)
|
- [RemoveFile](#RemoveFile)
|
||||||
- [ReadFileToString](#ReadFileToString)
|
- [ReadFileToString](#ReadFileToString)
|
||||||
- [ReadFileByLine](#ReadFileByLine)
|
- [ReadFileByLine](#ReadFileByLine)
|
||||||
- [Zip](#Zip)
|
- [Zip](#Zip)
|
||||||
|
- [UnZip](#UnZip)
|
||||||
- [UnZip](#UnZip)
|
- [UnZip](#UnZip)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
@@ -92,6 +94,32 @@ func main() {
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="CreateDir">CreateDir</span>
|
||||||
|
<p>Create directory in absolute path. param `absPath` like /a/, /a/b/.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func CreateDir(absPath string) error
|
||||||
|
```
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/fileutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
err := fileutil.CreateDir("/a/")
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="CopyFile">CopyFile</span>
|
### <span id="CopyFile">CopyFile</span>
|
||||||
<p>Copy src file to dest file. If dest file exist will overwrite it.</p>
|
<p>Copy src file to dest file. If dest file exist will overwrite it.</p>
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
## 目录
|
## 目录
|
||||||
- [ClearFile](#ClearFile)
|
- [ClearFile](#ClearFile)
|
||||||
- [CreateFile](#CreateFile)
|
- [CreateFile](#CreateFile)
|
||||||
|
- [CreateDir](#CreateDir)
|
||||||
- [CopyFile](#CopyFile)
|
- [CopyFile](#CopyFile)
|
||||||
- [FileMode](#FileMode)
|
- [FileMode](#FileMode)
|
||||||
- [MiMeType](#MiMeType)
|
- [MiMeType](#MiMeType)
|
||||||
@@ -92,6 +93,32 @@ func main() {
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="CreateDir">CreateDir</span>
|
||||||
|
<p>使用绝对路径创建嵌套目录,例如/a/, /a/b/</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func CreateDir(absPath string) error
|
||||||
|
```
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/fileutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
err := fileutil.CreateDir("/a/")
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="CopyFile">CopyFile</span>
|
### <span id="CopyFile">CopyFile</span>
|
||||||
<p>拷贝文件,会覆盖原有的拷贝文件</p>
|
<p>拷贝文件,会覆盖原有的拷贝文件</p>
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ import (
|
|||||||
- [DifferenceWith](#DifferenceWith)
|
- [DifferenceWith](#DifferenceWith)
|
||||||
- [DeleteAt](#DeleteAt)
|
- [DeleteAt](#DeleteAt)
|
||||||
- [Drop](#Drop)
|
- [Drop](#Drop)
|
||||||
|
- [Equal](#Equal)
|
||||||
|
- [EqualWith](#EqualWith)
|
||||||
- [Every](#Every)
|
- [Every](#Every)
|
||||||
- [Filter](#Filter)
|
- [Filter](#Filter)
|
||||||
- [Find](#Find)
|
- [Find](#Find)
|
||||||
@@ -360,6 +362,68 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="Equal">Equal</span>
|
||||||
|
<p>Check if two slices are equal: the same length and all elements' order and value are equal.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Equal[T comparable](slice1, slice2 []T) bool
|
||||||
|
```
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{1, 2, 3}
|
||||||
|
slice3 := []int{3, 2, 1}
|
||||||
|
|
||||||
|
res1 := slice.Equal(slice1, slice2)
|
||||||
|
res2 := slice.Equal(slice1, slice3)
|
||||||
|
|
||||||
|
fmt.Println(res1) //true
|
||||||
|
fmt.Println(res2) //false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="EqualWith">EqualWith</span>
|
||||||
|
<p>Check if two slices are equal with comparator func.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool
|
||||||
|
```
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{2, 4, 6}
|
||||||
|
|
||||||
|
isDouble := func(a, b int) bool {
|
||||||
|
return b == a*2
|
||||||
|
}
|
||||||
|
|
||||||
|
res := slice.EqualWith(slice1, slice2, isDouble)
|
||||||
|
|
||||||
|
fmt.Println(res) //true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="Every">Every</span>
|
### <span id="Every">Every</span>
|
||||||
<p>Return true if all of the values in the slice pass the predicate function.</p>
|
<p>Return true if all of the values in the slice pass the predicate function.</p>
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ import (
|
|||||||
- [DeleteAt](#DeleteAt)
|
- [DeleteAt](#DeleteAt)
|
||||||
- [Drop](#Drop)
|
- [Drop](#Drop)
|
||||||
- [Every](#Every)
|
- [Every](#Every)
|
||||||
|
- [Equal](#Equal)
|
||||||
|
- [EqualWith](#EqualWith)
|
||||||
- [Filter](#Filter)
|
- [Filter](#Filter)
|
||||||
- [Find](#Find)
|
- [Find](#Find)
|
||||||
- [FindLast](#FindLast)
|
- [FindLast](#FindLast)
|
||||||
@@ -393,6 +395,69 @@ func main() {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="Equal">Equal</span>
|
||||||
|
<p>检查两个切片是否相等,相等条件:切片长度相同,元素顺序和值都相同</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Equal[T comparable](slice1, slice2 []T) bool
|
||||||
|
```
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{1, 2, 3}
|
||||||
|
slice3 := []int{3, 2, 1}
|
||||||
|
|
||||||
|
res1 := slice.Equal(slice1, slice2)
|
||||||
|
res2 := slice.Equal(slice1, slice3)
|
||||||
|
|
||||||
|
fmt.Println(res1) //true
|
||||||
|
fmt.Println(res2) //false
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="EqualWith">EqualWith</span>
|
||||||
|
<p>检查两个切片是否相等,相等条件:对两个切片的元素调用比较函数comparator,返回true</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool
|
||||||
|
```
|
||||||
|
<b>例子:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/slice"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{2, 4, 6}
|
||||||
|
|
||||||
|
isDouble := func(a, b int) bool {
|
||||||
|
return b == a*2
|
||||||
|
}
|
||||||
|
|
||||||
|
res := slice.EqualWith(slice1, slice2, isDouble)
|
||||||
|
|
||||||
|
fmt.Println(res) //true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### <span id="Filter">Filter</span>
|
### <span id="Filter">Filter</span>
|
||||||
<p>返回切片中通过predicate函数真值测试的所有元素</p>
|
<p>返回切片中通过predicate函数真值测试的所有元素</p>
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -40,6 +41,11 @@ func CreateFile(path string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateDir create directory in absolute path. param `absPath` like /a/, /a/b/
|
||||||
|
func CreateDir(absPath string) error {
|
||||||
|
return os.MkdirAll(path.Dir(absPath), os.ModePerm)
|
||||||
|
}
|
||||||
|
|
||||||
// IsDir checks if the path is directory or not
|
// IsDir checks if the path is directory or not
|
||||||
func IsDir(path string) bool {
|
func IsDir(path string) bool {
|
||||||
file, err := os.Stat(path)
|
file, err := os.Stat(path)
|
||||||
|
|||||||
@@ -33,6 +33,27 @@ func TestCreateFile(t *testing.T) {
|
|||||||
os.Remove(f)
|
os.Remove(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateDir(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestCreateDir")
|
||||||
|
|
||||||
|
pwd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
dirPath := pwd + "/a/"
|
||||||
|
err = CreateDir(dirPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(true, IsExist(dirPath))
|
||||||
|
os.Remove(dirPath)
|
||||||
|
assert.Equal(false, IsExist(dirPath))
|
||||||
|
}
|
||||||
|
|
||||||
func TestIsDir(t *testing.T) {
|
func TestIsDir(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestIsDir")
|
assert := internal.NewAssert(t, "TestIsDir")
|
||||||
|
|
||||||
|
|||||||
@@ -147,6 +147,37 @@ func DifferenceWith[T any](slice []T, comparedSlice []T, comparator func(value,
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Equal checks if two slices are equal: the same length and all elements' order and value are equal
|
||||||
|
func Equal[T comparable](slice1, slice2 []T) bool {
|
||||||
|
if len(slice1) != len(slice2) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range slice1 {
|
||||||
|
if slice1[i] != slice2[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// EqualWith checks if two slices are equal with comparator func
|
||||||
|
func EqualWith[T, U any](slice1 []T, slice2 []U, comparator func(T, U) bool) bool {
|
||||||
|
if len(slice1) != len(slice2) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, v1 := range slice1 {
|
||||||
|
v2 := slice2[i]
|
||||||
|
if !comparator(v1, v2) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Every return true if all of the values in the slice pass the predicate function.
|
// Every return true if all of the values in the slice pass the predicate function.
|
||||||
func Every[T any](slice []T, predicate func(index int, item T) bool) bool {
|
func Every[T any](slice []T, predicate func(index int, item T) bool) bool {
|
||||||
if predicate == nil {
|
if predicate == nil {
|
||||||
|
|||||||
@@ -68,6 +68,30 @@ func TestConcat(t *testing.T) {
|
|||||||
// assert.Equal([]int{1, 2, 3, 4, 5}, Concat([]int{1, 2, 3}, []int{4}, 5))
|
// assert.Equal([]int{1, 2, 3, 4, 5}, Concat([]int{1, 2, 3}, []int{4}, 5))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEqual(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestEqual")
|
||||||
|
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{1, 2, 3}
|
||||||
|
slice3 := []int{3, 2, 1}
|
||||||
|
|
||||||
|
assert.Equal(true, Equal(slice1, slice2))
|
||||||
|
assert.Equal(false, Equal(slice1, slice3))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEqualWith(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestEqualWith")
|
||||||
|
|
||||||
|
slice1 := []int{1, 2, 3}
|
||||||
|
slice2 := []int{2, 4, 6}
|
||||||
|
|
||||||
|
isDouble := func(a, b int) bool {
|
||||||
|
return b == a*2
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(true, EqualWith(slice1, slice2, isDouble))
|
||||||
|
}
|
||||||
|
|
||||||
func TestEvery(t *testing.T) {
|
func TestEvery(t *testing.T) {
|
||||||
nums := []int{1, 2, 3, 5}
|
nums := []int{1, 2, 3, 5}
|
||||||
isEven := func(i, num int) bool {
|
isEven := func(i, num int) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user