-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplementation_test.go
More file actions
71 lines (60 loc) · 1.86 KB
/
implementation_test.go
File metadata and controls
71 lines (60 loc) · 1.86 KB
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
67
68
69
70
71
package lab2
import (
"testing"
"strings"
"fmt"
"github.com/stretchr/testify/assert"
)
func TestPostfixToPrefix(t *testing.T) {
res, err := ConvertPostfixToPrefix("3 3 -")
if assert.Nil(t, err) {
assert.Equal(t, "- 3 3", res)
}
}
func TestPostfixToPrefixLabExample(t *testing.T) {
res, err := ConvertPostfixToPrefix("4 2 - 3 * 5 +")
assert.Equal(t, nil, err)
assert.Equal(t, "+ * - 4 2 3 5", res)
}
func TestPostfixToPrefixOnlyPlus(t *testing.T) {
res, err := ConvertPostfixToPrefix("4 17 + 3 + 51 + 19 + 21 + 78")
assert.Equal(t, nil, err)
assert.Equal(t, "+ + + + + 4 17 3 51 19 21 78", res)
}
func TestPostfixToPrefixOnlyMinus(t *testing.T) {
res, err := ConvertPostfixToPrefix("4 3 - 13 - 21 - 5 - 19 - 1 - 2")
assert.Equal(t, nil, err)
assert.Equal(t, "- - - - - - 4 3 13 21 5 19 1 2", res)
}
func TestPostfixToPrefixOnlyMultiply(t *testing.T) {
res, err := ConvertPostfixToPrefix("100 101 * 102 *")
assert.Nil(t, err)
assert.Equal(t, "* * 100 101 102", res)
}
func TestPostfixToPrefixOnlyDivide(t *testing.T) {
res, err := ConvertPostfixToPrefix("18 2 / 3 /")
assert.Nil(t, err)
assert.Equal(t, "/ / 18 2 3", res)
}
func TestPostfixToPrefixAllOperators(t *testing.T) {
res, err := ConvertPostfixToPrefix("54 6 3 * / 7 + 11 -")
assert.Nil(t, err)
assert.Equal(t, "- + / 54 * 6 3 7 11", res)
}
func TestPostfixToPrefixEmptyInput(t *testing.T) {
res, err := ConvertPostfixToPrefix("")
assert.Equal(t, "", res)
assert.NotNil(t, err)
}
var res string
func BenchmarkPostfixToPrefix(b *testing.B) {
expression := "54 6 3 * / 7 + 11 -"
for i := 1; i <= 20; i++ {
repeatedExpression := strings.Repeat(expression, i * i) + "10" //add 10 to avoid broking expression
b.Run(fmt.Sprintf("%d-operators", i * i * 6), func(b *testing.B) {
for i := 0; i < b.N; i++ {
res, _ = ConvertPostfixToPrefix(repeatedExpression)
}
})
}
}