Пример #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)