Guest User

Untitled

a guest
Apr 29th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. import static org.junit.Assert.*;
  2. import org.junit.Test;
  3. /**
  4. * The test class PassengerArrivalFunctionTest.
  5. *
  6. * @version 1.0 ($Id: PassengerArrivalFunctionTest.java 158 2016-04-14 23:49:12Z garret $)
  7. */
  8. public class PassengerArrivalFunctionTest {
  9. @Test
  10. public void arrivalDataAccessTest() {
  11. PassengerArrivalFunction paf = new PassengerArrivalFunction();
  12. int[] allArrivals = paf.passengerArrivals();
  13. // This is the line causing trouble assertEquals((Time.MINUTES_PER_HOUR * Time.HOURS_PER_DAY), allArrivals.length);
  14. paf = new PassengerArrivalFunction(100000);
  15. allArrivals = paf.passengerArrivals();
  16. assertEquals((Time.MINUTES_PER_HOUR * Time.HOURS_PER_DAY), allArrivals.length);
  17. for (int i : allArrivals) {
  18. assertTrue("May fail due to random sequence.",
  19. 0 < i);
  20. }
  21. }
  22.  
  23. @Test
  24. public void uniformArrivalsTest() {
  25. final int expectedArrivals = 10000;
  26. final double tolerance = 0.05; // Accept 5% over/under.
  27. Uniform uniformDist = new Uniform();
  28. PassengerArrivalFunction paf = new PassengerArrivalFunction(expectedArrivals,
  29. uniformDist,
  30. uniformDist,
  31. uniformDist);
  32. double totalArrivals = paf.numberOfArrivingPassengers(new Time(0, 0), new Time(23, 59));
  33. assertEquals("May fail due to random sequence.",
  34. expectedArrivals, totalArrivals, tolerance * expectedArrivals);
  35. }
  36.  
  37. @Test
  38. public void uniformArrivalsBoundaryTest() {
  39. final int maxExpectedArrivals = 500;
  40. final double mean = 250;
  41. Uniform uniformDist = new Uniform();
  42. final int actualArrivals = uniformDist.nextSample(mean);
  43.  
  44. assertTrue("Actual passenger arrivals should " +
  45. "should not be greater than the max expected arrivals" +
  46. " since this is the upper boundary of our uniform interval",
  47. actualArrivals <= maxExpectedArrivals);
  48. }
  49.  
  50. @Test
  51. public void poissonArrivalsTest() {
  52. final int expectedArrivals = 10000;
  53. final double tolerance = 0.05;
  54. Poisson poissonDist = new Poisson();
  55. PassengerArrivalFunction paf = new PassengerArrivalFunction(expectedArrivals,
  56. poissonDist,
  57. poissonDist,
  58. poissonDist);
  59. double totalArrivals = paf.numberOfArrivingPassengers(new Time(0, 0), new Time(23, 59));
  60. assertEquals("May fail due to random sequence.",
  61. expectedArrivals, totalArrivals, tolerance * expectedArrivals);
  62. }
  63.  
  64. @Test
  65. public void standardArrivalsTest() {
  66. PassengerArrivalFunction paf = new PassengerArrivalFunction(10000);
  67. int offPeakHourArrivals = paf.numberOfArrivingPassengers(new Time(2, 0), new Time(3, 0));
  68. int morningPeakHourArrivals = paf.numberOfArrivingPassengers(new Time(7, 0), new Time(8, 0));
  69. int eveningPeakHourArrivals = paf.numberOfArrivingPassengers(new Time(16, 30), new Time(17, 30));
  70. assertTrue(offPeakHourArrivals < eveningPeakHourArrivals);
  71. assertTrue(eveningPeakHourArrivals < morningPeakHourArrivals);
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment