package com.levelup.java.array;

import static org.junit.Assert.assertEquals;

import org.apache.commons.math3.stat.StatUtils;
import org.junit.Test;

/**
 * This java example will demonstrate summing values in array.
 * 
 * @author Justin Musgrove
 * @see <a href='http://www.leveluplunch.com/java/examples/sum-values-in-array/'>Sum values in array</a>
 * 
 */
public class SumValuesInArray {

	double[] numbers = {1, 24, 45, 62, 85, 8, 91, 3, 5, 56, 9};
	
	@Test
	public void sum_values_in_array_with_java () {
	
		double total = 0;
		for (double element : numbers) {
			total += element;
		}
		assertEquals(389, total, 0);
	}

	//TODO
//	@Test
//	@Ignore
//	public void sum_values_in_array_with_java_8 () {
//		int total = IntStream.of(numbers).sum();
//		assertEquals(389, total);
//	}

	@Test
	public void sum_values_in_array_with_apache_commons () {
		
		double total = StatUtils.sum(numbers);
		assertEquals(389, total, 0);
	}
	
}

@@ -72,16 +72,80 @@
 quals;%0A%0A
+import java.util.Arrays;%0Aimport java.util.stream.DoubleStream;%0A%0A
 import o
@@ -692,37 +692,14 @@
 %7D%0A%0A%09
-//TODO%0A//%09@Test%0A//%09@Ignore%0A//
+@Test%0A
 %09pub
@@ -748,15 +748,19 @@
 ) %7B%0A
-//%09%09int
+%09%09%0A%09%09double
  tot
@@ -768,11 +768,14 @@
 l = 
-Int
+Double
 Stre
@@ -796,18 +796,19 @@
 .sum();%0A
-//
+%09%09%0A
 %09%09assert
@@ -828,13 +828,110 @@
 otal
+, 0);%0A%09%0A%09%09// or%0A%09%09%0A%09%09double total2 = Arrays.stream(numbers).sum();%0A%09%09%0A%09%09assertEquals(389, total2, 0
 );%0A
-//
 %09%7D%0A%0A

fix java 8 example