This project has retired. For details please refer to its Attic page.
TestRepeatBlock xref
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.Assert;
27  import org.junit.Test;
28  
29  import com.google.common.collect.Iterables;
30  
31  /**
32   * Tests repeatBlock's correctness
33   */
34  public class TestRepeatBlock {
35  
36    public static final int REPEAT_TIMES = 5;
37  
38    @Test
39    public void testRepeatBlockBasic() throws Exception {
40      Piece piece1 = new Piece();
41      Piece piece2 = new Piece();
42      Block innerBlock = new SequenceBlock(piece1, piece2);
43      Block repeatBlock = new RepeatBlock(
44              REPEAT_TIMES,
45              innerBlock
46      );
47      BlockTestingUtils.testIndependence(
48              Iterables.concat(Collections.nCopies(REPEAT_TIMES, Arrays.asList(piece1, piece2))),
49              repeatBlock);
50      Assert.assertEquals(REPEAT_TIMES * 2, repeatBlock.getPieceCount().getCount());
51    }
52  
53    @Test
54    public void testNestedRepeatBlock() throws Exception {
55      Piece piece1 = new Piece();
56      Piece piece2 = new Piece();
57      Block innerBlock = new SequenceBlock(piece1, piece2);
58      Block repeatBlock = new RepeatBlock(
59              REPEAT_TIMES,
60              innerBlock
61      );
62      BlockTestingUtils.testNestedRepeatBlock(
63              Iterables.concat(Collections.nCopies(REPEAT_TIMES, Arrays.asList(piece1, piece2))),
64              repeatBlock);
65    }
66  
67    @Test
68    public void testRepeatBlockEmpty() throws Exception {
69      Block innerBlock = new EmptyBlock();
70      Block repeatBlock = new RepeatBlock(
71              REPEAT_TIMES,
72              innerBlock
73      );
74      List<? extends AbstractPiece> referenceImpl = Collections.emptyList();
75      BlockTestingUtils.testIndependence(
76              // Concatenating EmptyIterator = just EmptyIterator. No obj's to
77              // compare against either
78              referenceImpl,
79              repeatBlock);
80    }
81  
82  }