def test_add_string_and_number(self):
     """
     Test the addition of a string and a float returns them as one
     concatenated string (in which the float is converted to a string)
     """
     result = calc.add2('abc', '5.5')
     self.assertEqual(result, 'abc5.5')
示例#2
0
 def test_add_string_and_integer(self):
     """
     Test the addition of a string and an integer returns them as one
     concatenated string (in which the integer is converted to a string)
     """
     result = calc.add2('abc', 3)
     self.assertEqual(result, 'abc3')
示例#3
0
 def test_add_strings(self):
     """
     Test the addition of two strings returns the two strings as one
     concatenated string
     """
     result = calc.add2('abc', 'def')
     self.assertEqual(result, 'abcdef')
示例#4
0
 def test_add_string_and_number(self):
     """
     Test the addition of a string and a float returns them as one
     concatenated string (in which the float is converted to a string)
     """
     result = calc.add2('abc', '5.5')
     self.assertEqual(result, 'abc5.5')
 def test_add_strings(self):
     """
     Test the addition of two strings returns the two strings as one
     concatenated string
     """
     result = calc.add2('abc', 'def')
     self.assertEqual(result, 'abcdef')
 def test_add_string_and_integer(self):
     """
     Test the addition of a string and an integer returns them as one
     concatenated string (in which the integer is converted to a string)
     """
     result = calc.add2('abc', 3)
     self.assertEqual(result, 'abc3')
示例#7
0
 def test_add_integers(self):
     result = calc.add2(1, 2)
     self.assertEqual(result, 3)
'''
A simple command line tool that takes 2 values and adds them together using
the calc.py library's 'add2' function.
'''

import sys
import calc

argnumbers = len(sys.argv) - 1

if argnumbers == 2 :
    print("")
    print("The RESULT is " + str(calc.add2(str(sys.argv[1]), str(sys.argv[2]))))
    print("")
    sys.exit(0)

if argnumbers != 2 :
    print("")
    print("You entered " + str(argnumbers) + " value/s.")
    print("")
    print("Usage: 'add2vals X Y' where X and Y are individual values.")
    print("       If add2vals is not in your path, usage is './add2vals X Y'.")
    print("       If unbundled, usage is 'python add2vals.py X Y'.")
    print("")
    sys.exit(1)
 def test_add_neg_and_pos_num(self):
     """
     Test the addition of a negative number and a positive number
     """
     result = calc.add2(3, -2)
     self.assertEqual(result, 1)
示例#10
0
'''
A simple command line tool that takes 2 values and adds them together using
the calc.py library's 'add2' function.
'''

import sys
import calc

argnumbers = len(sys.argv) - 1

if argnumbers == 2 :
    print("")
    print("The result is " + str(calc.add2(str(sys.argv[1]), str(sys.argv[2])) + 1))
    print("")
    sys.exit(0)

if argnumbers != 2 :
    print("")
    print("You entered " + str(argnumbers) + " value/s.")
    print("")
    print("Usage: 'add2vals X Y' where X and Y are individual values.")
    print("       If add2vals is not in your path, usage is './add2vals X Y'.")
    print("       If unbundled, usage is 'python add2vals.py X Y'.")
    print("")
    sys.exit(1)
示例#11
0
					print "Invalid operand! Try again!"
					exit(0)
				break
			i+=1


		while(i<len(ch)):
			if ch[i]>='0' and ch[i]<='9' or ch[i]=='.' or ch[i]== '-':
				n2+=ch[i]
			i+=1
	"""

		

	if ch[opf]=='+' :
		Ans=op.add2(float(n1),float(n2))
		print "\n",n1+ch[opf]+n2,"=",Ans
	elif ch[opf]=='-' :
		Ans=op.sub2(float(n1),float(n2))
		print "\n",n1+ch[opf]+n2,"=",Ans
	elif ch[opf]=='/' :
		Ans=op.div2(float(n1),float(n2))
		print "\n",n1+ch[opf]+n2,"=",Ans
	elif ch[opf]=='*' :	
		Ans=op.mul2(float(n1),float(n2))
		print "\n",n1+ch[opf]+n2,"=",Ans
	elif ch[opf]=='%' :
		Ans=op.rem1(float(n1),float(n2))
		print "\n",n1+ch[opf]+n2,"=",Ans
	elif ch[opf]=='^' :	
		Ans=op.pow(float(n1),float(n2))
示例#12
0
 def test_add_strings(self):
   """
   Test adding two strings become one string
   """
   result = calc.add2("hello", "there")
   self.assertEqual(result, "hellothere")
 def test_add_floats(self):
     """
     Test that the addition of two floats returns the correct result
     """
     result = calc.add2('10.5', 2)
     self.assertEqual(result, 12.5)
 def test_add2(self):
     self.assertEqual(calc.add2(7), 9)
'''
A simple command line tool that takes 2 values and adds them together using
the calc.py library's 'add2' function.
'''

import sys
import calc

argnumbers = len(sys.argv) - 1

if argnumbers == 2 :
    print("")
    print("The result is " + str(calc.add2(str(sys.argv[1]), str(sys.argv[2]))))
    print("")
    sys.exit(0)

if argnumbers != 2 :
    print("")
    print("You entered " + str(argnumbers) + " value/s.")
    print("")
    print("Usage: 'add2vals X Y' where X and Y are individual values.")
    print("       If add2vals is not in your path, usage is './add2vals X Y'.")
    print("       If unbundled, usage is 'python add2vals.py X Y'.")
    print("")
    sys.exit(1)
示例#16
0
 def test_add_floats(self):
     result = calc.add2('10.5', 2)
     self.assertEqual(result, 12.5)
示例#17
0
 def test_add_string_float(self):
   """
   Test add one string and float number together return back as one concatened string in which float being convert to string
   """
   result = calc.add2("glue", "4.6")
   self.assertEqual(result, "glue4.6")
示例#18
0
 def test_add_floats(self):
   """
   Test that the addition of two floats return the correct result
   """
   result = calc.add2("2.3", "4.5")
   self.assertEqual(result, 6.8)
示例#19
0
def compute(a, b):
    value = calc.add2(a, b)
    log_result_in_file(a, b, value)
    return value
示例#20
0
 def test_add_string_integer(self):
   """
   Test add string and integer return them back as a concatened string in which interger being conver as string
   """
   result = calc.add2("join", 5)
   self.assertEqual(result, "join5")
 def test_add_integers(self):
     """
     Test that the addition of two integers returns the correct total
     """
     result = calc.add2(1, 2)
     self.assertEqual(result, 3)
示例#22
0
""" A simple command line tool that takes 2 values and adds them together using 
the calc.py library's 'add2' function. """

