01: package test.tmp;
02:
03: import static org.testng.Assert.assertEquals;
04:
05: import org.testng.annotations.BeforeMethod;
06: import org.testng.annotations.DataProvider;
07: import org.testng.annotations.Test;
08:
09: @Test(suiteName="Exponent suite",testName="Exponent test")
10: public class ExponentTest {
11:
12: @DataProvider(name="random")
13: public Object[][] generateRandomExps() {
14: // This array should be generated with random numbers
15: return new Object[][] { new Object[] { 0.0, Math.exp(0) },
16: new Object[] { 1.0, Math.exp(1) },
17: new Object[] { 2.0, Math.exp(2) }, };
18: }
19:
20: @BeforeMethod
21: public void setUp() {
22: ppp("BEFORE METHOD");
23: }
24:
25: @Test(dataProvider="random")
26: public void testExponent(double exponent, double expected) {
27: ppp("COMPARING " + myExpFunction(exponent) + " AND " + expected);
28: assertEquals(myExpFunction(exponent), expected);
29: }
30:
31: private static void ppp(String s) {
32: System.out.println("[ExponentTest] " + s);
33: }
34:
35: private double myExpFunction(double exponent) {
36: return Math.exp(exponent);
37: }
38:
39: }
|