View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.giraph.block_app.framework.block;
19  
20  import java.util.Arrays;
21  import java.util.Collections;
22  import java.util.List;
23  
24  import org.apache.giraph.block_app.framework.piece.AbstractPiece;
25  import org.apache.giraph.block_app.framework.piece.Piece;
26  import org.junit.Test;
27  
28  import com.google.common.collect.Iterables;
29  
30  /**
31   * Tests repeatBlock's correctness
32   */
33  public class TestRepeatBlock {
34  
35    public static final int REPEAT_TIMES = 5;
36  
37    @Test
38    public void testRepeatBlockBasic() throws Exception {
39      Piece piece1 = new Piece();
40      Piece piece2 = new Piece();
41      Block innerBlock = new SequenceBlock(piece1, piece2);
42      Block repeatBlock = new RepeatBlock(
43              REPEAT_TIMES,
44              innerBlock
45      );
46      BlockTestingUtils.testIndependence(
47              Iterables.concat(Collections.nCopies(REPEAT_TIMES, Arrays.asList(piece1, piece2))),
48              repeatBlock);
49    }
50  
51    @Test
52    public void testNestedRepeatBlock() throws Exception {
53      Piece piece1 = new Piece();
54      Piece piece2 = new Piece();
55      Block innerBlock = new SequenceBlock(piece1, piece2);
56      Block repeatBlock = new RepeatBlock(
57              REPEAT_TIMES,
58              innerBlock
59      );
60      BlockTestingUtils.testNestedRepeatBlock(
61              Iterables.concat(Collections.nCopies(REPEAT_TIMES, Arrays.asList(piece1, piece2))),
62              repeatBlock);
63    }
64  
65    @Test
66    public void testRepeatBlockEmpty() throws Exception {
67      Block innerBlock = new EmptyBlock();
68      Block repeatBlock = new RepeatBlock(
69              REPEAT_TIMES,
70              innerBlock
71      );
72      List<? extends AbstractPiece> referenceImpl = Collections.emptyList();
73      BlockTestingUtils.testIndependence(
74              // Concatenating EmptyIterator = just EmptyIterator. No obj's to
75              // compare against either
76              referenceImpl,
77              repeatBlock);
78    }
79  
80  }