2018-05-07 09:30:50 +00:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
def call_command(command_to_call):
|
2018-05-07 14:38:28 +00:00
|
|
|
result = subprocess.check_output(command_to_call, shell=True)
|
|
|
|
return result[:-1].decode("utf-8")
|
2018-05-07 09:30:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestBC(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_divide(self):
|
|
|
|
result = call_command("echo '6.5 / 2.7' | bc")
|
2018-05-07 14:38:28 +00:00
|
|
|
self.assertEqual( result, '2')
|
2018-05-07 09:30:50 +00:00
|
|
|
|
|
|
|
def test_sum(self):
|
|
|
|
result = call_command("echo '2 + 5' | bc")
|
2018-05-07 14:38:28 +00:00
|
|
|
self.assertEqual( result, '7')
|
2018-05-07 09:30:50 +00:00
|
|
|
|
|
|
|
def test_difference(self):
|
|
|
|
result = call_command("echo '10 - 4' | bc")
|
2018-05-07 14:38:28 +00:00
|
|
|
self.assertEqual( result, '6')
|
2018-05-07 09:30:50 +00:00
|
|
|
|
|
|
|
def test_multiplying(self):
|
|
|
|
result = call_command("echo '3 * 8' | bc")
|
2018-05-07 14:38:28 +00:00
|
|
|
self.assertEqual( result, '24')
|
2018-05-07 09:30:50 +00:00
|
|
|
|
|
|
|
def test_scale(self):
|
|
|
|
result = call_command("echo 'scale = 2; 2 / 3' | bc")
|
2018-05-07 14:38:28 +00:00
|
|
|
self.assertEqual( result, '.66')
|
2018-05-07 09:30:50 +00:00
|
|
|
|
|
|
|
def test_remainder(self):
|
|
|
|
result = call_command("echo '6 % 4' | bc")
|
2018-05-07 14:38:28 +00:00
|
|
|
self.assertEqual( result, '2')
|
2018-05-07 09:30:50 +00:00
|
|
|
|
|
|
|
def test_exponent(self):
|
|
|
|
result = call_command("echo '10^2' | bc")
|
2018-05-07 14:38:28 +00:00
|
|
|
self.assertEqual( result, '100')
|
2018-05-07 09:30:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|