|
| 1 | +local wordy = require('wordy') |
| 2 | + |
| 3 | +describe('wordy', function() |
| 4 | + it('just a number', function() |
| 5 | + assert.are.same(5, wordy.answer('What is 5?')) |
| 6 | + end) |
| 7 | + |
| 8 | + it('addition', function() |
| 9 | + assert.are.same(2, wordy.answer('What is 1 plus 1?')) |
| 10 | + end) |
| 11 | + |
| 12 | + it('more addition', function() |
| 13 | + assert.are.same(55, wordy.answer('What is 53 plus 2?')) |
| 14 | + end) |
| 15 | + |
| 16 | + it('addition with negative numbers', function() |
| 17 | + assert.are.same(-11, wordy.answer('What is -1 plus -10?')) |
| 18 | + end) |
| 19 | + |
| 20 | + it('large addition', function() |
| 21 | + assert.are.same(45801, wordy.answer('What is 123 plus 45678?')) |
| 22 | + end) |
| 23 | + |
| 24 | + it('subtraction', function() |
| 25 | + assert.are.same(16, wordy.answer('What is 4 minus -12?')) |
| 26 | + end) |
| 27 | + |
| 28 | + it('multiplication', function() |
| 29 | + assert.are.same(-75, wordy.answer('What is -3 multiplied by 25?')) |
| 30 | + end) |
| 31 | + |
| 32 | + it('division', function() |
| 33 | + assert.are.same(-11, wordy.answer('What is 33 divided by -3?')) |
| 34 | + end) |
| 35 | + |
| 36 | + it('multiple additions', function() |
| 37 | + assert.are.same(3, wordy.answer('What is 1 plus 1 plus 1?')) |
| 38 | + end) |
| 39 | + |
| 40 | + it('addition and subtraction', function() |
| 41 | + assert.are.same(8, wordy.answer('What is 1 plus 5 minus -2?')) |
| 42 | + end) |
| 43 | + |
| 44 | + it('multiple subtraction', function() |
| 45 | + assert.are.same(3, wordy.answer('What is 20 minus 4 minus 13?')) |
| 46 | + end) |
| 47 | + |
| 48 | + it('subtraction then addition', function() |
| 49 | + assert.are.same(14, wordy.answer('What is 17 minus 6 plus 3?')) |
| 50 | + end) |
| 51 | + |
| 52 | + it('multiple multiplication', function() |
| 53 | + assert.are.same(-12, wordy.answer('What is 2 multiplied by -2 multiplied by 3?')) |
| 54 | + end) |
| 55 | + |
| 56 | + it('addition and multiplication', function() |
| 57 | + assert.are.same(-8, wordy.answer('What is -3 plus 7 multiplied by -2?')) |
| 58 | + end) |
| 59 | + |
| 60 | + it('multiple division', function() |
| 61 | + assert.are.same(2, wordy.answer('What is -12 divided by 2 divided by -3?')) |
| 62 | + end) |
| 63 | + |
| 64 | + it('unknown operation', function() |
| 65 | + assert.has_error(function() |
| 66 | + wordy.answer('What is 52 cubed?') |
| 67 | + end, 'Invalid question') |
| 68 | + end) |
| 69 | + |
| 70 | + it('Non math question', function() |
| 71 | + assert.has_error(function() |
| 72 | + wordy.answer('Who is the President of the United States?') |
| 73 | + end, 'Invalid question') |
| 74 | + end) |
| 75 | + |
| 76 | + it('reject problem missing an operand', function() |
| 77 | + assert.has_error(function() |
| 78 | + wordy.answer('What is 1 plus?') |
| 79 | + end, 'Invalid question') |
| 80 | + end) |
| 81 | + |
| 82 | + it('reject problem with no operands or operators', function() |
| 83 | + assert.has_error(function() |
| 84 | + wordy.answer('What is?') |
| 85 | + end, 'Invalid question') |
| 86 | + end) |
| 87 | + |
| 88 | + it('reject two operations in a row', function() |
| 89 | + assert.has_error(function() |
| 90 | + wordy.answer('What is 1 plus plus 2?') |
| 91 | + end, 'Invalid question') |
| 92 | + end) |
| 93 | + |
| 94 | + it('reject two numbers in a row', function() |
| 95 | + assert.has_error(function() |
| 96 | + wordy.answer('What is 1 plus 2 1?') |
| 97 | + end, 'Invalid question') |
| 98 | + end) |
| 99 | + |
| 100 | + it('reject postfix notation', function() |
| 101 | + assert.has_error(function() |
| 102 | + wordy.answer('What is 1 2 plus?') |
| 103 | + end, 'Invalid question') |
| 104 | + end) |
| 105 | + |
| 106 | + it('reject prefix notation', function() |
| 107 | + assert.has_error(function() |
| 108 | + wordy.answer('What is plus 1 2?') |
| 109 | + end, 'Invalid question') |
| 110 | + end) |
| 111 | +end) |
0 commit comments