samedi 25 mai 2019

Can I emulate input for my function inside the Test Case?

I am currently trying to make a Test Case for my program, but I am facing a difficulty. The way, I structured my code there is a function that takes the input, and according to that input it builds up a graph, and then there is a function that calculates something about the graph. I am also required to have this type of input for the job I am applying to. ( I can't do a simple unit test with a graph as an input).

The test file so far looks like this:

import unittest
from main_file import calculate, create_grid

class TestCase1(unittest.TestCase):

        def test1(self):

            data = create_grid()
            self.assertEqual(2, calculate(data))

The way it works right now, I input the needed data by myself with create_grid(). Is there a way I can emulate the computer/program to do it by itself (with specific values, as this is what I want). Thank you very much!

Aucun commentaire:

Enregistrer un commentaire