-
Notifications
You must be signed in to change notification settings - Fork 0
/
numblr_test.go
37 lines (31 loc) · 1.02 KB
/
numblr_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"testing"
"github.com/heyLu/numblr/feed"
"github.com/stretchr/testify/assert"
)
func TestNextPostsGroup(t *testing.T) {
testCases := []struct {
author string
groupSize int
posts []*feed.Post
numGroup, numRest int
}{
{"a", 3, []*feed.Post{{Author: "a"}, {Author: "a"}, {Author: "a"}, {Author: "b"}, {Author: "c"}, {Author: "d"}}, 3, 3},
{"a", 3, []*feed.Post{{Author: "a"}, {Author: "x"}, {Author: "a"}, {Author: "b"}, {Author: "c"}, {Author: "d"}}, 1, 5},
{"a", 3, []*feed.Post{{Author: "a"}, {Author: "a"}, {Author: "a"}}, 3, 0},
}
for _, tc := range testCases {
t.Run(tc.author, func(t *testing.T) {
group, rest := nextPostsGroup(tc.posts, tc.groupSize)
assert.Equal(t, tc.numGroup, len(group), "group")
assert.Equal(t, tc.numRest, len(rest), "group")
for _, post := range group {
assert.Equal(t, tc.author, post.Author, "group author")
}
if len(rest) > 0 {
assert.NotEqual(t, tc.author, rest[0].Author, "rest author")
}
})
}
}