コード例 #1
0
def test_divide_integer_with_zero():
    """Test divide function in mymath with one non zero integer inputs."""
    with pytest.raises(ZeroDivisionError):
        divide(2, 0)
コード例 #2
0
 def test_divide_by_zero(self):
     """
     Test that multiplying integers returns the correct result
     """
     with self.assertRaises(ZeroDivisionError):
         result = mymath.divide(8, 0)
コード例 #3
0
x = int(input("Enter 1st number: "))
y = int(input("Enter 2nd number: "))
print()

# Call the add function
resAdd = mymath.add(x, y)
print("Sum =", resAdd)

#Call the subtract function
resSub = mymath.subtract(x, y)
print("Difference =", resSub)

#Call the multiply function
resMul = mymath.multiply(x, y)
print("Product =", resMul)

#Call the divide function
resDiv = mymath.divide(x, y)
print("Division =", resDiv)
print()

#Call the isPrime function
resPri = mymath.isPrime(x)
if resPri == True:
    print(x, "is Prime")
else:
    print(x, "is not Prime")

#Call the factorial function
resFac = mymath.factorial(y)
print(y, "Factorial =", resFac)
コード例 #4
0
def test_divide_integers_even():
    """Test divide function in mymath with two non zero integer inputs."""
    assert divide(2, 10) == 0.2
コード例 #5
0
def test_divide_integers_repetant():
    nose.tools.assert_almost_equal(divide(1, 3), 0.33333333, 7)
コード例 #6
0
 def test_divide_by_zero(self):
     """
     Test that multiplying integers returns the correct result
     """
     with self.assertRaises(ZeroDivisionError):
         result = mymath.divide(8, 0)
コード例 #7
0
def test_divide_integers_even():
    assert divide(2, 10) == 0.2
コード例 #8
0
 def test_divide_by_zero(self):
     with self.assertRaises(ZeroDivisionError):
         result = mymath.divide(8, 0)
         self.assertEqual(result, ZeroDivisionError)
コード例 #9
0
 def test_divide_float(self):
     result = mymath.divide(10, 5)
     self.assertEqual(result, 2)
コード例 #10
0
import mymath

if __name__ == "__main__":
    assert mymath.add(1, 2) == 3
    assert mymath.subtract(2, 1) == 1
    assert mymath.multiply(2, 3) == 6
    assert mymath.divide(4, 2) == 2
コード例 #11
0
import mymath

print mymath.divide(10, 5)

try:
    print mymath.divide(3, 0)
except Exception as e:
    print type(e), e

try:
    print mymath.divide(3.2, 2)
except Exception as e:
    print type(e), e

try:
    print mymath.divide(0, 0)
except Exception as e:
    print type(e), e