FAIL: LotteryNumbersTest testDrawNumbersCallRemovesOldNumbersAndDrawsNewNew numbers should have been drawn with drawNumbers call! Numbers were [2, 9, 19, 20, 25, 28, 38]
public class LotteryNumbers {private ArrayList<Integer> numbers;public LotteryNumbers() {this.numbers = new ArrayList<Integer>();this.drawNumbers();}public ArrayList<Integer> numbers() {return this.numbers;}public void drawNumbers() {Random randomiser = new Random();while (this.numbers.size() < 7) {int number = randomiser.nextInt(38) + 1;if (!containsNumber(number)) {this.numbers.add(number);}}Collections.sort(this.numbers);}public boolean containsNumber(int number) {int counter = 0;for (int value : this.numbers) {if (value == number) {counter++;}if (counter >= 1) {return true;}}return false;}}
--
http://mooc.fi
---
You received this message because you are subscribed to the Google Groups "mooc.fi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moocfi+un...@googlegroups.com.
To post to this group, send email to moo...@googlegroups.com.
Visit this group at http://groups.google.com/group/moocfi.
To view this discussion on the web visit https://groups.google.com/d/msgid/moocfi/4f133ba4-e619-4843-b061-5f2fdc38fb45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
LotteryNumbers lotteryNumbers = new LotteryNumbers();
System.out.println(lotteryNumbers.numbers()); // Print numbers
lotteryNumbers.drawNumbers();
System.out.println(lotteryNumbers.numbers()); // This shouldn't print same numbers