|
| 1 | +package com.baeldung.array; |
| 2 | + |
| 3 | +import org.junit.Assert; |
| 4 | +import org.junit.Test; |
| 5 | + |
| 6 | +public class SumAndAverageInArrayTest { |
| 7 | + @Test |
| 8 | + public void givenAnIntArray_whenNotUsingStream_thenFindSum() { |
| 9 | + int[] array = { 1, 3, 4, 8, 19, 20 }; |
| 10 | + int expectedSumOfArray = 55; |
| 11 | + int actualSumOfArray = SumAndAverageInArray.findSumWithoutUsingStream(array); |
| 12 | + Assert.assertEquals(expectedSumOfArray, actualSumOfArray); |
| 13 | + } |
| 14 | + |
| 15 | + @Test |
| 16 | + public void givenAnIntArray_whenUsingStream_thenFindSum() { |
| 17 | + int[] array = { 1, 3, 4, 8, 19, 20 }; |
| 18 | + int expectedSumOfArray = 55; |
| 19 | + int actualSumOfArray = SumAndAverageInArray.findSumUsingStream(array); |
| 20 | + |
| 21 | + Assert.assertEquals(expectedSumOfArray, actualSumOfArray); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + public void givenAnIntArray_whenNotUsingStream_thenFindAverage() { |
| 26 | + int[] array = { 1, 3, 4, 8, 19, 20 }; |
| 27 | + double expectedAvgOfArray = 9.17; |
| 28 | + double actualAvgOfArray = SumAndAverageInArray.findAverageWithoutUsingStream(array); |
| 29 | + |
| 30 | + Assert.assertEquals(expectedAvgOfArray, actualAvgOfArray, 0.0034); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void givenAnIntArray_whenUsingStream_thenFindAverage() { |
| 35 | + int[] array = { 1, 3, 4, 8, 19, 20 }; |
| 36 | + double expectedAvgOfArray = 9.17; |
| 37 | + double actualAvgOfArray = SumAndAverageInArray.findAverageUsingStream(array); |
| 38 | + |
| 39 | + Assert.assertEquals(expectedAvgOfArray, actualAvgOfArray, 0.0034); |
| 40 | + } |
| 41 | +} |
0 commit comments