Skip to content

Commit

Permalink
Merge pull request #36 from gochore/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfogre authored Mar 3, 2021
2 parents 5792254 + 06f509d commit 3d33252
Show file tree
Hide file tree
Showing 26 changed files with 507 additions and 39 deletions.
15 changes: 12 additions & 3 deletions cmd/generate/gen_x_seq.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,20 @@ func (s *{{.Name}}Seq) Range(interval Interval) *{{.Name}}Seq {
return new{{.Name}}Seq(slice)
}

// Slice returns a sub *{{.Name}}Seq with specified index
// Slice returns a sub *{{.Name}}Seq with specified index,
// (1, 2) means [1:2], (-1, 2) means [:2], (-1, -1) means [:]
func (s *{{.Name}}Seq) Slice(i, j int) *{{.Name}}Seq {
if i < 0 && j < 0 {
return s
}
sslice := s.getSlice()
slice := sslice[i:j]
return new{{.Name}}Seq(slice)
if i < 0 {
return new{{.Name}}Seq(sslice[:j])
}
if j < 0 {
return new{{.Name}}Seq(sslice[i:])
}
return new{{.Name}}Seq(sslice[i:j])
}

// Trim returns a *{{.Name}}Seq without elements which make fn returns true
Expand Down
27 changes: 27 additions & 0 deletions cmd/generate/gen_x_seq_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,33 @@ func Test{{.Name}}Seq_Slice(t *testing.T) {
},
want: data[1:3],
},
{
name: "left negative",
data: data,
args: args{
i: -1,
j: 3,
},
want: data[:3],
},
{
name: "right negative",
data: data,
args: args{
i: 1,
j: -3,
},
want: data[1:],
},
{
name: "all negative",
data: data,
args: args{
i: -1,
j: -3,
},
want: data[:],
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
15 changes: 12 additions & 3 deletions gen_float32_seq.go

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

27 changes: 27 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.

15 changes: 12 additions & 3 deletions gen_float64_seq.go

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

27 changes: 27 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.

15 changes: 12 additions & 3 deletions gen_int16_seq.go

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

27 changes: 27 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.

15 changes: 12 additions & 3 deletions gen_int32_seq.go

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

27 changes: 27 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.

15 changes: 12 additions & 3 deletions gen_int64_seq.go

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

27 changes: 27 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.

15 changes: 12 additions & 3 deletions gen_int8_seq.go

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

Loading

0 comments on commit 3d33252

Please sign in to comment.