-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.go
41 lines (36 loc) · 866 Bytes
/
handler_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
package lab2
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
type OutputSim struct {
called bool
}
func (o *OutputSim) Write(p []byte) (n int, err error) {
o.called = true
return 0, nil
}
func TestComputerHandleCorrect(t *testing.T) {
testExpression := "4 2 - 3 * 5 +"
inputSimulation := strings.NewReader(testExpression)
outputSimulation := OutputSim{}
handler := ComputeHandler{
Input: inputSimulation,
Output: &outputSimulation,
}
err := handler.Compute()
assert.Nil(t, err)
assert.Equal(t, true, outputSimulation.called)
}
func TestComputerHandleIncorrect(t *testing.T) {
testExpression := ""
inputSimulation := strings.NewReader(testExpression)
outputSimulation := OutputSim{}
handler := ComputeHandler{
Input: inputSimulation,
Output: &outputSimulation,
}
err := handler.Compute()
assert.NotNil(t, err)
}