This project has retired. For details please refer to its Attic page.
TestFloatAggregators 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.0f (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.0f
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.FloatWritable;
24  import org.junit.Test;
25  
26  public class TestFloatAggregators {
27  
28    @Test
29    public void testMaxAggregator() {
30      FloatMaxAggregator max = new FloatMaxAggregator();
31      max.aggregate(new FloatWritable(2.0f));
32      max.aggregate(new FloatWritable(3.0f));
33      assertEquals(3.0f, max.getAggregatedValue().get(), 0f);
34      max.setAggregatedValue(new FloatWritable(1.0f));
35      assertEquals(1.0f, max.getAggregatedValue().get(), 0f);
36      FloatWritable fw = max.createInitialValue();
37      assertNotNull(fw);
38    }
39  
40    @Test
41    public void testMinAggregator() {
42      FloatMinAggregator min = new FloatMinAggregator();
43      min.aggregate(new FloatWritable(3.0f));
44      min.aggregate(new FloatWritable(2.0f));
45      assertEquals(2.0f, min.getAggregatedValue().get(), 0f);
46      min.setAggregatedValue(new FloatWritable(3.0f));
47      assertEquals(3.0f, min.getAggregatedValue().get(), 0f);
48      FloatWritable fw = min.createInitialValue();
49      assertNotNull(fw);
50    }
51  
52    @Test
53    public void testOverwriteAggregator() {
54      FloatOverwriteAggregator overwrite = new FloatOverwriteAggregator();
55      overwrite.aggregate(new FloatWritable(1.0f));
56      assertEquals(1.0f, overwrite.getAggregatedValue().get(), 0f);
57      overwrite.aggregate(new FloatWritable(2.0f));
58      assertEquals(2.0f, overwrite.getAggregatedValue().get(), 0f);
59      overwrite.setAggregatedValue(new FloatWritable(3.0f));
60      assertEquals(3.0f, overwrite.getAggregatedValue().get(), 0f);
61      FloatWritable fw = overwrite.createInitialValue();
62      assertNotNull(fw);
63    }
64  
65    @Test
66    public void testProductAggregator() {
67      FloatProductAggregator product = new FloatProductAggregator();
68      product.aggregate(new FloatWritable(6.0f));
69      product.aggregate(new FloatWritable(7.0f));
70      assertEquals(42.0f, product.getAggregatedValue().get(), 0f);
71      product.setAggregatedValue(new FloatWritable(1.0f));
72      assertEquals(1.0f, product.getAggregatedValue().get(), 0f);
73      FloatWritable fw = product.createInitialValue();
74      assertNotNull(fw);
75    }
76  
77    @Test
78    public void testSumAggregator() {
79      FloatSumAggregator sum = new FloatSumAggregator();
80      sum.aggregate(new FloatWritable(1.0f));
81      sum.aggregate(new FloatWritable(2.0f));
82      assertEquals(3.0f, sum.getAggregatedValue().get(), 0f);
83      sum.setAggregatedValue(new FloatWritable(4.0f));
84      assertEquals(4.0f, sum.getAggregatedValue().get(), 0f);
85      FloatWritable fw = sum.createInitialValue();
86      assertNotNull(fw);
87    }
88  }