Exemplo n.º 1
0
def home(request):
    submission = request.POST.get('user-input', '')
    output = utilities.process_string(submission)
    if output is None:
        outstring = 'Unable to evaluate your input. Please try again.'
    else:
        outstring = output
    c = {
        'submission': submission,
        'evaluation': outstring,
    }
    c.update(csrf(request))
    return render_to_response("calc.html", c)
Exemplo n.º 2
0
def home(request):
    submission = request.POST.get('user-input', '')
    output = utilities.process_string(submission)
    if output is None:
        outstring = 'Unable to evaluate your input. Please try again.'
    else:
        outstring = output
    c = {
        'submission': submission,
        'evaluation': outstring,
    }
    c.update(csrf(request))
    return render_to_response("calc.html", c)
 def test_minus(self):
     result = utilities.process_string("fifty three minus twenty one")
     self.assertEqual(32, result)
 def test_incorrect_ascending(self):
     nstring = 'four eighty one'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
 def test_incorrect_descending3(self):
     nstring = '430 twenty eight'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
 def test_unordered(self):
     nstring = 'four million three hundred thousand one hundred and seventy four'
     result = utilities.process_string(nstring)
     self.assertEqual(4300174, result)
 def test_order_of_operations(self):
     nstring = 'three ** (four minus two) * one plus two'
     result = utilities.process_string(nstring)
     self.assertEqual(11, result)
 def test_mod(self):
     result = utilities.process_string("fifty three mod twenty one")
     self.assertEqual(11, result)
 def test_spacing(self):
     nstring = 'twohundredthousandninehundredandfourminussixtysix'
     result = utilities.process_string(nstring)
     self.assertEqual(200838, result)    
Exemplo n.º 10
0
 def test_order_of_operations(self):
     nstring = 'three ** (four minus two) * one plus two'
     result = utilities.process_string(nstring)
     self.assertEqual(11, result)
Exemplo n.º 11
0
 def test_consecutive_digits(self):
     nstring = '12 4'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
Exemplo n.º 12
0
 def test_unordered(self):
     nstring = 'four million three hundred thousand one hundred and seventy four'
     result = utilities.process_string(nstring)
     self.assertEqual(4300174, result)
Exemplo n.º 13
0
 def test_places(self):
     nstring = 'two trillion four billion eighty eight million nine thousand five hundred ninety two'
     result = utilities.process_string(nstring)
     self.assertEqual(2004088009592, result)
Exemplo n.º 14
0
 def test_mixed(self):
     nstring = '30 thousand 800 seventy four'
     result = utilities.process_string(nstring)
     self.assertEqual(30874, result)
Exemplo n.º 15
0
 def test_spacing(self):
     nstring = 'twohundredthousandninehundredandfourminussixtysix'
     result = utilities.process_string(nstring)
     self.assertEqual(200838, result)
Exemplo n.º 16
0
 def test_decimals(self):
     nstring = 'two point one three plus four dot zero seven one'
     result = utilities.process_string(nstring)
     self.assertEqual(6.201, result)
Exemplo n.º 17
0
 def test_mod(self):
     result = utilities.process_string("fifty three mod twenty one")
     self.assertEqual(11, result)
Exemplo n.º 18
0
 def test_incorrect_ascending(self):
     nstring = 'four eighty one'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
Exemplo n.º 19
0
 def test_divide(self):
     result = utilities.process_string("fifty four \ twenty seven")
     self.assertEqual(2, result)
Exemplo n.º 20
0
 def test_incorrect_descending2(self):
     nstring = 'ten one'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
Exemplo n.º 21
0
 def test_decimals(self):
     nstring = 'two point one three plus four dot zero seven one'
     result = utilities.process_string(nstring)
     self.assertEqual(6.201, result)
Exemplo n.º 22
0
 def test_incorrect_descending3(self):
     nstring = '430 twenty eight'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
Exemplo n.º 23
0
 def test_mixed(self):
     nstring = '30 thousand 800 seventy four'
     result = utilities.process_string(nstring)
     self.assertEqual(30874, result)
Exemplo n.º 24
0
 def test_negative_power(self):
     nstring = '-(5 + ((1 + 2) ** -4) - 3)'
     result = utilities.process_string(nstring)
     self.assertEqual(-2.0123456790123457, result)
Exemplo n.º 25
0
 def test_places(self):
     nstring = 'two trillion four billion eighty eight million nine thousand five hundred ninety two'
     result = utilities.process_string(nstring)
     self.assertEqual(2004088009592, result)
Exemplo n.º 26
0
 def test_negative_power2(self):
     nstring = '(-3) ^ 3'
     result = utilities.process_string(nstring)
     self.assertEqual(-27, result)
Exemplo n.º 27
0
 def test_consecutive_digits(self):
     nstring = '12 4'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
Exemplo n.º 28
0
 def test_minus(self):
     result = utilities.process_string("fifty three minus twenty one")
     self.assertEqual(32, result)
Exemplo n.º 29
0
 def test_incorrect_descending2(self):
     nstring = 'ten one'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
Exemplo n.º 30
0
 def test_multiply(self):
     result = utilities.process_string("fifty three times twenty one")
     self.assertEqual(1113, result)
Exemplo n.º 31
0
 def test_negative_power(self):
     nstring = '-(5 + ((1 + 2) ** -4) - 3)'
     result = utilities.process_string(nstring)
     self.assertEqual(-2.0123456790123457, result)
Exemplo n.º 32
0
 def test_multiply(self):
     result = utilities.process_string("fifty three times twenty one")
     self.assertEqual(1113, result)
Exemplo n.º 33
0
 def test_negative_power2(self):
     nstring = '(-3) ^ 3'
     result = utilities.process_string(nstring)
     self.assertEqual(-27, result)
Exemplo n.º 34
0
 def test_divide(self):
     result = utilities.process_string("fifty four \ twenty seven")
     self.assertEqual(2, result)