Copyleft Games

Intro to Unit Testing

When writing complex code which is worked on by many people, its important to be able to test the individual pieces to ensure that they operate as they're intended. This is called unit testing. This exercise is intended to get you familiar with writing and expanding unit tests.

The primary test should always be a documented use-case to ensure the function runs at all. Additional tests are generally added for cases such as missing or empty arguments, negative numbers, 16-bit and 32-bit unicode characters, etc.

Using Python's unittest module, write a unit test suite for the following function to demonstrate at least 3 ways this Python 3 function needs improvement:

def add_angle(angle1: float, angle2: float) -> float:
    """ Add two angles together, returning 0 to 360 degrees """
    ret = angle1 + angle2
    if ret > 360:
        ret -= 360
    return ret

Submit a single .py file to your task when complete.

Task tags

  • unittest

Students who completed this task

juozapas, Václav Šraier, RoAdd, Carmen Popa, hirurana, Compeador, Awaykened

Task type

  • done_all Quality Assurance

Level

Beginner
close

2015