Test Driven Design with Enumerated Types
An Enumerated Type is a specialized class in Java that allows you to create a set of predefined constants. Common examples include compass directions (e.g., NORTH, SOUTH, EAST, and WEST) or the days of the week. A variable can only be equal to one of the predefined values and no other instances can be created dynamically, but it provides better security against errors that may occur if you simply used Strings or Integers to denote a fixed set of values.
Getting Started
For this lab exercise, it is suggested that you work together with one other person in the class:
- One person should fork the original lab_poker repository into your own account to provide a place to edit, commit, and push changes
- On the resulting project web page, go to
Settings -> Membersto add your partner so both people in the group can access the same repository - Search for your partner's name and give them a
Maintainerrole in the project and chooseAdd to Project - Both students should clone the one forked repository to their individual machines so they can work on their own separate copies
- Import the project into IntelliJ (
New -> Project From Existing Sources)using the folder you just created (and just accept the defaults for all the options by selectingNext)
- Once the project window appears, you will need to do a few more steps to get it to run:
- Select
File -> Project Structureand then selectLibrarieswithin the dialog that appears - Right click on the
junitlibrary and selectAdd to Modules - Click
OKin the dialog that appears andOKagain to close the Project Settings dialog - Click to expand the folders
src -> pokerto find the Java classHandTest - Right click on this class to run it by selecting "Run HandTest"
- Select
- Run the program to verify that your Java installation is working.
If there are compilation errors or it does not run, then the project is not correctly configured.
Enumerated Types
Add a test to the HandTest class that creates a Hand that includes a Joker card and another example Hand, then compare the two hands and expect that the hand with a Joker has the higher value.
However, the Joker card does not technically have a Suit or Color. So to make this test pass, add NONE values to both the Color and Suit Enumerated Type classes. The NONE Suit should be created with a NONE Color and a "*" symbol.
Once you think you have this part working, use GIT to add and commit the changes you have made.
Test Driven Design
Complete last week's lab exercise with these given classes as a starting point.
As before, use the TDD process and verify you are doing so by committing each test first before the code that implements that test.
Submission
At the end of class, use Gitlab's Merge Request to submit your code to the original organization repository (note, there is no discussion file for this lab). Make sure your NetID is in the title of your Merge Request and in comments within the main class.