public class Domino extends java.lang.Object implements DominoSpecification
DominoMVC
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_LEFT_VALUE
The value for the left side of the domino constructed by default
|
static int |
DEFAULT_RIGHT_VALUE
The value for the right side of the domino constructed by default
|
INVARIANT, MAX, MIN, NUMBER_OF_DOMINOES_POSSIBLE, RANGE_OF_VALUES
Constructor and Description |
---|
Domino()
The default constructor for the domino, sets both side values to MIN
Tested by JUnit_Domino.test_DefaultConstructor() |
Domino(DominoSpecification domino_to_copy)
A copy constructor - makes a new domino object which is a copy of the given domino
Tested by
JUnit_Domino.test_CopyConstructorOK() and JUnit_Domino.test_CopyConstructorKO() |
Domino(int l,
int r)
Construct a domino from the given left and right values
Tested by JUnit_Domino.test_Constructor() and
JUnit_Domino.test_ConstructorException() |
Domino(java.util.Random rng)
Construct a valid random domino.
Tested by JUnit_Domino.test_RandomConstructor() . |
Modifier and Type | Method and Description |
---|---|
DominoSpecification |
copy()
Constructs a new domino using a copy of the left and right values of
this Tested by JUnit_DominoSpecification.test_copy() |
int |
getLeftValue()
Getter function of the left value.
Tested by JUnit_DominoSpecification.test_getLeft() |
int |
getRightValue()
Getter function of the right value.
Tested by JUnit_DominoSpecification.test_getRight() |
int |
hashCode()
We simply calculate the hash as (3+l)*(3+r), for left and right values l and r.
|
boolean |
invariant()
Should check that the left and right values are in allowed range
DominoSpecification.MIN .. |
void |
randomize()
update the state of the object in a random (safe) manner.
|
void |
randomize(java.util.Random rng)
update the state of the object in a random (safe) manner
|
void |
switchSides()
Swap the left and right values - to model flipping/switching the domino around.
|
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
equals, toString
public static final int DEFAULT_LEFT_VALUE
public static final int DEFAULT_RIGHT_VALUE
public Domino()
JUnit_Domino.test_DefaultConstructor()
public Domino(DominoSpecification domino_to_copy) throws java.lang.IllegalArgumentException
JUnit_Domino.test_CopyConstructorOK()
and JUnit_Domino.test_CopyConstructorKO()
domino_to_copy
- is the domino whose values are to be copied in the new objectjava.lang.IllegalArgumentException
- if the domino to copy is null or the domino to copy is not validpublic Domino(int l, int r) throws java.lang.IllegalArgumentException, InvariantBrokenException
JUnit_Domino.test_Constructor()
and
JUnit_Domino.test_ConstructorException()
l
- for Left valuer
- for Right valuejava.lang.IllegalArgumentException
- when l or r are out of bounds DominoSpecification.MIN
.. DominoSpecification.MAX
InvariantBrokenException
- if the domino state is not valid after executionpublic Domino(java.util.Random rng) throws InvariantBrokenException
JUnit_Domino.test_RandomConstructor()
.rng
- the random number generator used to randomly set the domino values, if this is null then we construct itInvariantBrokenException
- if the domino state is not valid after executionpublic void randomize() throws InvariantBrokenException
Randomizable
randomize
in interface Randomizable
InvariantBrokenException
- if the domino state is not valid after execution (this should not happen)public void randomize(java.util.Random rng) throws InvariantBrokenException
Randomizable
randomize
in interface Randomizable
rng
- the random number generator used to randomly set the domino values, if this is null then we construct itInvariantBrokenException
- if the domino state is not valid after execution (this should not happen)public boolean invariant()
DominoSpecification
DominoSpecification.MIN
.. DominoSpecification.MAX
invariant
in interface DominoSpecification
invariant
in interface HasInvariant
public DominoSpecification copy()
DominoSpecification
this
JUnit_DominoSpecification.test_copy()
copy
in interface DominoSpecification
this
public void switchSides() throws InvariantBrokenException
DominoSpecification
JUnit_DominoSpecification.test_switchSides()
switchSides
in interface DominoSpecification
InvariantBrokenException
- if the state change produces an invalid dominopublic int getRightValue()
DominoSpecification
JUnit_DominoSpecification.test_getRight()
getRightValue
in interface DominoSpecification
public int getLeftValue()
DominoSpecification
JUnit_DominoSpecification.test_getLeft()
getLeftValue
in interface DominoSpecification
public int hashCode()
Object.equals(java.lang.Object)
method that allows us to flip/switch the sides and maintain equalityhashCode
in interface DominoSpecification
hashCode
in class java.lang.Object
DominoSpecification.equals(java.lang.Object)
methodDominoSpecification.equals(java.lang.Object)