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.IntWritable;
24import org.junit.Test;
2526publicclassTestIntAggregators {
2728 @Test
29publicvoid 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 }
3940 @Test
41publicvoid 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 }
5152 @Test
53publicvoid 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 }
6465 @Test
66publicvoid 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 }
7677 @Test
78publicvoid 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 }
8889 }