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