def test_multiple_numbers(self):
     assert 5050 == add("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16," +
                        "17,18,19,20,21,22,23,24,25,26,27,28,29," +
                        "30,31,32,33,34,35,36,37,38,39,40,41,42," +
                        "43,44,45,46,47,48,49,50,51,52,53,54,55," +
                        "56,57,58,59,60,61,62,63,64,65,66,67,68," +
                        "69,70,71,72,73,74,75,76,77,78,79,80,81," +
                        "82,83,84,85,86,87,88,89,90,91,92,93,94," +
                        "95,96,97,98,99,100")
Example #2
0
def prob3(a,b):
    """Calculate and return the length of the hypotenuse of a right triangle.
    Do not use any methods other than those that are imported from the
    'calculator' module.
    
    Parameters:
        a (float): the length one of the sides of the triangle.
        b (float): the length the other nonhypotenuse side of the triangle.
    
    Returns:
        The length of the triangle's hypotenuse.
    """
    return calc.square_root(calc.add(calc.mult(a,a),calc.mult(b,b)))
Example #3
0
def main():
    op = input("enter op.: +, -, *, /: ")
    num1 = int(input("enter a number: "))
    num2 = float(input("enter a decimal number: "))

    if op == "+":
        result = calculator.add(num1, num2)
    elif op == "-":
        result = calculator.sub(num1, num2)
    elif op == "*":
        result = calculator.mult(num1, num2)
    elif op == "/":
        result = calculator.div(num1, num2)
    else:
        print("Invalid operation")
    print(result)
 def test_reject_negatives(self):
     try:
         add("1,3,-1,4")
         assert False, "ValueError expected"
     except ValueError:
         pass
Example #5
0
def test_three_digits_seperated():
    assert add('42,-1,17') == 58
def test_add_no_negatives_two():
	try:
		add("-1,-2")
	except ValueError as e:
		assert e.message == "negatives not allowed [-1, -2]",e.message
Example #7
0
 def test_add(self):
     result = add(2,2)
     self.assertEqual(result , 4)
print('Great! Now enter the second number: ')
second = int(input())

choice = 0

#let's output a menu
while choice != 5:
    print('Choose what you\'d like to do with ' + str(first) + ' and ' + str(second) + ':')
    print('\t1: add')
    print('\t2: subtract')
    print('\t3: multiply')
    print('\t4: divide')
    print('\t5: exit')

    choice = int(input())

    # this series of if-statements call the proper functions from within the calculator program
    if choice == 1:
        print('The calculator returned: ' + str(calculator.add( first, second )))
    elif choice == 2:
        print('The calculator returned: ' + str(calculator.subtract( first, second )))
    elif choice == 3:
        print('The calculator returned: ' + str(calculator.multiply( first, second )))
    elif choice == 4:
        print('The calculator returned: ' + str(calculator.divide( first, second )))
    elif choice == 5:
        print('Goodbye!')
    else:
        print('Sorry that\'s not a valid choice. Try again.')
def test_add_mixed_delimeters():
	assert 1+2+3==add("1\n2,3")
Example #10
0
from calculator import add, mul, sqr
add(10, 20)
mul(2, 8)
sqr(2)
w = raw_input('enter ur no')
print(w)
n = raw_input("enter ur name")
print(n)
Example #11
0
import calculator
import network.config
import db.config
print(calculator.add(4, 5))
 def test_ignore_greater_than_1000(self):
     assert 2 == add("1001,2")
     assert 1002 == add("1000,2")
Example #13
0
 def test_add(self):
     assert calculator.add(1, 2) == 3
Example #14
0
 def test_addition(self):
     assert 4 == calculator.add(2, 2)
 def test_simple(self):
     "addition of comma-separated integers"
     assert 2 == add("1,1")
     assert 7 == add("1,4,2")
 def test_multicharacter_multiple_delimiter(self):
     assert 9 == add("//[***][%]\n1\n2***3%3")
     assert 9 == add("//[***][->]\n1\n2***3->3")
Example #17
0
def test_multi_line_with_commas():
    assert add('1,2\n3,4\n42') == 52
Example #18
0
# print(add(10,10))

# custom module, fxn wrap and multiple decorator study
# read documentation at python.org

# from functools import wraps

# def test(anyfunction):
#     @wraps(anyfunction)
#     def inner():
#         """ Hello inner function """
#         return "test"

#     return inner

# @test
# def get():
#     """ Hello get function """
#     return "success"

# print(get.__doc__)


#online compiler linux study

import calculator 
print(calculator.add(20,10))
print(calculator.sub(40,30))


#git ignore, OS module,  system module study
Example #19
0
def test_single_digit():
    assert add('0') == 0
    assert add('9') == 9
Example #20
0
# -*- coding: utf-8 -*-
# UTF-8 encoding when using korean
import calculator

add_result = calculator.add(10, 2)
sub_result = calculator.sub(10, 2)
mul_result = calculator.mul(10, 2)
div_result = calculator.div(10, 2)
mod_result = calculator.mod(10, 2)

print(add_result)
print(sub_result)
print(mul_result)
print(div_result)
print(mod_result)
Example #21
0
def test_add_typeerror():
    with pytest.raises(TypeError) as e:
        assert calculator.add('yes', 1)
    assert str(
        e.value
    ) == 'can only concatenate str (not "int") to str'  #Also checking if the output is correct
