forked from anz-bank/go-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
66 lines (47 loc) · 1.09 KB
/
main_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"bytes"
"math/rand"
"sort"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBubbleSortMain(t *testing.T) {
var buf bytes.Buffer
out = &buf
main()
expected := strconv.Quote("[1 2 3 5]\n")
actual := strconv.Quote(buf.String())
if expected != actual {
t.Errorf("Unexpected output in main()")
}
}
func TestBubbleWithSmallSlice(t *testing.T) {
a := assert.New(t)
sorted := bubble([]int{2, 1})
expected := []int{1, 2}
a.Equal(expected, sorted)
}
func TestBubbleWithRepeatedNumbers(t *testing.T) {
a := assert.New(t)
sorted := bubble([]int{3, 1, 2, 3, 2, 1})
expected := []int{1, 1, 2, 2, 3, 3}
a.Equal(expected, sorted)
}
func TestBubbleWithLargeSlice(t *testing.T) {
a := assert.New(t)
expected := make([]int, 100)
for i := range expected {
expected[i] = rand.Intn(1000)
}
sorted := bubble(expected)
sort.Ints(expected)
a.Equal(expected, sorted)
}
func TestBubbleWithSmallSliceIncludingNegativeInts(t *testing.T) {
a := assert.New(t)
sorted := bubble([]int{1, -2, -3})
expected := []int{-3, -2, 1}
a.Equal(expected, sorted)
}