This project has retired. For details please refer to its Attic page.
TestBooleanAggregators 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.aggregators;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  
23  import org.apache.hadoop.io.BooleanWritable;
24  import org.junit.Test;
25  
26  public class TestBooleanAggregators {
27  
28    @Test
29    public void 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    }
41  
42    @Test
43    public void 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    }
55  
56    @Test
57    public void 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    }
68  
69  }