Advertisement
ksoltan

JamManufacturerTest

Nov 20th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import static org.junit.Assert.*;
  2.  
  3. import org.junit.Before;
  4. import org.junit.Test;
  5.  
  6. public class JamManufacturerTest {
  7.     private JamManufacturer j;
  8.  
  9.     @Before
  10.     public void setUp() throws Exception {
  11.         j = new JamManufacturer();
  12.     }
  13.  
  14.     @Test
  15.     public void test() {
  16.         for (int jars = 0; jars < 500; jars++) {
  17.             int nCartons = (jars + 11) / 12;
  18.             int totalOunces = 21 * jars + 25 * nCartons;
  19.             int lbs = (totalOunces + 15) / 16;
  20.             double cost = 3.0 + 1.44 * nCartons + 0.96 * lbs;
  21.             assertEquals(cost, j.computeShippingCost(jars), getTolerance(cost));
  22.         }
  23.     }
  24.  
  25.     /**
  26.      *
  27.      * @param cost
  28.      * @return 5% tolerance for the cost
  29.      */
  30.     private double getTolerance(double cost) {
  31.         return 0.05 * cost;
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement