예제 #1
0
 def test_sum_of_number_is_itself(self):
     calc = Calculator()
     self.assertEqual(calc.add("5"), 5, "Sum of number is itself")
예제 #2
0
 def test_sum_of_two_numbers_comma_separated(self):
     calc = Calculator()
     self.assertEqual(calc.add("5,3"), 8, "Sum of 5,3 is 8")
예제 #3
0
 def test_add(self):
     calculator = Calculator(operation="add", number1=4, number2=7)
     self.assertEqual(calculator.add(), 11)
예제 #4
0
def calc(a, b):
    print("==========开始测试============")
    cal: Calculator = Calculator(a, b)
    yield cal
    print("!!!!!!!!!!!!!结束测试!!!!!!!!!!!!!")
예제 #5
0
 def test_subtract(self):
     calculator = Calculator(operation="subtract", number1=10, number2=7)
     self.assertEqual(calculator.subtract(), 3)
예제 #6
0
 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)
예제 #7
0
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()
예제 #8
0
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()
예제 #10
0
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.
예제 #11
0
 def setUp(self):
     self.calculator = Calculator(a(), s(), m(), d())
예제 #12
0
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)
예제 #13
0
 def __init__(self):
     self._calc = Calculator()
     self._result = ''