Skip to content

Commit

Permalink
calc: test even more edge cases
Browse files Browse the repository at this point in the history
These additional cases (and a new error handler) cover as much of the
`tools.calculation` submodule as possible using the example decorator.
Further coverage of `tools.calculation` would require real unit tests
of the sort one finds in this project's `test/` directory.
  • Loading branch information
dgw committed Oct 28, 2023
1 parent b7537ff commit 24db1cc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions sopel/modules/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@
@plugin.example('.c foo * bar', "Can't process expression: Node type 'Name' is not supported.")
@plugin.example('.c 10 / 0', 'Division by zero is not supported in this universe.')
@plugin.example('.c 10\\2', 'Invalid syntax')
@plugin.example('.c (10**1000000)**2',
"Couldn't run the calculation: "
"ValueError('Pow expression too complex to calculate.')")
@plugin.example('.c (10**100000)**2 * (10**100000)**2',
"Couldn't run the calculation: "
"ValueError('Value is too large to be handled in limited time and memory.')")
@plugin.example('.c 5 + 3', '8')
@plugin.example('.c 0.9*10', '9')
@plugin.example('.c 10*0.9', '9')
@plugin.example('.c 0.5**2', '0.25')
@plugin.example('.c 3**0', '1')
@plugin.example('.c 0 * 5', '0')
@plugin.example('.c 5**5', '3125')
@plugin.example('.c 2*(1+2)*3', '18', user_help=True)
@plugin.example('.c 2**10', '1024', user_help=True)
@plugin.example('.c 5 // 2', '2', user_help=True)
Expand All @@ -43,5 +53,8 @@ def c(bot, trigger):
except SyntaxError:
bot.reply('Invalid syntax')
return
except ValueError as err:
bot.reply("Couldn't run the calculation: %r" % err)
return

bot.say(result)

0 comments on commit 24db1cc

Please sign in to comment.