Skip to content

Commit

Permalink
add test: bnc.TestSimpleKline_NotExist
Browse files Browse the repository at this point in the history
  • Loading branch information
dwdwow committed Mar 4, 2024
1 parent ee03d0c commit 3be2904
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bnc/kline.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func NewSimpleKlineFromStruct(k Kline) (kline SimpleKline) {
}

func (k SimpleKline) NotExist() bool {
return k[0] == 0
return k[1] == 0
}

func (k SimpleKline) OpenTime() int64 {
Expand Down
36 changes: 29 additions & 7 deletions bnc/kline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,36 @@ func TestNewSimpleKline(t *testing.T) {

}

// TestNotExist tests the NotExist method of the SimpleKline type
func TestSimpleKline_NotExist(t *testing.T) {
kline := SimpleKline{1}
if kline.NotExist() {
t.FailNow()
}
kline[0] = 0
if !kline.NotExist() {
t.FailNow()
tests := []struct {
name string
k SimpleKline
want bool
}{
{
name: "not_exist",
k: SimpleKline{1, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10},
want: true,
},
{
name: "exist",
k: SimpleKline{1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10},
want: false,
},
{
name: "empty_kline",
k: SimpleKline{},
want: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.k.NotExist(); got != tt.want {
t.Errorf("NotExist() = %v, want %v", got, tt.want)
}
})
}
}

Expand Down

0 comments on commit 3be2904

Please sign in to comment.