1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */18package org.apache.giraph.block_app.framework.block;
1920import java.util.Arrays;
21import java.util.Collections;
22import java.util.List;
2324import org.apache.giraph.block_app.framework.piece.AbstractPiece;
25import org.apache.giraph.block_app.framework.piece.Piece;
26import org.junit.Assert;
27import org.junit.Test;
2829import com.google.common.collect.Iterables;
3031/**32 * Tests repeatBlock's correctness33 */34publicclassTestRepeatBlock {
3536publicstaticfinalint REPEAT_TIMES = 5;
3738 @Test
39publicvoid 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 }
5253 @Test
54publicvoid 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 }
6667 @Test
68publicvoid 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 to77// compare against either78 referenceImpl,
79 repeatBlock);
80 }
8182 }