Introduction
For this week's task, you will practice using basic Erlang syntax by modifying an existing project. The goal is to make sure all the unit tests pass. As you work on these, make sure to read through all the code in the team_builder.erl file. That is where all your code will go. You should also read through the unit tests in the bottom portion of that file and try to understand how they work.
- There are four functions that you need to complete in the team_builder.erl file. These functions are add, divide, lower_divide, remainder, and difference.
- There are three unit tests at the end of the file that you'll need to fix. These unit tests will require you to insert some code in order for them to work correctly. Read the code and comments that are provided to help you figure out what you need to do.
Scenario: You work for a TV production company that is producing a game show. The Show is a program that has, as a major design component, competition between teams and cooperation within teams.
Your Task
Your boss needs help selecting good teams from persons that have been selected to be potential participants. He has assigned you to help with this effort.
-
Being new to Erlang, you decide to start by doing some experimentation so you can see what to expect from Erlang lists and expressions. You have written some unit tests in the team_builder.erl file in the game_show.zip file you got from your team. You figured these would help you see what happens in various situations. Write code to complete the functions and tests in the team_builder.erl file. Download the project you created, unzip it, and finish the needed lines of code.
You found a web page with a list of all of the possible assertions available.
Stretch Challenge (Optional)
Try experimenting with Erlang by putting the following in the REPL.
1234567890123456789.0 - 1234567890123456788.0.
Notice that the result is not 1.0.
Now put the following in the REPL.
1234567890123456789123456789.0 - 123456789012345678912356788.0.
Again, the result is not 1.0. See if you can figure out why this is so for both of these examples.
Suggestion: Take a look at Why are floating point numbers inaccurate?
Review
After completing the previous tasks:
- Review one of the many possible solutions for this task,
- Compare and contrast your code with the possible solutions’ code, and
- Make note of any improvements you could make for future tasks.
- Make note of what your approach does well.