This project has retired. For details please refer to its Attic page.
TestIntAggregators 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.IntWritable;
24  import org.junit.Test;
25  
26  public class TestIntAggregators {
27  
28    @Test
29    public void testMaxAggregator() {
30      IntMaxAggregator max = new IntMaxAggregator();
31      max.aggregate(new IntWritable(2));
32      max.aggregate(new IntWritable(3));
33      assertEquals(3, max.getAggregatedValue().get());
34      max.setAggregatedValue(new IntWritable(1));
35      assertEquals(1, max.getAggregatedValue().get());
36      IntWritable iw = max.createInitialValue();
37      assertNotNull(iw);
38    }
39  
40    @Test
41    public void testMinAggregator() {
42      IntMinAggregator min = new IntMinAggregator();
43      min.aggregate(new IntWritable(3));
44      min.aggregate(new IntWritable(2));
45      assertEquals(2, min.getAggregatedValue().get());
46      min.setAggregatedValue(new IntWritable(3));
47      assertEquals(3, min.getAggregatedValue().get());
48      IntWritable iw = min.createInitialValue();
49      assertNotNull(iw);
50    }
51  
52    @Test
53    public void testOverwriteAggregator() {
54      IntOverwriteAggregator overwrite = new IntOverwriteAggregator();
55      overwrite.aggregate(new IntWritable(1));
56      assertEquals(1, overwrite.getAggregatedValue().get());
57      overwrite.aggregate(new IntWritable(2));
58      assertEquals(2, overwrite.getAggregatedValue().get());
59      overwrite.setAggregatedValue(new IntWritable(3));
60      assertEquals(3, overwrite.getAggregatedValue().get());
61      IntWritable iw = overwrite.createInitialValue();
62      assertNotNull(iw);
63    }
64    
65    @Test
66    public void testProductAggregator() {
67      IntProductAggregator product = new IntProductAggregator();
68      product.aggregate(new IntWritable(6));
69      product.aggregate(new IntWritable(7));
70      assertEquals(42, product.getAggregatedValue().get());
71      product.setAggregatedValue(new IntWritable(1));
72      assertEquals(1, product.getAggregatedValue().get());
73      IntWritable iw = product.createInitialValue();
74      assertNotNull(iw);
75    }
76  
77    @Test
78    public void testSumAggregator() {
79      IntSumAggregator sum = new IntSumAggregator();
80      sum.aggregate(new IntWritable(1));
81      sum.aggregate(new IntWritable(2));
82      assertEquals(3, sum.getAggregatedValue().get());
83      sum.setAggregatedValue(new IntWritable(4));
84      assertEquals(4, sum.getAggregatedValue().get());
85      IntWritable iw = sum.createInitialValue();
86      assertNotNull(iw);
87    }
88  
89  }