Skip to content

Write a test that checks if a triangle is a triangle #1

@andershedberg

Description

@andershedberg

A triangle angles sums up to 180 degrees.

For Test Driven Development we need to start with a test, and the test should fail before we write the real code.

In Python we can create a test like this:

def test_sum_angles():
    if classification(60,60,60) == false : 
         print(" sum_angles FAILED ") 

The code that fails look like this:

def classification (a,b,c):
    return false

Write the above in your own language of choice and see that the test indeed prints out FAILED.

Now add the minimal amount of code that makes the test pass.

def classification(a,b,c):
    if a+b+c == 180:
        print("This IS a triangle")
        return true
   return false

Run the code and see that the test passes. We now have a working test to check if we have a triangle.

Extra - For Test Driven Development, clean up the code ( refactor it ) and re-run all tests to check that nothing broke in the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions