def test_sum_of_number_is_itself(self): calc = Calculator() self.assertEqual(calc.add("5"), 5, "Sum of number is itself")
def test_sum_of_two_numbers_comma_separated(self): calc = Calculator() self.assertEqual(calc.add("5,3"), 8, "Sum of 5,3 is 8")
def test_add(self): calculator = Calculator(operation="add", number1=4, number2=7) self.assertEqual(calculator.add(), 11)
def calc(a, b): print("==========开始测试============") cal: Calculator = Calculator(a, b) yield cal print("!!!!!!!!!!!!!结束测试!!!!!!!!!!!!!")
def test_subtract(self): calculator = Calculator(operation="subtract", number1=10, number2=7) self.assertEqual(calculator.subtract(), 3)
def test_get_operation(self): calculator = Calculator(operation="add", number1=10, number2=7) self.assertEqual(calculator.get_operation(), calculator.add) calculator = Calculator(operation="subtract", number1=10, number2=7) self.assertEqual(calculator.get_operation(), calculator.subtract)
import logging import db.postgres as pg from calculator.calculator import Calculator from settings import * logger = logging.getLogger(__name__) db = pg.Postgres(dbname=DB_NAME, user=DB_USER, password=DB_PASSWORD, host=DB_HOST, port=DB_PORT) def setup_logging(debug=False): logging_format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' level = logging.INFO if debug: level = logging.DEBUG logging.basicConfig(format=logging_format, level=level) if __name__ == "__main__": setup_logging(debug=DEBUG) calculator = Calculator(db) calculator.run()
def calculate_date_range(startDateObj, endDateObj): """This function expects user defined date class object for start and end dates.Returns difference between the same. If end date is less than start date, it just calucalte the difference backwards""" if validate.validate_date_range( validateObj, startDateObj, endDateObj): # Validates if start date is less than end date. return calObj.get_days_difference(startDateObj, endDateObj) else: return calObj.get_days_difference(endDateObj, startDateObj) if __name__ == "__main__": validateObj = validate() # Create Validate class object calObj = Calculator() # Create Calculator class object startDateString = read_input( "start date") # Call read_input to read start date in # (DD/MM/YYY) format. ex: 02/06/2001 startDateObj = create_date_obj( startDateString, "start date") # Create Date object from the date string endDateString = read_input( "end date") # Call read_input to read end date in # (DD/MM/YYY) format. ex: 22/06/1983 endDateObj = create_date_obj( endDateString, "end date") # Create Date object from the date string difference = calculate_date_range(
def setUp(self) -> None: self.calculator = Calculator()
def calculate(a, b): # Use a breakpoint in the code line below to debug your script. calc = Calculator() print('done') # Press Ctrl+F8 to toggle the breakpoint.
def setUp(self): self.calculator = Calculator(a(), s(), m(), d())
from calculator.adder import Adder from calculator.subtracter import Subtracter from calculator.multiplier import Multiplier from calculator.divider import Divider from calculator.calculator import Calculator from calculator.exceptions import InsufficientOperands if __name__ == '__main__': add = Adder() sub = Subtracter() multi = Multiplier() div = Divider() test_1 = Calculator(add, sub, multi, div) test_1.enter_number(1) test_1.enter_number(2) temp_num = test_1.add() print(temp_num)
def __init__(self): self._calc = Calculator() self._result = ''