MsMasterpull
erge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
@@ -50,3 +50,4 @@
|
||||
- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
|
||||
- [Java Bitwise Operators](https://www.baeldung.com/java-bitwise-operators)
|
||||
- [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar)
|
||||
- [Making a JSON POST Request With HttpURLConnection](https://www.baeldung.com/httpurlconnection-post)
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.baeldung.inlining;
|
||||
|
||||
public class ConsecutiveNumbersSum {
|
||||
|
||||
private long totalSum;
|
||||
private int totalNumbers;
|
||||
|
||||
public ConsecutiveNumbersSum(int totalNumbers) {
|
||||
this.totalNumbers = totalNumbers;
|
||||
}
|
||||
|
||||
public long getTotalSum() {
|
||||
totalSum = 0;
|
||||
for (int i = 1; i <= totalNumbers; i++) {
|
||||
totalSum += i;
|
||||
}
|
||||
return totalSum;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.baeldung.inlining;
|
||||
|
||||
public class InliningExample {
|
||||
|
||||
public static final int NUMBERS_OF_ITERATIONS = 15000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int i = 1; i < NUMBERS_OF_ITERATIONS; i++) {
|
||||
calculateSum(i);
|
||||
}
|
||||
}
|
||||
|
||||
private static long calculateSum(int n) {
|
||||
return new ConsecutiveNumbersSum(n).getTotalSum();
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.baeldung.inlining;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ConsecutiveNumbersSumUnitTest {
|
||||
|
||||
private static final int TOTAL_NUMBERS = 10;
|
||||
|
||||
@Test
|
||||
public void givenTotalIntegersNumber_whenSumCalculated_thenEquals() {
|
||||
ConsecutiveNumbersSum consecutiveNumbersSum = new ConsecutiveNumbersSum(TOTAL_NUMBERS);
|
||||
long expectedSum = calculateExpectedSum(TOTAL_NUMBERS);
|
||||
|
||||
assertEquals(expectedSum, consecutiveNumbersSum.getTotalSum());
|
||||
}
|
||||
|
||||
private long calculateExpectedSum(int totalNumbers) {
|
||||
return totalNumbers * (totalNumbers + 1) / 2;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user