package com.translationdata.p010;
/** Strategy: Sieve of SieveOfEratosthenes. */
import static org.junit.Assert.assertEquals;

import java.util.stream.LongStream;

import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import JUnitTests.FastTest;
import misc.SieveOfEratosthenes;
public class P010_SummationOfPrimes {
	static int testNo = 1;
	
	public long primesSum(final int upperLimit) {
		final SieveOfEratosthenes primeSieve = new SieveOfEratosthenes( upperLimit );
		final long primeSum = LongStream.range(2, upperLimit)
			.filter(candidate -> primeSieve.isPrime((int) candidate))
			.sum();
		return primeSum;
	}

	@Before
	public void before() {
		System.out.printf("Running unit test...%d%n", testNo);
		testNo += 1;
	}
	
	@Test(timeout = 1_000)
	@Category(FastTest.class)
	public void TwoMillionPrimes() {
		final int upperLimit = 2_000_000;
		long primeSum = primesSum(upperLimit);
		assertEquals( "Incorrect sum", 142913828922L, primeSum );
		System.out.printf("Result(%d) = %d, %n", upperLimit, primeSum);
	}
}

@@ -120,16 +120,94 @@
 quals;%0A%0A
+import java.util.function.LongPredicate;%0Aimport java.util.function.Predicate;%0A
 import j
@@ -234,16 +234,16 @@
 Stream;%0A
-
 %0Aimport 
@@ -587,16 +587,125 @@
 imit );%0A
+%09%09//Predicate%3CLong%3E isPrime =  candidate -%3E primeSieve.isPrime( Integer.parseInt(candidate.toString()) );%0A%09%09%0A
 %09%09final 
@@ -846,17 +846,18 @@
 Sum;%0A%09%7D%0A
+%09
 %0A
-
 %09@Before
@@ -1124,68 +1124,8 @@
 t);%0A
-%09%09assertEquals( %22Incorrect sum%22, 142913828922L, primeSum );%0A
 %09%09Sy
@@ -1186,13 +1186,73 @@
 meSum);%0A
+%09%09assertEquals( %22Incorrect sum%22, 142913828922L, primeSum );%0A
 %09%7D%0A%7D%0A

Add Predicate