-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnotation_test.go
More file actions
44 lines (35 loc) · 949 Bytes
/
Copy pathnotation_test.go
File metadata and controls
44 lines (35 loc) · 949 Bytes
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
package stack
import (
"strings"
"testing"
)
func Test_isNum(t *testing.T) {
if r := isNum("2"); r != true {
t.Fatal(r)
}
if r := isNum("0.023231"); r != true {
t.Fatal(r)
}
}
func Test_IN2RPN(t *testing.T) {
infix := "4.99 * 1.06 + 5.99 + 6.99 * 1.06"
reversePolish := "4.99 1.06 * 5.99 + 6.99 1.06 * +"
if r := IN2RPN(strings.Split(infix, " ")); strings.Join(r, " ") != reversePolish {
t.Fatal(r)
}
infix = "( ( 4.99 * 1.06 ) + 5.99 ) + ( 6.99 * 1.06 )"
if r := IN2RPN(strings.Split(infix, " ")); strings.Join(r, " ") != reversePolish {
t.Fatal(r)
}
}
func Test_IN2PN(t *testing.T) {
infix := "4.99 * 1.06 + 5.99 + 6.99 * 1.06"
polish := "+ + * 4.99 1.06 5.99 * 6.99 1.06"
if r := IN2PN(strings.Split(infix, " ")); strings.Join(r, " ") != polish {
t.Fatal(r)
}
infix = "( ( 4.99 * 1.06 ) + 5.99 ) + ( 6.99 * 1.06 )"
if r := IN2PN(strings.Split(infix, " ")); strings.Join(r, " ") != polish {
t.Fatal(r)
}
}