mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +01:00
Fixed bug found by G-LiTe and added a test.
This commit is contained in:
parent
68a84e17b0
commit
6c3e193b93
@ -127,6 +127,7 @@ class Math(callbacks.Privmsg):
|
||||
text = privmsgs.getArgs(args)
|
||||
text = text.translate(string.ascii, '_[] \t')
|
||||
text = text.replace('lambda', '')
|
||||
#debug.printf(text)
|
||||
def handleMatch(m):
|
||||
s = m.group(1)
|
||||
if s.startswith('0x'):
|
||||
@ -138,8 +139,12 @@ class Math(callbacks.Privmsg):
|
||||
i = int(s)
|
||||
else:
|
||||
i = float(s)
|
||||
return str(complex(i))
|
||||
x = complex(i)
|
||||
if x == abs(x):
|
||||
x = abs(x)
|
||||
return str(x)
|
||||
text = self._mathRe.sub(handleMatch, text)
|
||||
#debug.printf(text)
|
||||
try:
|
||||
x = complex(eval(text, self._mathEnv, self._mathEnv))
|
||||
irc.reply(msg, self._complexToString(x))
|
||||
|
@ -42,6 +42,7 @@ class MathTestCase(PluginTestCase, PluginDocumentation):
|
||||
self.assertResponse('calc -((-5)**.5)', '-2.2360679775i')
|
||||
self.assertNotRegexp('calc [9, 5] + [9, 10]', 'TypeError')
|
||||
self.assertError('calc [9, 5] + [9, 10]')
|
||||
self.assertNotError('calc degrees(2)')
|
||||
|
||||
def testRpn(self):
|
||||
self.assertResponse('rpn 5 2 +', '7')
|
||||
|
Loading…
Reference in New Issue
Block a user