This project has retired. For details please refer to its
Attic page.
TestFloatAggregators xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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 }