2023-01-16 06:38:55 +00:00
|
|
|
package safety
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-01-21 11:31:23 +00:00
|
|
|
"github.com/fthvgb1/wp-go/helper/number"
|
2023-12-10 11:15:49 +00:00
|
|
|
"github.com/fthvgb1/wp-go/taskPools"
|
2023-01-16 06:38:55 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSlice_Append(t *testing.T) {
|
|
|
|
type args[T any] struct {
|
|
|
|
t []T
|
|
|
|
}
|
|
|
|
type testCase[T any] struct {
|
|
|
|
name string
|
|
|
|
r Slice[T]
|
|
|
|
args args[T]
|
|
|
|
}
|
|
|
|
tests := []testCase[int]{
|
|
|
|
{
|
|
|
|
name: "t1",
|
2024-06-11 16:14:07 +00:00
|
|
|
r: *NewSlice[int](),
|
2023-01-21 11:31:23 +00:00
|
|
|
args: args[int]{number.Range(1, 10, 1)},
|
2023-01-16 06:38:55 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
fn := func() {
|
2023-12-10 11:15:49 +00:00
|
|
|
switch number.Rand(1, 3) {
|
|
|
|
case 1:
|
|
|
|
f := tt.r.Load()
|
|
|
|
fmt.Println(f)
|
|
|
|
case 2:
|
|
|
|
tt.r.Append(tt.args.t...)
|
|
|
|
case 3:
|
|
|
|
/*s := tt.r.Load()
|
|
|
|
if len(s) < 1 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
ii, v := slice.Rand(number.Range(0, len(s)))
|
|
|
|
s[ii] = v*/
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
p := taskPools.NewPools(20)
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
p.Execute(fn)
|
2023-01-16 06:38:55 +00:00
|
|
|
}
|
2023-12-10 11:15:49 +00:00
|
|
|
p.Wait()
|
2023-01-16 06:38:55 +00:00
|
|
|
fmt.Println(tt.r.Load())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|