Skip to content

Lots of functions need unitary tests #29

Open
@rjodon

Description

@rjodon

I think lots of functions are not so obvious to understand and could easily lead to bugs.
Writing unitary test for them within unittest framework would be a great idea for:

  • be sure that the code is bulletproof.
  • make refactoring and maintenance much easier
  • help to understand what the code does.

Example with this:

class Steel(SteelBase):

    def __init__(self, name, fy, fu, eu, E, v, p):
        super(Steel, self).__init__(name, fy, fu, eu, E, v, p)
        self.data = self._generate_data()

    def _generate_data(self):
        data_section = []
        line = """*Material, name={}
*Density
{},
*Elastic
{}, {}
*Plastic""".format(self.name, self.p, self.E['E'], self.v['v'])
        data_section.append(line)

        for i, j in zip(self.compression['f'], self.compression['e']):
            line = """{}, {}""".format(abs(i), abs(j))
            data_section.append(line)
        return '\n'.join(data_section)

If you take a month of holiday and I am in charge of the maintenance without knowing Abaqus, your part of the code, a small test case for this function will give me all the cards in my hand for fixing a bug. I will know exactly what is inside each variable and what to expect from the function.

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions