Esempio 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)
Esempio 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)    
Esempio 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)
Esempio n. 11
0
 def test_consecutive_digits(self):
     nstring = '12 4'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
Esempio 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)
Esempio 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)
Esempio n. 14
0
 def test_mixed(self):
     nstring = '30 thousand 800 seventy four'
     result = utilities.process_string(nstring)
     self.assertEqual(30874, result)
Esempio n. 15
0
 def test_spacing(self):
     nstring = 'twohundredthousandninehundredandfourminussixtysix'
     result = utilities.process_string(nstring)
     self.assertEqual(200838, result)
Esempio 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)
Esempio n. 17
0
 def test_mod(self):
     result = utilities.process_string("fifty three mod twenty one")
     self.assertEqual(11, result)
Esempio n. 18
0
 def test_incorrect_ascending(self):
     nstring = 'four eighty one'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
 def test_divide(self):
     result = utilities.process_string("fifty four \ twenty seven")
     self.assertEqual(2, result)
Esempio n. 20
0
 def test_incorrect_descending2(self):
     nstring = 'ten one'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
 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)
Esempio n. 22
0
 def test_incorrect_descending3(self):
     nstring = '430 twenty eight'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
 def test_mixed(self):
     nstring = '30 thousand 800 seventy four'
     result = utilities.process_string(nstring)
     self.assertEqual(30874, result)
Esempio n. 24
0
 def test_negative_power(self):
     nstring = '-(5 + ((1 + 2) ** -4) - 3)'
     result = utilities.process_string(nstring)
     self.assertEqual(-2.0123456790123457, result)
 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)
Esempio n. 26
0
 def test_negative_power2(self):
     nstring = '(-3) ^ 3'
     result = utilities.process_string(nstring)
     self.assertEqual(-27, result)
 def test_consecutive_digits(self):
     nstring = '12 4'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
Esempio n. 28
0
 def test_minus(self):
     result = utilities.process_string("fifty three minus twenty one")
     self.assertEqual(32, result)
 def test_incorrect_descending2(self):
     nstring = 'ten one'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
Esempio n. 30
0
 def test_multiply(self):
     result = utilities.process_string("fifty three times twenty one")
     self.assertEqual(1113, result)
 def test_negative_power(self):
     nstring = '-(5 + ((1 + 2) ** -4) - 3)'
     result = utilities.process_string(nstring)
     self.assertEqual(-2.0123456790123457, result)
 def test_multiply(self):
     result = utilities.process_string("fifty three times twenty one")
     self.assertEqual(1113, result)
 def test_negative_power2(self):
     nstring = '(-3) ^ 3'
     result = utilities.process_string(nstring)
     self.assertEqual(-27, result)
Esempio n. 34
0
 def test_divide(self):
     result = utilities.process_string("fifty four \ twenty seven")
     self.assertEqual(2, result)