import sys
import calc

argnumbers = len(sys.argv) - 1

if argnumbers == 2:
    print("")
    print("The result is " +
          str(calc.add2(str(sys.argv[1]), str(sys.argv[2]))))
    print("")
    sys.exit(0)

if argnumbers != 2:
    print("")
    print("You entered " + str(argnumbers) + " value/s.")
    print("")
    print("Usage: 'add2vals X Y' where X and Y are individual values.")
    print(
        "        If add2vals is not in your path, usage is './add2vals X Y' ")
    print("        If unbundled, usage is 'python add2vals.py X Y'.")
    print("")
    sys.exit(1)
示例#23
0
import sys
import calc

argnumbers = len(sys.argv) - 1

if argnumbers == 2:
    print("")
    print("Result is " + str(calc.add2(str(sys.argv[1]), str(sys.argv[2]))))
    print("")
    sys.exit(0)

if argnumbers != 2:
    print("")
    print("Your entry " + str(argnumbers) + " value/s.")
    print("")
    print(" 'add2vals X Y' where X and Y are individual values.")
    print("       If add2vals is not in your path, usage is './add2vals X Y'.")
    print("       If unbundled, usage is 'python add2vals.py X Y'.")
    print("")
    sys.exit(1)
示例#24
0
import calc as op

while (True):
    print "MENU \n1.Add\n2.Subtract\n3.Divivde\n4.Multiply\n5.Remainder\n6.Power\n7.Exit\n\nEnter your choice for calculation :",

    ch = input()
    if ch == 7:
        exit(0)

    a = input("Enter first input :")
    b = input("Enter second input :")
    if ch == 1:
        print "The sum is :", op.add2(a, b)
    elif ch == 2:
        print "The difference is :", op.sub2(a, b)
    elif ch == 3:
        print "The division result is :", op.div2(a, b)
    elif ch == 4:
        print "The product is :", op.mul2(a, b)
    elif ch == 5:
        print "The remainder is :", op.rem1(a, b)
    elif ch == 6:
        print "The result of a^b is :", op.pow(a, b)
    else:
        print "Invalid choice!!"

    print "\n\n"
示例#25
0
 def test_add_float_string(self):
     """
     Test that the addition of float and string returns float conatenate with string as string
     """
     result = calc.add2('123.45', 'six')
     self.assertEqual(result, '123.45six')
示例#26
0
 def test_add_floats(self):
     """
     Test that the addition of two floats returns the correct result
     """
     result = calc.add2('10.5', 2)
     self.assertEqual(result, 12.5)
示例#27
0
 def test_add_strings(self):
     result = calc.add2('abc', 'def')
     self.assertEqual(result, 'abcdef')
示例#28
0
 def test_add_string_and_integer(self):
     result = calc.add2('abc', 3)
     self.assertEqual(result, 'abc3')
示例#29
0
 def test_add_string_and_number(self):
     result = calc.add2('abc', '5.5')
     self.assertEqual(result, 'abc5.5')
示例#30
0
 def test_add_integers(self):
     """
     Test that the addition of two integers returns the correct total
     """
     result = calc.add2(1, 2)
     self.assertEqual(result, 3)
#!/usr/bin/python

import sys
import calc

#print(len(sys.argv))

argnum = len(sys.argv) - 1

if argnum == 2:
  print(calc.add2(sys.argv[1], sys.argv[2]))
  sys.exit(0)
else:
  print("add2val usage is ./add2val arg1 arg2 !!!")
  sys.exit(1)