GithubHelp home page GithubHelp logo

se-q3-test-katas's Introduction

Test These Katas

The katas.py file includes our solution to the prior activity Functions and Loops.

Unfortunately, while we had good intentions and wrote a test harness, we didn't actually write any unit tests!

Testing with Unittest

By now, you should be familiar with how unit tests generally work in python. Unit tests are collected in their own separate folder, and should never be mixed in with actual production code. Up until now, you have written the code and the tests have been written for you. If you have ever peeked inside the tests folder, the test modules usually say "Students should not modify these tests". For this assignment the flow is reversed: We give you the code, and YOU write the tests! It is perfectly fine to go back to previous projects to get an idea of what a unittest module looks like, so you can get some ideas on how to structure this one.

There is a handy command-line utility out there called rerun (pip install rerun), which can help when running tests.

```console
% rerun "python -m unittest discover tests"
```

This will watch your project directory for any file changes, and run the tests automatically each time you make a file change. You should see something like the following:

failing output

Then, open up tests/test_katas.py and start fixing those TODOs!

Once complete, you should see the following test output:

passing output

Of course, you can also run and debug these same tests using the Test Explorer extension built in to the VSCode editor, by enabling automatic test discovery. This is a really useful tool and we highly recommend to learn it.

https://code.visualstudio.com/docs/python/testing#_test-discovery

  • Test framework is unittest
  • Test folder pattern is tests
  • Test name pattern is test*

Writing the Tests

Each test you write should have at least one assert or self.assertXXXXX where it checks an actual return value against an expected value.

  • add: Generate some random integers or floats using the random library. Does the add function in katas.py add the numbers together correctly? Does the function handle negative values correctly?
  • multiply: Write tests similar to the add function tests.
  • power: Does the function handle positive integers correctly? The function should raise a ValueError exception if you provide a negative or fractional exponent value. How can you test if a function raises an exception? (Hint: explore the assertion methods available in Unittest.TestCase parent class)
  • factorial: Set up a list of the first 15 terms of the factorial series as literal integer values. Make sure the function returns the correct values when iterating through values of n. Does the function raise a ValueError if you give it negative values?
  • fibonacci: Test if the function can produce the first 30 terms of the fibonacci sequence. Make sure that it raise a ValueError exception when given a negative number.

Submitting your work

This excercise may be provided as a graded assignment, or an ungraded Activity. To submit your solution for grading, you will need to create a github Pull Request (PR). Refer to the PR Workflow article in your course content for details.

se-q3-test-katas's People

Contributors

daniellomelino avatar ericmhanson avatar madarp avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.