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.aggregators;
1920importstatic org.junit.Assert.assertEquals;
21importstatic org.junit.Assert.assertNotNull;
2223import org.apache.hadoop.io.BooleanWritable;
24import org.junit.Test;
2526publicclassTestBooleanAggregators {
2728 @Test
29publicvoid testAndAggregator() {
30 BooleanAndAggregator and = new BooleanAndAggregator();
31 assertEquals(true, and.getAggregatedValue().get());
32 and.aggregate(new BooleanWritable(true));
33 assertEquals(true, and.getAggregatedValue().get());
34 and.aggregate(new BooleanWritable(false));
35 assertEquals(false, and.getAggregatedValue().get());
36 and.setAggregatedValue(new BooleanWritable(true));
37 assertEquals(true, and.getAggregatedValue().get());
38 BooleanWritable bw = and.createInitialValue();
39 assertNotNull(bw);
40 }
4142 @Test
43publicvoid testOrAggregator() {
44 BooleanOrAggregator or = new BooleanOrAggregator();
45 assertEquals(false, or.getAggregatedValue().get());
46 or.aggregate(new BooleanWritable(false));
47 assertEquals(false, or.getAggregatedValue().get());
48 or.aggregate(new BooleanWritable(true));
49 assertEquals(true, or.getAggregatedValue().get());
50 or.setAggregatedValue(new BooleanWritable(false));
51 assertEquals(false, or.getAggregatedValue().get());
52 BooleanWritable bw = or.createInitialValue();
53 assertNotNull(bw);
54 }
5556 @Test
57publicvoid testOverwriteAggregator() {
58 BooleanOverwriteAggregator overwrite = new BooleanOverwriteAggregator();
59 overwrite.aggregate(new BooleanWritable(true));
60 assertEquals(true, overwrite.getAggregatedValue().get());
61 overwrite.aggregate(new BooleanWritable(false));
62 assertEquals(false, overwrite.getAggregatedValue().get());
63 overwrite.setAggregatedValue(new BooleanWritable(true));
64 assertEquals(true, overwrite.getAggregatedValue().get());
65 BooleanWritable bw = overwrite.createInitialValue();
66 assertNotNull(bw);
67 }
6869 }