Skip to content

Commit e9b7124

Browse files
committed
fixed magic numbers
1 parent a820c28 commit e9b7124

File tree

6 files changed

+30
-14
lines changed

6 files changed

+30
-14
lines changed

app/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ dependencies {
2424

2525
tasks.test {
2626
useJUnitPlatform()
27-
finalizedBy("jacocoTestReport") // Ссылаемся на задачу по имени, чтобы она выполнялась после тестов
27+
finalizedBy("jacocoTestReport")
2828
}
2929

3030
tasks.named<JacocoReport>("jacocoTestReport") {
31-
dependsOn(tasks.test) // Задаем зависимость от задачи тестирования
31+
dependsOn(tasks.test)
3232
reports {
33-
xml.required.set(true) // Генерация XML отчета
34-
html.required.set(true) // Генерация HTML отчета
33+
xml.required.set(true)
34+
html.required.set(true)
3535
}
3636
}
3737

app/src/main/java/hexlet/code/games/Calc.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
public class Calc {
1111
public static int calc() {
1212

13+
final int maxRandomNumber1 = 19;
14+
final int maxRandomNumber2 = 9;
15+
1316
Random random = new Random();
1417
String mainGameQuestion = "What is the result of the expression?";
1518

1619
String[] question = new String[Engine.ROUNDS];
1720
String[] correctAnswer = new String[Engine.ROUNDS];
1821

1922
for (var i = 0; i < Engine.ROUNDS; i++) {
20-
int randomNumber1 = random.nextInt(19) + 1;
21-
int randomNumber2 = random.nextInt(9) + 1;
23+
int randomNumber1 = random.nextInt(maxRandomNumber1) + 1;
24+
int randomNumber2 = random.nextInt(maxRandomNumber2) + 1;
2225

2326
String plus = randomNumber1 + " + " + randomNumber2;
2427
String minus = randomNumber1 + " - " + randomNumber2;

app/src/main/java/hexlet/code/games/Even.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
public class Even {
88
public static int even() {
99

10+
final int maxRandomNumber = 5;
11+
1012
Random random = new Random();
1113
String mainGameQuestion = "Answer 'yes' if the number is even, otherwise answer 'no'.";
1214

1315
String[] question = new String[Engine.ROUNDS];
1416
String[] correctAnswer = new String[Engine.ROUNDS];
1517

1618
for (var i = 0; i < Engine.ROUNDS; i++) {
17-
int randomNumber = random.nextInt(99) + 1;
19+
int randomNumber = random.nextInt(maxRandomNumber) + 1;
1820
question[i] = Integer.toString(randomNumber);
1921
correctAnswer[i] = (randomNumber % 2 == 0) ? "yes" : "no";
2022
}

app/src/main/java/hexlet/code/games/Gcd.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
public class Gcd {
1010
public static int gcd() {
11+
12+
final int maxrandomCommon = 10;
13+
final int maxRandomNumber = 10;
14+
1115
Random random = new Random();
1216
String mainGameQuestion = "Find the greatest common divisor of given numbers.";
1317

@@ -16,9 +20,9 @@ public static int gcd() {
1620

1721
for (var i = 0; i < Engine.ROUNDS; i++) {
1822

19-
int randomCommon = random.nextInt(10) + 2;
20-
int randomNumber1 = randomCommon * (random.nextInt(10) + 1);
21-
int randomNumber2 = randomCommon * (random.nextInt(10) + 1);
23+
int randomCommon = random.nextInt(maxrandomCommon) + 2;
24+
int randomNumber1 = randomCommon * (random.nextInt(maxRandomNumber) + 1);
25+
int randomNumber2 = randomCommon * (random.nextInt(maxRandomNumber) + 1);
2226

2327
BigInteger bigA = BigInteger.valueOf(randomNumber1);
2428
BigInteger bigB = BigInteger.valueOf(randomNumber2);

app/src/main/java/hexlet/code/games/Prime.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
public class Prime {
88
public static int prime() {
99

10+
final int maxRandomNumber = 20;
11+
1012
Random random = new Random();
1113
String mainGameQuestion = "Answer 'yes' if given number is prime. Otherwise answer 'no'.";
1214

1315
String[] question = new String[Engine.ROUNDS];
1416
String[] correctAnswer = new String[Engine.ROUNDS];
1517

1618
for (var i = 0; i < Engine.ROUNDS; i++) {
17-
int randomNumber = random.nextInt(20) + 2;
19+
int randomNumber = random.nextInt(maxRandomNumber) + 2;
1820
question[i] = Integer.toString(randomNumber);
1921

2022
boolean isPrime = true;

app/src/main/java/hexlet/code/games/Progression.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
public class Progression {
99
public static int progression() {
10+
11+
final int minArrayLength = 5;
12+
final int maxStep = 9;
13+
final int maxStartValue = 14;
14+
1015
Random random = new Random();
1116
String mainGameQuestion = "What number is missing in the progression?";
1217

@@ -15,11 +20,11 @@ public static int progression() {
1520

1621
for (var i = 0; i < Engine.ROUNDS; i++) {
1722

18-
int arrayLength = random.nextInt(5) + 5;
23+
int arrayLength = random.nextInt(minArrayLength) + minArrayLength;
1924
int[] array = new int[arrayLength];
2025

21-
int step = random.nextInt(9) + 1;
22-
int start = random.nextInt(14) + 1;
26+
int step = random.nextInt(maxStep) + 1;
27+
int start = random.nextInt(maxStartValue) + 1;
2328

2429
for (int j = 0; j < arrayLength; j++) {
2530
array[j] = start + j * step;

0 commit comments

Comments
 (0)