Skip to content

Commit

Permalink
Merge pull request #25 from gochore/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfogre authored Oct 13, 2020
2 parents b363d56 + c988bdb commit acfaeee
Show file tree
Hide file tree
Showing 10 changed files with 550 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/generate/gen_x_seq.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (v {{.Name}}) IsZero() bool {
return v.Value == 0 && v.Time.IsZero()
}

func (v {{.Name}}) Equal(n {{.Name}}) bool {
return v.Value == n.Value && v.Time.Equal(n.Time)
}

type {{.Name}}s []{{.Name}}

func (s {{.Name}}s) Len() int {
Expand Down
106 changes: 106 additions & 0 deletions cmd/generate/gen_x_seq_test.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,59 @@ func Test{{.Name}}Seq_Index(t *testing.T) {
}
}

func Test{{.Name}}Seq_Time(t *testing.T) {
now := time.Now()
yesterday := now.AddDate(0, 0, -1)
lastMonth := now.AddDate(0, -1, 0)
lastYear := now.AddDate(-1, 0, 0)

data := Random{{.Name}}s(100)
data[0].Time = lastMonth
data[1].Time = lastMonth
data[2].Time = lastMonth
data[3].Time = yesterday
Sort(data)

type args struct {
t time.Time
}
tests := []struct {
name string
args args
want {{.Name}}
}{
{
name: "regular",
args: args{
t: yesterday,
},
want: data[3],
},
{
name: "multiple",
args: args{
t: lastMonth,
},
want: data[0],
},
{
name: "none",
args: args{
t: lastYear,
},
want: {{.Name}}{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := New{{.Name}}Seq(data)
if got := s.Time(tt.args.t); !got.Equal(tt.want) {
t.Errorf("Time() = %v, want %v", got, tt.want)
}
})
}
}

func Test{{.Name}}Seq_MTime(t *testing.T) {
now := time.Now()
yesterday := now.AddDate(0, 0, -1)
Expand Down Expand Up @@ -174,6 +227,59 @@ func Test{{.Name}}Seq_MTime(t *testing.T) {
}
}

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

value1 := data[0].Value
value2 := data[1].Value
value3 := data[2].Value

data[0].Value = value1
data[1].Value = value2
data[2].Value = value2
data[3].Value = value2

type args struct {
v {{.Type}}
}
tests := []struct {
name string
args args
want {{.Name}}
}{
{
name: "regular",
args: args{
v: value1,
},
want: data[0],
},
{
name: "multiple",
args: args{
v: value2,
},
want: data[1],
},
{
name: "none",
args: args{
v: value3,
},
want: {{.Name}}{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := New{{.Name}}Seq(data)
if got := s.Value(tt.args.v); !got.Equal(tt.want) {
t.Errorf("Value() = %v, want %v", got, tt.want)
}
})
}
}

func Test{{.Name}}Seq_MValue(t *testing.T) {
data := Random{{.Name}}s(100)
Sort(data)
Expand Down
4 changes: 4 additions & 0 deletions gen_float64_seq.go

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

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

4 changes: 4 additions & 0 deletions gen_int64_seq.go

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

106 changes: 106 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 acfaeee

Please sign in to comment.