-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmyAtoi_test.go
47 lines (39 loc) · 1.13 KB
/
myAtoi_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
package stringtointegeratoi
import (
"testing"
"github.com/WindomZ/testify/assert"
)
func Test_myAtoi(t *testing.T) {
assert.Equal(t, 0, myAtoi(""))
assert.Equal(t, 1, myAtoi("1"))
assert.Equal(t, 1, myAtoi("+1"))
assert.Equal(t, -1, myAtoi("-1"))
assert.Equal(t, 12, myAtoi("+12"))
assert.Equal(t, -12, myAtoi("-12"))
assert.Equal(t, 123, myAtoi("+123"))
assert.Equal(t, -123, myAtoi("-123"))
assert.Equal(t, 123, myAtoi(" +123 "))
assert.Equal(t, -123, myAtoi(" -123 "))
assert.Equal(t, 123, myAtoi(" +123x"))
assert.Equal(t, -123, myAtoi(" -123x"))
assert.Equal(t, 2147483647, myAtoi("2147483647"))
assert.Equal(t, 2147483647, myAtoi("21474836471"))
assert.Equal(t, -2147483647, myAtoi("-2147483647"))
assert.Equal(t, -2147483648, myAtoi("-21474836471"))
assert.Equal(t, -2147483648, myAtoi("-2147483648"))
assert.Equal(t, -1010023630, myAtoi(" -1010023630o4"))
}
func Benchmark_myAtoi(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
b.StartTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
myAtoi("")
myAtoi("-1")
myAtoi(" 123 ")
myAtoi("+2147483648")
myAtoi("-2147483648")
}
})
}