lundi 29 février 2016

Python how to write test driver?

import unittest
from test import support

class TestCase(unittest.TestCase):
    def addition():


x = [[3, 4],
     [5, 6]]

y = [[1, 2],
     [3, 4]]

output = [[0, 0],
          [0, 0]]

def addition(x, y):
for i in range(len(x)):
    for j in range(len(y[0])):
        output[i][j] += x[i][j] + y[i][j]

for o in output:
    print(o)

print("addition: ")
addition(x, y)

Hi, thanks for reading. I was trying to make a test driver for my matrix addition but I wonder if I was doing correctly. I added import unittest and from test import support at the top of the code. But do I have to make a new .py file in order to make test driver? How can I make a test driver for a matrix addition? I just started python a week ago. Please help!

Aucun commentaire:

Enregistrer un commentaire