Skip to content

Commit

Permalink
Merge pull request #35 from gochore/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfogre authored Mar 3, 2021
2 parents d60f1ac + 0788f8f commit 5792254
Show file tree
Hide file tree
Showing 28 changed files with 561 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: go

go:
- 1.14.x
- 1.15.x
- 1.16.x

before_install:
- go get -t -v ./...
Expand Down
9 changes: 8 additions & 1 deletion cmd/generate/gen_x_seq.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,14 @@ func (s *{{.Name}}Seq) Range(interval Interval) *{{.Name}}Seq {
return new{{.Name}}Seq(slice)
}

// Range returns a *{{.Name}}Seq without elements which make fn returns true
// Slice returns a sub *{{.Name}}Seq with specified index
func (s *{{.Name}}Seq) Slice(i, j int) *{{.Name}}Seq {
sslice := s.getSlice()
slice := sslice[i:j]
return new{{.Name}}Seq(slice)
}

// Trim returns a *{{.Name}}Seq without elements which make fn returns true
func (s *{{.Name}}Seq) Trim(fn func(i int, v {{.Name}}) bool) *{{.Name}}Seq {
sslice := s.getSlice()
if fn == nil || len(sslice) == 0 {
Expand Down
35 changes: 35 additions & 0 deletions cmd/generate/gen_x_seq_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func Test{{.Name}}Seq_NilSafe(t *testing.T) {
seq.Last()
seq.Percentile(0.5)
seq.Range(Interval{})
seq.Slice(0, 0)
seq.Trim(func(i int, v {{.Name}}) bool {
return false
})
Expand Down Expand Up @@ -675,6 +676,40 @@ func Test{{.Name}}Seq_Range(t *testing.T) {
}
}

func Test{{.Name}}Seq_Slice(t *testing.T) {
data := Random{{.Name}}s(100)
Sort(data)

type args struct {
i int
j int
}
tests := []struct {
name string
data {{.Name}}s
args args
want {{.Name}}s
}{
{
name: "regular",
data: data,
args: args{
i: 1,
j: 3,
},
want: data[1:3],
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := new{{.Name}}Seq(data)
if got := s.Slice(tt.args.i, tt.args.j).{{.Name}}s(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Slice() = %v, want %v", got, tt.want)
}
})
}
}

func Test{{.Name}}Seq_Trim(t *testing.T) {
data := Random{{.Name}}s(10)
Sort(data)
Expand Down
9 changes: 8 additions & 1 deletion gen_float32_seq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions gen_float32_seq_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion gen_float64_seq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions gen_float64_seq_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion gen_int16_seq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions gen_int16_seq_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion gen_int32_seq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions gen_int32_seq_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion gen_int64_seq.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions gen_int64_seq_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5792254

Please sign in to comment.