| 1 | package timeline |
| 2 | |
| 3 | import ( |
| 4 | "slices" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestMerge(t *testing.T) { |
| 9 | tests := []struct { |
| 10 | name string |
| 11 | a, b []int64 |
| 12 | n int |
| 13 | want []int64 |
| 14 | }{ |
| 15 | {"only the timeline", []int64{9, 5, 2}, nil, 3, []int64{9, 5, 2}}, |
| 16 | {"only pulled", nil, []int64{8, 4}, 3, []int64{8, 4}}, |
| 17 | {"cut at n", []int64{9, 5, 2}, []int64{8, 4}, 3, []int64{9, 8, 5}}, |
| 18 | {"the same post in both", []int64{9, 8, 5}, []int64{8, 4}, 3, []int64{9, 8, 5}}, |
| 19 | } |
| 20 | for _, tt := range tests { |
| 21 | t.Run(tt.name, func(t *testing.T) { |
| 22 | if got := merge(tt.a, tt.b, tt.n); !slices.Equal(got, tt.want) { |
| 23 | t.Errorf("merge(%v, %v, %d) = %v, want %v", tt.a, tt.b, tt.n, got, tt.want) |
| 24 | } |
| 25 | }) |
| 26 | } |
| 27 | } |