1 42 43 package org.jfree.data.junit; 44 45 import junit.framework.TestCase; 46 47 import org.jfree.data.DataUtilities; 48 import org.jfree.data.DefaultKeyedValues2D; 49 50 53 public class DataUtilitiesTests extends TestCase { 54 55 58 public void testCreateNumberArray2D() { 59 double[][] d = new double[2][]; 60 d[0] = new double[] {1.1, 2.2, 3.3, 4.4}; 61 d[1] = new double[] {1.1, 2.2, 3.3, 4.4, 5.5}; 62 Number [][] n = DataUtilities.createNumberArray2D(d); 63 assertEquals(2, n.length); 64 assertEquals(4, n[0].length); 65 assertEquals(5, n[1].length); 66 } 67 68 private static final double EPSILON = 0.000000001; 69 70 73 public void testCalculateColumnTotal() { 74 DefaultKeyedValues2D table = new DefaultKeyedValues2D(); 75 table.addValue(new Double (1.0), "R0", "C0"); 76 table.addValue(new Double (2.0), "R0", "C1"); 77 table.addValue(new Double (3.0), "R1", "C0"); 78 table.addValue(new Double (4.0), "R1", "C1"); 79 assertEquals(4.0, DataUtilities.calculateColumnTotal(table, 0), EPSILON); 80 assertEquals(6.0, DataUtilities.calculateColumnTotal(table, 1), EPSILON); 81 table.setValue(null, "R1", "C1"); 82 assertEquals(2.0, DataUtilities.calculateColumnTotal(table, 1), EPSILON); 83 } 84 85 88 public void testCalculateRowTotal() { 89 DefaultKeyedValues2D table = new DefaultKeyedValues2D(); 90 table.addValue(new Double (1.0), "R0", "C0"); 91 table.addValue(new Double (2.0), "R0", "C1"); 92 table.addValue(new Double (3.0), "R1", "C0"); 93 table.addValue(new Double (4.0), "R1", "C1"); 94 assertEquals(3.0, DataUtilities.calculateRowTotal(table, 0), EPSILON); 95 assertEquals(7.0, DataUtilities.calculateRowTotal(table, 1), EPSILON); 96 table.setValue(null, "R1", "C1"); 97 assertEquals(3.0, DataUtilities.calculateRowTotal(table, 1), EPSILON); 98 } 99 } 100 | Popular Tags |