MathIterators { static InfiniteIterator<Integer> hamming(Integer... primes) { return new Hamming(primes); } private  MathIterators(); static Comparator<Double> weakDoubleComparator(double epsilon); static UnaryOperator<Double> increment(Double delta); static UnaryOperator<Double> times(Double factor); static InfiniteIterator<Double> random(); static InfiniteIterator<Double> arithmeticSeries(double start, double delta); static InfiniteIterator<Double> geometricSeries(double start, double factor); static ImmutableIterator<Double> exp(); static ImmutableIterator<Double> sin(); static ImmutableIterator<Double> cos(); static ImmutableIterator<Double> add(Iterator<Double> s, double inc); @SuppressWarnings("unchecked") static Iterator<Double> inc(Iterator<Double> s, double inc); static ImmutableIterator<Double> add(Iterator<Double> s, Iterator<Double> t); static ImmutableIterator<Double> multiply(Iterator<Double> s, double factor); static ImmutableIterator<Double> multiply(Iterator<Double> s, Iterator<Double> t); static ImmutableIterator<Double> square(Iterator<Double> t); static InfiniteIterator<Double> inverse(Iterator<Double> t); static ImmutableIterator<Double> divide(Iterator<Double> s, Iterator<Double> t); static UnaryOperator<Double> polynom(Iterator<Double> t, int dim); static UnaryOperator<Double> polynom(Iterator<Double> t); static Iterator<Double> compose(Iterator<Double> t, Iterator<Double> s, int dim); static Iterator<Double> compose(Iterator<Double> t, Iterator<Double> s);  }
@Test public void testHamming() { Iterator<Integer> r; int sum; try { hamming(); } catch (IllegalArgumentException ignored) { } Iterator<Integer> h = hamming(2); BinaryOperator<Integer> acc = (a, b) -> a + b; sum = reduce(limit(h, 10), acc); assertEquals(1023, sum); Iterator<Integer> k = hamming(2, 5); sum = reduce(limit(k, 10), acc); assertEquals(123, sum); h = hamming(2); k = hamming(2, 5); List<Iterator<Integer>> m = asList(h, k); r = merge(m, true); sum = reduce(limit(r, 10), acc); assertEquals(45, sum); h = hamming(2); k = hamming(2, 5); r = merge(asList(h, k), true); sum = reduce(limit(r, 10), acc); assertEquals(45, sum); }