コード例 #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
ファイル: views.py プロジェクト: emilgeorgejames1/nlc-django
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)
コード例 #3
0
 def test_minus(self):
     result = utilities.process_string("fifty three minus twenty one")
     self.assertEqual(32, result)
コード例 #4
0
 def test_incorrect_ascending(self):
     nstring = 'four eighty one'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
コード例 #5
0
 def test_incorrect_descending3(self):
     nstring = '430 twenty eight'
     result = utilities.process_string(nstring)
     self.assertIsNone(result)
コード例 #6
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)
コード例 #7
0
 def test_order_of_operations(self):
     nstring = 'three ** (four minus two) * one plus two'
     result = utilities.process_string(nstring)
     self.assertEqual(11, result)
コード例 #8
0
 def test_mod(self):
     result = utilities.process_string("fifty three mod twenty one")
     self.assertEqual(11, result)
コード例 #9
0
 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)