2013-11-17 15:37:14 -05:00
|
|
|
# coding=utf-8
|
2012-06-02 17:23:26 -04:00
|
|
|
"""
|
|
|
|
test_calc.py - tests for the calc module
|
|
|
|
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
|
|
|
|
"""
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
from mock import MagicMock, Mock
|
2016-03-06 17:55:50 -05:00
|
|
|
from modules.calc import c
|
2012-06-02 17:23:26 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TestCalc(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.phenny = MagicMock()
|
|
|
|
|
|
|
|
def test_c(self):
|
|
|
|
input = Mock(group=lambda x: '5*5')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('25')
|
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
def test_c_simplify(self):
|
|
|
|
input = Mock(group=lambda x: 'simplify 2^2+2(2)')
|
2013-11-17 15:37:14 -05:00
|
|
|
c(self.phenny, input)
|
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
self.phenny.say.assert_called_once_with('8')
|
2013-11-17 15:37:14 -05:00
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
def test_c_factor(self):
|
|
|
|
input = Mock(group=lambda x: 'factor x^2 + 2x')
|
2012-06-05 21:24:43 -04:00
|
|
|
c(self.phenny, input)
|
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
self.phenny.say.assert_called_once_with('x (x + 2)')
|
2012-06-05 21:24:43 -04:00
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
def test_c_derive(self):
|
|
|
|
input = Mock(group=lambda x: 'derive x^2+2x')
|
2012-06-19 21:04:00 -04:00
|
|
|
c(self.phenny, input)
|
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
self.phenny.say.assert_called_once_with('2 x + 2')
|
|
|
|
|
|
|
|
def test_c_integrate(self):
|
|
|
|
input = Mock(group=lambda x: 'integrate x^2+2x')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('1/3 x^3 + x^2')
|
|
|
|
|
|
|
|
def test_c_zeroes(self):
|
|
|
|
input = Mock(group=lambda x: 'zeroes x^2+2x')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('[-2, 0]')
|
|
|
|
|
|
|
|
def test_c_tangent(self):
|
|
|
|
input = Mock(group=lambda x: 'tangent 2|x^3')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('12 x + -16')
|
|
|
|
|
|
|
|
def test_c_area(self):
|
|
|
|
input = Mock(group=lambda x: 'area 2:4|x^3')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('60')
|
|
|
|
|
|
|
|
def test_c_cos(self):
|
|
|
|
input = Mock(group=lambda x: 'cos pi')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('-1')
|
|
|
|
|
|
|
|
def test_c_sin(self):
|
|
|
|
input = Mock(group=lambda x: 'sin 0')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('0')
|
2017-07-07 00:28:10 -04:00
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
def test_c_tan(self):
|
|
|
|
input = Mock(group=lambda x: 'tan .03')
|
2017-07-07 00:28:10 -04:00
|
|
|
c(self.phenny, input)
|
|
|
|
|
2019-06-20 21:45:18 -04:00
|
|
|
self.phenny.say.assert_called_once_with('0.030009')
|
|
|
|
|
|
|
|
def test_c_arccos(self):
|
|
|
|
input = Mock(group=lambda x: 'arccos 1')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('0')
|
|
|
|
|
|
|
|
def test_c_arcsin(self):
|
|
|
|
input = Mock(group=lambda x: 'arcsin .04')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('0.0400107')
|
|
|
|
|
|
|
|
def test_c_arctan(self):
|
|
|
|
input = Mock(group=lambda x: 'arctan 1')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('1/2 pi')
|
|
|
|
|
|
|
|
def test_c_abs(self):
|
|
|
|
input = Mock(group=lambda x: 'abs -3')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('3')
|
|
|
|
|
|
|
|
def test_c_log(self):
|
|
|
|
input = Mock(group=lambda x: 'log 2|8')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with('3')
|
|
|
|
|
|
|
|
def test_c_none(self):
|
|
|
|
input = Mock(group=lambda x: 'tangent 2lx^3')
|
|
|
|
c(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.reply.assert_called_once_with('Sorry, no result.')
|