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.LongWritable;
24import org.junit.Test;
2526publicclassTestLongAggregators {
2728 @Test
29publicvoid testMaxAggregator() {
30 LongMaxAggregator max = new LongMaxAggregator();
31 max.aggregate(new LongWritable(2L));
32 max.aggregate(new LongWritable(3L));
33 assertEquals(3L, max.getAggregatedValue().get());
34 max.setAggregatedValue(new LongWritable(1L));
35 assertEquals(1L, max.getAggregatedValue().get());
36 LongWritable lw = max.createInitialValue();
37 assertNotNull(lw);
38 }
3940 @Test
41publicvoid testMinAggregator() {
42 LongMinAggregator min = new LongMinAggregator();
43 min.aggregate(new LongWritable(3L));
44 min.aggregate(new LongWritable(2L));
45 assertEquals(2L, min.getAggregatedValue().get());
46 min.setAggregatedValue(new LongWritable(3L));
47 assertEquals(3L, min.getAggregatedValue().get());
48 LongWritable lw = min.createInitialValue();
49 assertNotNull(lw);
50 }
5152 @Test
53publicvoid testOverwriteAggregator() {
54 LongOverwriteAggregator overwrite = new LongOverwriteAggregator();
55 overwrite.aggregate(new LongWritable(1L));
56 assertEquals(1L, overwrite.getAggregatedValue().get());
57 overwrite.aggregate(new LongWritable(2L));
58 assertEquals(2L, overwrite.getAggregatedValue().get());
59 overwrite.setAggregatedValue(new LongWritable(3L));
60 assertEquals(3L, overwrite.getAggregatedValue().get());
61 LongWritable lw = overwrite.createInitialValue();
62 assertNotNull(lw);
63 }
6465 @Test
66publicvoid testProductAggregator() {
67 LongProductAggregator product = new LongProductAggregator();
68 product.aggregate(new LongWritable(6L));
69 product.aggregate(new LongWritable(7L));
70 assertEquals(42L, product.getAggregatedValue().get());
71 product.setAggregatedValue(new LongWritable(1L));
72 assertEquals(1L, product.getAggregatedValue().get());
73 LongWritable lw = product.createInitialValue();
74 assertNotNull(lw);
75 }
7677 @Test
78publicvoid testSumAggregator() {
79 LongSumAggregator sum = new LongSumAggregator();
80 sum.aggregate(new LongWritable(1L));
81 sum.aggregate(new LongWritable(2L));
82 assertEquals(3L, sum.getAggregatedValue().get());
83 sum.setAggregatedValue(new LongWritable(4L));
84 assertEquals(4L, sum.getAggregatedValue().get());
85 LongWritable lw = sum.createInitialValue();
86 assertNotNull(lw);
87 }
8889 }