01: package fit.decorator.performance;
02:
03: import java.text.ParseException;
04:
05: import fit.Counts;
06: import fit.decorator.FixtureDecoratorTestCase;
07: import fit.decorator.exceptions.InvalidInputException;
08: import fit.decorator.util.TestCaseHelper;
09:
10: public class TimeRangeTest extends FixtureDecoratorTestCase {
11: private static final String FIRST_HTML_ROW = "<tr><td>"
12: + TimeRange.class.getName()
13: + "</td><td>0</td><td>milliseconds min and max</td><td>30</td><td>milliseconds</td></tr>";
14: private TimeRange decorator = new TimeRange();
15:
16: protected String geDecoratorHTMLRow() {
17: return FIRST_HTML_ROW;
18: }
19:
20: protected int numberOfAssertionsOnDecorator() {
21: return 2;
22: }
23:
24: public void testSetupDecoratorMustThrowInvalidInputExceptionIfTimeRangeIsNotSpecified()
25: throws ParseException {
26: try {
27: decorator.setupDecorator(new String[] { "10" });
28: fail("Should blow up ");
29: } catch (InvalidInputException e) {
30: // expected
31: }
32: }
33:
34: public void testSetupDecoratorShouldAddTimeRangeToSummary()
35: throws Exception {
36: decorator.setupDecorator(new String[] { "10", "80" });
37: assertEquals(10, ((Long) decorator.summary
38: .get(TimeRange.MIN_TIME)).longValue());
39: assertEquals(80, ((Long) decorator.summary
40: .get(MaxTime.MAX_TIME)).longValue());
41: }
42:
43: public void testShouldFailIfActualExecutionTimeGreaterThanMaxTime()
44: throws Exception {
45: String fitPage = "<table><tr><td>fit.decorator.TimeRange</td><td>15</td><td>milliseconds min and max</td>"
46: + "<td>19</td><td>milliseconds</td></tr><tr><td>eg.Division</td></tr>"
47: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
48: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
49: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
50: Counts expected = TestCaseHelper.counts(4, 1, 0, 0);
51: executeAndAssert(expected, fitPage, new TimeRange(stopWatch));
52: }
53:
54: public void testShouldFailIfActualExecutionTimeLessThanMinTime()
55: throws Exception {
56: String fitPage = "<table><tr><td>fit.decorator.TimeRange</td><td>21</td><td>milliseconds min and max</td>"
57: + "<td>25</td><td>milliseconds</td></tr><tr><td>eg.Division</td></tr>"
58: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
59: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
60: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
61: Counts expected = TestCaseHelper.counts(4, 1, 0, 0);
62: executeAndAssert(expected, fitPage, new TimeRange(stopWatch));
63: }
64:
65: public void testShouldPassIfActualExecutionTimeIsWithinTheRange()
66: throws Exception {
67: String fitPage = "<table><tr><td>fit.decorator.TimeRange</td><td>15</td><td>milliseconds min and max</td>"
68: + "<td>25</td><td>milliseconds</td></tr><tr><td>eg.Division</td></tr>"
69: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
70: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
71: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
72: Counts expected = TestCaseHelper.counts(5, 0, 0, 0);
73: executeAndAssert(expected, fitPage, new TimeRange(stopWatch));
74: }
75:
76: public void testShouldPassIfActualExecutionTimeIsEqualToMinTime()
77: throws Exception {
78: String fitPage = "<table><tr><td>fit.decorator.TimeRange</td><td>20</td><td>milliseconds min and max</td>"
79: + "<td>25</td><td>milliseconds</td></tr><tr><td>eg.Division</td></tr>"
80: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
81: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
82: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
83: Counts expected = TestCaseHelper.counts(5, 0, 0, 0);
84: executeAndAssert(expected, fitPage, new TimeRange(stopWatch));
85: }
86:
87: public void testShouldPassIfActualExecutionTimeIsEqualToMaxTime()
88: throws Exception {
89: String fitPage = "<table><tr><td>fit.decorator.TimeRange</td><td>15</td><td>milliseconds min and max</td>"
90: + "<td>20</td><td>milliseconds</td></tr><tr><td>eg.Division</td></tr>"
91: + "<tr><td>numerator</td><td>denominator</td><td>quotient()</td></tr>"
92: + "<tr><td>10</td><td>2</td><td>5</td></tr><tr><td>12.6</td><td>3</td><td>4.2</td></tr>"
93: + "<tr><td>100</td><td>4</td><td>25</td></tr></table>";
94: Counts expected = TestCaseHelper.counts(5, 0, 0, 0);
95: executeAndAssert(expected, fitPage, new TimeRange(stopWatch));
96: }
97: }
|