Exercise 1
info
This is an in-class exercise. An exercise page like this one will contain a brief description but is intended to be supplemented by discussion during our meeting time. Complete the exercise to the best of your ability in the time given. Feel free to talk with other students as you work, and do not be afraid to ask questions. Aim to complete as much as possible during our meeting, but you need not hand it in.
#
Learning ObjectivesObjectives
This exercise should help you:
- warm up with creating a java project using Intellij
- make use of JUnit to write test cases
- understand the difference between Fault, Error and Failure
#
Getting set up- Using
git
, clone the course public repo to get a copy of the files you will be working with in this exercise. To do so, you can type at a terminal (when you are in your desired folder location):
tip
You need to have git
installed on your machine already. If you do not have git
, you can download it from here. You can follow the instructions here. If you need to brush up on your git skills, this video could be a good starting point.
info
Once you succesffuly clone the repo, you can find ex1 files under exercises/ex1
under which there is ArrayUtils.Java
.
Create a new Java Gradle project on
Intellij
and addJUint5
.- if you do not have
Intellij
installed, you may download the Ultimate version here for free. - Go to
File
->New
->Project
and selectGradle
. Follow the steps to finish creating the project. - Go to
build.gradle
and make sure it has the following content (in particulartest
anddependencies
):
- if you do not have
Copy
ArrayUtils.java
tosrc/main/java
path in your project.
Alternate IDE
Feel free to use an alternate IDE other than Intellij
if you prefer. The instructions in this exercise are based on Intellij
though.
#
Task- Follow the instructions at the top of
ArrayUtils.java
and write your asnwers on a paper or a word document. Implement your test cases as JUnit test cases in your project.
tip
In order to write JUnit tests, you would want to create a test class under src/test/java
in your project and write your test cases in that class. Follow the skeletal/naming convention offered in the lecture notes.
Program State
A program state during program execution is defined as the current value of all live variables and the current location as given by program counter (PC). PC is the next statement to be executed in the program. Each time a new statement (instruction) is fetched to be executed, PC is incremented.
tip
Recall that "error" is incorrect program state.
- Execute JUnit test cases you wrote and verify the results.
tip
We will study JUnit in more details in near future, but for now you can brush up on your JUnit skills by referring to its user manual.