Example #22
0
 def test_add(self):
   self.assertEqual(calculator.add(2, 3), 5)
 def test_multicharacter_delimiter(self):
     assert 9 == add("//[***]\n1\n2***3***3")
Example #24
0
import calculator as cal
import list as li

print("calculator is working", "Add is", cal.add(x, y), "Sub is",
      cal.subtract(x, y), "Multliply is", cal.multiply(x, y), "Divide is",
      cal.divide(x, y))

print("\n")

print("list operations are")
A = [1, 2, 3, 4, 5, 6, 7, 8, 9]
li.Full(A)
def _test_add_variable_delimeters_Three():
	assert 1+2+3==add("//;\n1;2;3")
Example #26
0
 def test_add(self):
     self.assertEqual(calc.add(43, 25), 68)
     self.assertEqual(calc.add(-1, 1), 0)
     self.assertEqual(calc.add(-1, -1), -2)
 def test_add(self):
     self.assertEqual(5 + 6, calculator.add(5, 6))
def test_calc_double_add():
    temp = calculator.add(2.3, 4.6)
    assert temp == float(6.9)
Example #29
0
 def test_stringinput(self):
   with self.assertRaises(TypeError):
     self.assertEqual(calculator.add(1,'A'),2)
def test_calc_int_add():
    temp = calculator.add(2, 4)
    assert temp == 6
Example #31
0
 def test_numbers_3_4(self):
     self.assertEqual(add(3, 4), 7)
def test_calc_undef_mult():
    temp = calculator.add('nonum', 'ahmet')
    assert temp == 'Error'
Example #33
0
def test_two_digits_on_seperate_lines():
    assert add('17\n42') == 59
 def testAddition(self):
     '''Calculator should return the sum of two numbers'''
     for num1, num2 in self.testValues:
         result = calculator.add(num1, num2)
         self.assertEqual(9, result)
Example #35
0
def test_empty_string():
    assert add('') == 0
Example #36
0
import calculator as calc
import datetime as dt

print(calc.add(3, 5))
print(dt.datetime(2020, 4, 12))
Example #37
0
def test_two_digits_seperated_by_commas():
    assert add('1,1') == 2
Example #38
0
 def test_add(self):
     #self.assertEqual(calculator.add(2,3), 6)
     print('test_Add===========')
     self.assertEqual(calculator.add(2,3), 5)
def testAdd():
    assert (calculator.add(0,3) == 3)
    assert (calculator.add(5,0) == 5)
    assert (calculator.add(-1,-7) == -8)
    assert (calculator.add(-8,3) == -5)
Example #40
0
 def test_add(self):
     self.assertEqual(add(0,0), 0)   
     self.assertEqual(add(2,2), 4)
     self.assertEqual(add(2,6), 8)
'''
    this teaches you how to create your own module
    use : suppose there are a no. of functions which are used in most of files
     so you wouid not write them in every single file
     you can simply club all these commonly used functions and import the module in whicheer file reqd
'''


import calculator
import random

calculator.add(10,20,30,50)
calculator.div(100,20)
calculator.mul(10,2,3,5)

i = random.randrange(0, 10)     # random is also a module written by a deveolper
print i
def test_add_three():
	assert 1+2+3==add("1,2,3")
Example #43
0
import calculator

a = int(input("enter the first number"))
b = int(input("enter the second number"))
calculator.add(a, b)
calculator.sub(a, b)
 def test_empty(self):
     "addition of empty o null inputs is 0"
     assert 0 == add(None)
     assert 0 == add("")
def test_add_two():
	assert 1+2==add("1,2")
def test_positives():
    result = add(4, 5)
    assert result == 9
def test_add_n():
	"""Overkill? """
	l = [str(i) for i in range(10)]
	string_list = ",".join(l)
	sum_list = sum(range(10))
	assert sum_list==add(string_list)
def test_many_numbers():
    result = add(1, 2, 3, 4)
    assert result == 10
def test_add_variable_delimeters():
	assert 1+2==add("//;\n1;2")
def test_add_zeros():
    result = add(0, 0)
    assert result == 0
def test_add_zero():
	assert 0==add("")
def test_negatives():
    result = add(-1, -1)
    assert result == -2
def test_add_one():
	assert 1==add("1")
Example #54
0
def test_add():
    assert calculator.add(2, 1) == 3
Example #55
0
import calculator
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
print(a,"+",b,"=",calculator.add(a, b))
print(a,"-",b,"=",calculator.subtract(a, b))
print(a,"*",b,"=",calculator.multiply(a, b))
print(a,"/",b,"=",calculator.divide(a, b))
Example #56
0
 def test_addition(self):
     assert 4 == calculator.add(2, 2)
Example #57
0
 def test_operator(self):
   self.assertEqual(calculator.add(13,11),24)
   self.assertEqual(calculator.subtract(15,-10),25)
   self.assertEqual(calculator.divide(16,2),8)
   self.assertEqual(calculator.multiply(7,-3),-21)
Example #58
0
 def test_strings_5_3(self):
     self.assertEqual(add(5, 3), 8)
Example #59
0
 def test_Add(self):
   self.assertEqual(calculator.add(1,1),2)
Example #60
0
 def test_strings_5_4(self):
     self.assertEqual(add(5, 4), 9)