11import org .junit .Ignore ;
22import org .junit .Test ;
33
4- import static org .junit .Assert .*;
4+ import java .util .List ;
5+
6+ import static org .junit .Assert .assertEquals ;
7+ import static org .junit .Assert .assertTrue ;
58
69public class DnDCharacterTest {
710
@@ -104,9 +107,54 @@ public void testAbilityModifierForScore18Is4() {
104107
105108 @ Ignore ("Remove to run test" )
106109 @ Test
107- public void testRandomAbilityIsWithinRange () {
108- int score = dndCharacter .ability ();
109- assertTrue (score > 2 && score < 19 );
110+ public void test4DiceWereUsedForRollingScores () {
111+ assertEquals (4 , dndCharacter .rollDice ().size ());
112+ }
113+
114+ @ Ignore ("Remove to run test" )
115+ @ Test
116+ public void testDiceValuesBetween1And6 () {
117+ assertTrue (dndCharacter .rollDice ().stream ().allMatch (d -> d >= 1 && d <= 6 ));
118+ }
119+
120+ @ Ignore ("Remove to run test" )
121+ @ Test
122+ public void testAbilityCalculationsUses3LargestNumbersFromScoresInDescendingOrder () {
123+ assertEquals (9 , dndCharacter .ability (List .of (4 , 3 , 2 , 1 )));
124+ }
125+
126+ @ Ignore ("Remove to run test" )
127+ @ Test
128+ public void testAbilityCalculationsUses3LargestNumbersFromFromScoresInAscendingOrder () {
129+ assertEquals (9 , dndCharacter .ability (List .of (1 , 2 , 3 , 4 )));
130+ }
131+
132+ @ Ignore ("Remove to run test" )
133+ @ Test
134+ public void testAbilityCalculationsUses3LargestNumbersFromScoresInRandomOrder () {
135+ assertEquals (9 , dndCharacter .ability (List .of (2 , 4 , 3 , 1 )));
136+ }
137+
138+ @ Ignore ("Remove to run test" )
139+ @ Test
140+ public void testAbilityCalculationsWithLowestEqualNumbers () {
141+ assertEquals (3 , dndCharacter .ability (List .of (1 , 1 , 1 , 1 )));
142+ }
143+
144+ @ Ignore ("Remove to run test" )
145+ @ Test
146+ public void testAbilityCalculationsWithHighestEqualNumbers () {
147+ assertEquals (18 , dndCharacter .ability (List .of (6 , 6 , 6 , 6 )));
148+ }
149+
150+ @ Ignore ("Remove to run test" )
151+ @ Test
152+ public void testAbilityCalculationDoesNotChangeInputScores () {
153+ List <Integer > scores = List .of (1 , 2 , 3 , 4 );
154+ dndCharacter .ability (scores );
155+
156+ assertEquals (4 , scores .size ());
157+ assertEquals (scores , List .of (1 , 2 , 3 , 4 ));
110158 }
111159
112160 @ Ignore ("Remove to run test" )
@@ -120,8 +168,7 @@ public void testRandomCharacterIsValid() {
120168 assertTrue (character .getIntelligence () > 2 && character .getIntelligence () < 19 );
121169 assertTrue (character .getWisdom () > 2 && character .getWisdom () < 19 );
122170 assertTrue (character .getCharisma () > 2 && character .getCharisma () < 19 );
123- assertEquals (character .getHitpoints (),
124- 10 + character .modifier (character .getConstitution ()));
171+ assertEquals (10 + character .modifier (character .getConstitution ()), character .getHitpoints ());
125172 }
126173 }
127174
@@ -131,4 +178,21 @@ public void testEachAbilityIsOnlyCalculatedOnce() {
131178 assertEquals (dndCharacter .getStrength (), dndCharacter .getStrength ());
132179 }
133180
181+ @ Ignore ("Remove to run test" )
182+ @ Test
183+ public void testUniqueCharacterIsCreated () {
184+ DnDCharacter uniqueDnDCharacter = new DnDCharacter ();
185+ for (int i = 0 ; i < 1000 ; i ++) {
186+ DnDCharacter dnDCharacter = new DnDCharacter ();
187+ boolean dnDCharactersHaveDifferentAttributes =
188+ dnDCharacter .getStrength () != uniqueDnDCharacter .getStrength ()
189+ || dnDCharacter .getDexterity () != uniqueDnDCharacter .getDexterity ()
190+ || dnDCharacter .getConstitution () != uniqueDnDCharacter .getConstitution ()
191+ || dnDCharacter .getIntelligence () != uniqueDnDCharacter .getIntelligence ()
192+ || dnDCharacter .getWisdom () != uniqueDnDCharacter .getWisdom ()
193+ || dnDCharacter .getCharisma () != uniqueDnDCharacter .getCharisma ()
194+ || dnDCharacter .getHitpoints () != uniqueDnDCharacter .getHitpoints ();
195+ assertTrue (dnDCharactersHaveDifferentAttributes );
196+ }
197+ }
134198}
0 commit comments