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