1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
/*
* TestChartOperationsVisual.java of project jchart2d, test case
* for visually testing operations of the jchart2d API.
* Copyright 2007 (C) Achim Westermann, created on 04.03.2007 11:12:01.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*
* If you modify or optimize the code in a useful way please let me know.
* Achim.Westermann@gmx.de
*
*/
package info.monitorenter.gui.chart.labelformatters;
import info.monitorenter.gui.chart.Chart2D;
import info.monitorenter.gui.chart.IAxis;
import info.monitorenter.gui.chart.IAxisLabelFormatter;
import info.monitorenter.gui.chart.ITrace2D;
import info.monitorenter.gui.chart.test.ATestChartOperations;
import java.text.DecimalFormat;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Visual test of operations upon the chart with basic ui for human judgement of
* success or failure.
* <p>
*
* @author <a href="mailto:Achim.Westermann@gmx.de">Achim Westermann</a>
*
*
* @version $Revision: 1.5 $
*/
public class TestLabelFormatterAutoUnits extends ATestChartOperations {
/**
* Test suite for this test class.
* <p>
*
* @return the test suite
*/
public static Test suite() {
TestSuite suite = new TestSuite();
suite.setName(TestLabelFormatterAutoUnits.class.getName());
suite.addTest(new TestLabelFormatterAutoUnits("testLabelFormatterSimple"));
suite.addTest(new TestLabelFormatterAutoUnits("testLabelFormatterAutoUnits"));
suite.addTest(new TestLabelFormatterAutoUnits("testLabelFormatterAutoUnitsFemto"));
suite.addTest(new TestLabelFormatterAutoUnits("testLabelFormatterAutoUnitsNano"));
return suite;
}
/**
* Constructor with the test name.
* <p>
*
* @param arg0
* the name of the test.
*/
public TestLabelFormatterAutoUnits(final String arg0) {
super(arg0);
}
/**
* Sets a new number format to a <code>{@link LabelFormatterNumber}</code> of
* the y axis.
* <p>
*/
public void testLabelFormatterAutoUnits() {
ATestChartOperations.AChartOperation operation = new AChartOperation(
"y-axis with auto units formatter and a minimal milli range: enough ticks?") {
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.IChart2DOperation#action(info.monitorenter.gui.chart.Chart2D)
*/
public Object action(final Chart2D chart) {
return null;
}
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.AChartOperation#fillTrace(info.monitorenter.gui.chart.ITrace2D)
*/
@Override
public void fillTrace(final ITrace2D trace) {
trace.addPoint(47, 0.103759765625);
trace.addPoint(48, 0.106201171875);
trace.addPoint(48, 0.10986328125);
trace.addPoint(49, 0.106201171875);
trace.addPoint(49, 0.091552734375);
trace.addPoint(50, 0.091552734375);
}
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.AChartOperation#preCondition(info.monitorenter.gui.chart.Chart2D)
*/
@Override
public void preCondition(final Chart2D chart) throws Exception {
chart.getAxisY().setStartMajorTick(false);
LabelFormatterAutoUnits formatter = new LabelFormatterAutoUnits();
LabelFormatterNumber nf = (LabelFormatterNumber) formatter.getDelegate();
nf.getNumberFormat().setMaximumFractionDigits(100);
nf.setNumberFormat(new DecimalFormat("##.######"));
IAxis<?> yAxis = chart.getAxisY();
yAxis.setFormatter(formatter);
// force the precondition visual change to have time show.
// else the repaint could occur after the number format has been
// set to the LabelFormatterNumber!
Thread.sleep(1000);
}
};
this.setTestOperation(operation);
}
/**
* Checks if the given label formatter uses the femto unit for small numbers
* (e.g. 0.0000000000000005).
* <p>
*/
public void testLabelFormatterAutoUnitsFemto() {
ATestChartOperations.AChartOperation operation = new AChartOperation(
"y-axis should have femto prefix") {
/**
* Sets a {@link LabelFormatterAutoUnits} to the y axis of the chart.
* <p>
*
* @see info.monitorenter.gui.chart.test.ATestChartOperations.AChartOperation#preCondition(info.monitorenter.gui.chart.Chart2D)
*/
@Override
public void preCondition(Chart2D chart) throws Exception {
super.preCondition(chart);
chart.getAxisY().setFormatter(new LabelFormatterAutoUnits());
}
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.IChart2DOperation#action(info.monitorenter.gui.chart.Chart2D)
*/
public Object action(final Chart2D chart) {
return null;
}
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.AChartOperation#fillTrace(info.monitorenter.gui.chart.ITrace2D)
*/
@Override
public void fillTrace(final ITrace2D trace) {
trace.addPoint(47, 0.0000000000000005);
trace.addPoint(48, 0.0000000000000010);
trace.addPoint(48, 0.0000000000000006);
trace.addPoint(49, 0.0000000000000009);
trace.addPoint(49, 0.0000000000000008);
trace.addPoint(50, 0.0000000000000007);
trace.addPoint(48, 0.0000000000000012);
}
};
this.setTestOperation(operation);
}
/**
* Checks if the given label formatter uses the nano unit for small numbers
* (e.g. 0.0000000000005).
* <p>
*/
public void testLabelFormatterAutoUnitsNano() {
ATestChartOperations.AChartOperation operation = new AChartOperation(
"y-axis should have nano prefix") {
/**
* Sets a {@link LabelFormatterAutoUnits} to the y axis of the chart.
* <p>
*
* @see info.monitorenter.gui.chart.test.ATestChartOperations.AChartOperation#preCondition(info.monitorenter.gui.chart.Chart2D)
*/
@Override
public void preCondition(Chart2D chart) throws Exception {
super.preCondition(chart);
chart.getAxisY().setFormatter(new LabelFormatterAutoUnits());
}
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.IChart2DOperation#action(info.monitorenter.gui.chart.Chart2D)
*/
public Object action(final Chart2D chart) {
return null;
}
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.AChartOperation#fillTrace(info.monitorenter.gui.chart.ITrace2D)
*/
@Override
public void fillTrace(final ITrace2D trace) {
trace.addPoint(47, 0.0000000005);
trace.addPoint(48, 0.0000000010);
trace.addPoint(48, 0.0000000006);
trace.addPoint(49, 0.0000000009);
trace.addPoint(49, 0.0000000008);
trace.addPoint(50, 0.0000000007);
trace.addPoint(50, 0.0000000027);
}
};
this.setTestOperation(operation);
}
/**
* Sets a new number format to a <code>{@link LabelFormatterNumber}</code> of
* the y axis.
* <p>
*/
public void testLabelFormatterSimple() {
ATestChartOperations.AChartOperation operation = new AChartOperation(
"y-axis with simple formatter and a minimal milli range: enough ticks?") {
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.IChart2DOperation#action(info.monitorenter.gui.chart.Chart2D)
*/
public Object action(final Chart2D chart) {
return null;
}
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.AChartOperation#fillTrace(info.monitorenter.gui.chart.ITrace2D)
*/
@Override
public void fillTrace(final ITrace2D trace) {
trace.addPoint(47, 0.103759765625);
trace.addPoint(48, 0.106201171875);
trace.addPoint(48, 0.10986328125);
trace.addPoint(49, 0.106201171875);
trace.addPoint(49, 0.091552734375);
trace.addPoint(50, 0.091552734375);
}
/**
* @see info.monitorenter.gui.chart.test.ATestChartOperations.AChartOperation#preCondition(info.monitorenter.gui.chart.Chart2D)
*/
@Override
public void preCondition(final Chart2D chart) throws Exception {
chart.getAxisY().setStartMajorTick(false);
IAxisLabelFormatter formatter = new LabelFormatterSimple();
IAxis<?> yAxis = chart.getAxisY();
yAxis.setFormatter(formatter);
// force the precondition visual change to have time show.
// else the repaint could occur after the number format has been
// set to the LabelFormatterNumber!
Thread.sleep(1000);
}
};
this.setTestOperation(operation);
}
}
|