Esempio n. 1
0
func TestEval(t *testing.T) {
	assert.Equal(t, 1, Init())
	r, err := Eval("1+3*4")
	assert.Nil(t, err)
	assert.True(t, r.IsNumeric())
	assert.False(t, r.IsComplex())
	assert.Panics(t, func() { r.AsComplex() })
	num := r.AsNumeric()
	assert.Equal(t, 1, num.Len())
	assert.Equal(t, 13, num.Get(0))

	r = EvalOrDie("sqrt(-2+0i)")
	assert.False(t, r.IsNumeric())
	assert.True(t, r.IsComplex())
	assert.Panics(t, func() { r.AsNumeric() })
	cpl := r.AsComplex()
	assert.Equal(t, 1, cpl.Len())
	assert.Equal(t, complex(0, math.Sqrt(2)), cpl.Get(0))
}
Esempio n. 2
0
func Test_Mock_Called_Unexpected(t *testing.T) {

	var mockedService *TestExampleImplementation = new(TestExampleImplementation)

	// make sure it panics if no expectation was made
	assert.Panics(t, func() {
		mockedService.Mock.Called(1, 2, 3)
	}, "Calling unexpected method should panic")

}
Esempio n. 3
0
func TestEvalBadExpr(t *testing.T) {
	assert.Equal(t, 1, Init())
	r, err := Eval("x+")
	assert.Nil(t, r)
	assert.Error(t, err)

	assert.Panics(t, func() {
		EvalOrDie("+1*(")
	})
}