Advertisement
moreiramota

Untitled

Jan 9th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.55 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package lapr.project.model;
  7.  
  8. import java.sql.Timestamp;
  9. import java.util.ArrayList;
  10. import java.util.Date;
  11. import java.util.HashSet;
  12. import java.util.List;
  13. import java.util.Set;
  14. import lapr.project.controller.GraphController;
  15. import lapr.project.data.JourneyDB;
  16. import lapr.project.data.ParkDB;
  17. import lapr.project.data.RouteDB;
  18. import static org.junit.jupiter.api.Assertions.assertEquals;
  19. import static org.junit.jupiter.api.Assertions.assertFalse;
  20. import static org.junit.jupiter.api.Assertions.assertThrows;
  21. import static org.junit.jupiter.api.Assertions.assertTrue;
  22. import static org.junit.jupiter.api.Assertions.fail;
  23. import org.junit.jupiter.api.Test;
  24. import org.mockito.Mock;
  25. import org.mockito.Mockito;
  26. import static org.mockito.Mockito.when;
  27. import org.mockito.MockitoAnnotations;
  28.  
  29. /**
  30. *
  31. * @author morei
  32. */
  33. public class JourneyTest {
  34.  
  35. @Mock
  36. ParkDB pdb;
  37.  
  38. @Mock
  39. JourneyDB db;
  40.  
  41. @Mock
  42. Park p;
  43.  
  44. @Mock
  45. RouteDB rdb;
  46.  
  47. @Mock
  48. Route route;
  49.  
  50. Journey j = new Journey();
  51.  
  52. List<Route> routes = new ArrayList<>();
  53. Journey instance = new Journey();
  54. Journey instance1 = new Journey(new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0);
  55. Journey instance2 = new Journey(1, new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0, new Date(10), routes);
  56. Journey instance3 = new Journey(new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0);
  57. Journey instance4 = new Journey(new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0, new Date(10));
  58.  
  59. @Test
  60. public void testException() {
  61. Journey.setDB(null);
  62. NullPointerException exceptionGet = assertThrows(NullPointerException.class, () -> {
  63. Journey.getJourney(0);
  64. });
  65. assertTrue(exceptionGet.getMessage().equals("The dataBase connection was not yet set, either set or get a new one"));
  66. exceptionGet = assertThrows(NullPointerException.class, () -> {
  67. Journey.removeJourney(0);
  68. });
  69. assertTrue(exceptionGet.getMessage().equals("The dataBase connection was not yet set, either set or get a new one"));
  70. exceptionGet = assertThrows(NullPointerException.class, () -> {
  71. new Journey().save();
  72. });
  73. assertTrue(exceptionGet.getMessage().equals("The dataBase connection was not yet set, either set or get a new one"));
  74. assertTrue(Journey.getCurrentDB() == null);
  75.  
  76. Journey.getDB();
  77. assertTrue(Journey.getCurrentDB() != null);
  78.  
  79. }
  80.  
  81. @Test
  82. public void testDB() {
  83. MockitoAnnotations.initMocks(this);
  84. Journey.setDB(db);
  85.  
  86. when(db.getJourney(0)).thenReturn(j);
  87. assertTrue(Journey.getJourney(0).equals(j));
  88.  
  89. System.out.println("Test remove");
  90. Mockito.doThrow(new IllegalArgumentException()).when(db).removeJourney(0);
  91.  
  92. //ensure method call
  93. boolean exception = false;
  94. try {
  95. Journey.removeJourney(0);
  96. fail("There should have been an exception");
  97. } catch (Exception ex) {
  98. exception = true;
  99. }
  100. assertTrue(exception);
  101. Mockito.doNothing().when(db).removeJourney(0);
  102.  
  103. Journey.removeJourney(0);
  104. assertTrue(true);
  105.  
  106. System.out.println("Test save");
  107. System.out.println("Test save-update");
  108. Mockito.doThrow(new IndexOutOfBoundsException("test"))
  109. .when(db).updateJourney(j);
  110.  
  111. try {
  112. exception = false;
  113. j.save();
  114. fail("There should have been an exception");
  115. } catch (IndexOutOfBoundsException ex) {
  116. exception = true;
  117. }
  118. assertTrue(exception);
  119.  
  120. System.out.println("Test savve-add");
  121. Mockito.doThrow(new IllegalArgumentException()).when(db).updateJourney(j);
  122. //ensure method add is called
  123. Mockito.doThrow(new IndexOutOfBoundsException("test")).when(db).addJourney(j);
  124.  
  125. try {
  126. exception = false;
  127. j.save();
  128. fail("There should have been an exception");
  129. } catch (IndexOutOfBoundsException ex) {
  130. exception = true;
  131. }
  132. assertTrue(exception);
  133. Mockito.doNothing().when(db).addJourney(j);
  134.  
  135. System.out.println("Test save- routes");
  136. j.setRoutes(new ArrayList<>());
  137. j.addRoute(route);
  138. Mockito.doNothing().when(db).addJourney(j);
  139. Mockito.doThrow(new IndexOutOfBoundsException("test")).when(route).updateRoute();
  140. //ensure ps.update is being executed
  141. try {
  142. exception = false;
  143. j.save();
  144. fail("There should have been an exception");
  145. } catch (IndexOutOfBoundsException ex) {
  146. exception = true;
  147. }
  148. Mockito.doNothing().when(route).updateRoute();
  149. j.save();
  150. assertTrue(true);
  151.  
  152. Mockito.doThrow(new IllegalArgumentException("test")).when(route).updateRoute();
  153. Mockito.doThrow(new IndexOutOfBoundsException("test")).when(route).save();
  154. //ensure ps.addParkingSlot is being executed
  155. try {
  156. exception = false;
  157. j.save();
  158. fail("There should have been an exception");
  159. } catch (IndexOutOfBoundsException ex) {
  160. exception = true;
  161. }
  162. Mockito.doNothing().when(route).save();
  163. j.save();
  164. assertTrue(true);
  165. Mockito.doNothing().when(db).updateJourney(j);
  166. j.save();
  167. assertTrue(true);
  168.  
  169. System.out.println("Test end");
  170. Park.setDB(pdb);
  171. p.setLocation(new Location(0, 0, 0));
  172. when(pdb.getPark(0, 0)).thenReturn(p);
  173. j.setUserName(new User("", "349590615116555", 1, 23));
  174. Bicycle b1 = new Bicycle("", 1, 1, "y", 20, null);
  175. j.setBicycle(b1);
  176. route.setLocation(new Location(0, 0, 0));
  177. j.setRoutes(new ArrayList<>());
  178. j.addRoute(new Route(new Location(0, 0, 0), 0, new Timestamp(400), 0));
  179.  
  180. j.addRoute(new Route(new Location(0, 0, 0), 0, new Timestamp(100000000), 0));
  181. assertFalse(j.endJourney());
  182. when(p.addBicycle(b1)).thenReturn(new ParkingSlot(1));
  183. Mockito.doThrow(new IllegalArgumentException()).when(p).save();
  184. assertFalse(j.endJourney());
  185.  
  186. Mockito.doNothing().when(p).save();
  187. assertTrue(j.endJourney());
  188. assertEquals(j.getPrice(), 81);
  189. assertTrue(j.getMonthYear().equals(new Timestamp(100000000)));
  190. }
  191.  
  192. //ENSURE UPDATE CALL
  193. @Test
  194. public void testDbGetDelete() {
  195. MockitoAnnotations.initMocks(this);
  196. Journey.setDB(db);
  197.  
  198. //TEST OF GET
  199. when(db.getJourney(0)).thenReturn(j);
  200. assertEquals(Journey.getJourney(0), j);
  201.  
  202. //TEST OF REMOVE
  203. //ENSURE REMOVE IS CALLED
  204. Mockito.doThrow(new ArrayIndexOutOfBoundsException()).when(db).removeJourney(0);
  205. ArrayIndexOutOfBoundsException exceptionGet = assertThrows(ArrayIndexOutOfBoundsException.class, () -> {
  206. Journey.removeJourney(0);
  207. });
  208. assertTrue(exceptionGet.getMessage() == null);
  209.  
  210. Mockito.doNothing().when(db).removeJourney(0);
  211. Journey.removeJourney(0);
  212. assertTrue(true);
  213. }
  214.  
  215. /**
  216. * Test of getId method, of class Journey.
  217. */
  218. @Test
  219. public void testGetIdReservation() {
  220. System.out.println("getIdReservation");
  221. int expResult = 1;
  222. int result = instance2.getIdReservation();
  223. assertEquals(expResult, result);
  224. }
  225.  
  226. /**
  227. * Test of getReservationDate method, of class Journey.
  228. */
  229. @Test
  230. public void testGetReservationDate() {
  231. System.out.println("getReservationDate");
  232. Timestamp expResult = new Timestamp(10);
  233. Timestamp result = instance2.getReservationDate();
  234. assertEquals(expResult, result);
  235. }
  236.  
  237. /**
  238. * Test of getPrice method, of class Journey.
  239. */
  240. @Test
  241. public void testGetPrice() {
  242. System.out.println("getPrice");
  243. int expResult = 0;
  244. int result = instance2.getPrice();
  245. assertEquals(expResult, result);
  246. }
  247.  
  248. /**
  249. * Test of getMonthYear method, of class Journey.
  250. */
  251. @Test
  252. public void testGetMonthYear() {
  253. System.out.println("getMonthYear");
  254. Date expResult = new Date(10);
  255. Date result = instance2.getMonthYear();
  256. assertEquals(expResult, result);
  257. }
  258.  
  259. /**
  260. * Test of setReservationDate method, of class Journey.
  261. */
  262. @Test
  263. public void testSetReservationDate() {
  264. System.out.println("setReservationDate");
  265. Timestamp reservationDate = new Timestamp(15);
  266. instance2.setReservationDate(reservationDate);
  267. assertEquals(reservationDate, instance2.getReservationDate());
  268. }
  269.  
  270. /**
  271. * Test of setUserName method, of class Journey.
  272. */
  273. @Test
  274. public void testSetUsername() {
  275. System.out.println("testSetUsername");
  276. User instance = new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0);
  277. instance2.setUserName(instance);
  278. assertEquals(instance, instance2.getUser());
  279. }
  280.  
  281. /**
  282. * Test of setIdBicycle method, of class Journey.
  283. */
  284. @Test
  285. public void testSetIdBicycle() {
  286. System.out.println("setIdBicycle");
  287.  
  288. Bicycle b1 = new Bicycle("", 1, 1, "y", 15.6, "oo");
  289. instance2.setBicycle(b1);
  290. assertEquals(b1, instance2.getBicycle());
  291. }
  292.  
  293. /**
  294. * Test of setPrice method, of class Journey.
  295. */
  296. @Test
  297. public void testSetPrice() {
  298. System.out.println("setPrice");
  299. int price = 15;
  300. instance2.setPrice(price);
  301. assertEquals(price, instance2.getPrice());
  302. }
  303.  
  304. /**
  305. * Test of setMonthYear method, of class Journey.
  306. */
  307. @Test
  308. public void testSetMonthYear() {
  309. System.out.println("setMonthYear");
  310. Date monthYear = new Date(15);
  311. instance2.setMonthYear(monthYear);
  312. assertEquals(monthYear, instance2.getMonthYear());
  313. }
  314.  
  315. /**
  316. * Test of toString method, of class Journey.
  317. */
  318. @Test
  319. public void testToString() {
  320. System.out.println("toString");
  321. // String expResult = "Reservation date 1970-01-01 01:00:00.01 Email 1161263@isep.ipp.pt Id bicycle 1 Price 0 Month Year Thu Jan 01 01:00:00 WET 1970";
  322.  
  323. String expResult1 = "Reservation date "
  324. + instance2.getReservationDate().toString()
  325. + " Username " + instance2.getUser().getUsername()
  326. + " Id bicycle " + instance2.getBicycle().getDescription()
  327. + " Price " + instance2.getPrice()
  328. + " Month Year " + instance2.getMonthYear().toString();
  329. String result = instance2.toString();
  330.  
  331. assertEquals(expResult1, result);
  332. }
  333.  
  334. /**
  335. * Test of equals method, of class Journey.
  336. */
  337. @Test
  338. public void testEquals() {
  339. System.out.println("equals");
  340. Object obj = null;
  341. boolean expResult = false;
  342. boolean result = instance.equals(obj);
  343. assertEquals(expResult, result);
  344. }
  345.  
  346. /**
  347. * Test of equals method, of class Journey.
  348. */
  349. @Test
  350. public void testEqualsDiferentClass() {
  351. System.out.println("equals");
  352. Object obj = new Park("", new Location(), 0, 0);
  353. boolean expResult = false;
  354. boolean result = instance.equals(obj);
  355. assertEquals(expResult, result);
  356. }
  357.  
  358. /**
  359. * Test of equals method, of class Journey.
  360. */
  361. @Test
  362. public void testEquals1() {
  363. System.out.println("equals");
  364. Object obj = instance2;
  365. boolean expResult = true;
  366. boolean result = instance2.equals(obj);
  367. assertEquals(expResult, result);
  368. }
  369.  
  370. /**
  371. * Test of equals method, of class Journey.
  372. */
  373. @Test
  374. public void testEquals2() {
  375. System.out.println("equals");
  376. Object obj = new Journey(2, new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 0, new Date(10), routes);
  377. boolean expResult = false;
  378. boolean result = instance2.equals(obj);
  379. assertEquals(expResult, result);
  380. }
  381.  
  382. /**
  383. * Test of equals method, of class Journey.
  384. */
  385. @Test
  386. public void testEquals3() {
  387. System.out.println("equals");
  388. Object obj = new Journey(1, new User("", "NOTadminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(15), new Bicycle("", 2, 1, "y", 15.6, null), 2, new Date(15), routes);
  389. boolean expResult = true;
  390. boolean result = instance2.equals(obj);
  391. assertEquals(expResult, result);
  392. }
  393.  
  394. /**
  395. * Test of routes methods, of class Journey.
  396. */
  397. @Test
  398. public void testSetAddGetRoutes() {
  399. List<Route> routes = new ArrayList<>();
  400. routes.add(new Route(null, 0));
  401.  
  402. Journey journey = new Journey();
  403. journey.setRoutes(routes);
  404. journey.addRoute(new Route(null, 1));
  405.  
  406. assertEquals(journey.getRoutes().size(), 2);
  407. assertEquals(journey.getRoutes(), routes);
  408.  
  409. }
  410.  
  411. @Test
  412. public void testCalcPrice() {
  413. List<Route> routes = new ArrayList<>();
  414. routes.add(new Route(new Timestamp(0), 0));
  415. routes.add(new Route(new Timestamp(10000000), 0));
  416. Journey test = new Journey(new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null));
  417. test.setRoutes(routes);
  418. test.calculatePrice();
  419. assertEquals(test.getPrice(), 6);
  420. test.calculateMonthYear();
  421. assertEquals(test.getMonthYear(), new Timestamp(10000000));
  422. routes.get(0).setVisitDate(new Timestamp(10000000));
  423. test.calculatePrice();
  424. assertEquals(test.getPrice(), 0);
  425.  
  426. }
  427.  
  428. /**
  429. * Test of hashCode method, of class Journey.
  430. */
  431. @Test
  432. public void testHashCode() {
  433. System.out.println("hashCode");
  434. int expResult = hashCode(instance2);
  435. int result = instance2.hashCode();
  436. assertEquals(expResult, result);
  437. }
  438.  
  439. public int hashCode(Journey j) {
  440. int hash = 5;
  441. hash = 37 * hash + j.getIdReservation();
  442. return hash;
  443. }
  444.  
  445. @Test
  446. public void testCalculateCredits() {
  447. MockitoAnnotations.initMocks(this);
  448.  
  449. List<Route> rou1 = new ArrayList<>();
  450. Journey journey = new Journey(1, new User("", "349590615116555", 0, 0), new Timestamp(50),
  451. new Bicycle("a", 1, 1, "Y", 20.0, "name"), 30, new Timestamp(60), rou1);
  452. assertTrue(journey.getCredits() == null);
  453. assertTrue(journey.getUser().getCreditPoints() == 0);
  454. Journey.setDB(null);
  455. journey.calculateCredits();
  456. assertTrue(journey.getCredits() == null);
  457. assertTrue(journey.getUser().getCreditPoints() == 0);
  458. //
  459. Journey.setDB(db);
  460. assertTrue(Journey.getCurrentDB() != null);
  461. Route r = new Route(new Location(0, 0, 0), 0, new Timestamp(0), 0);
  462. Route r1 = new Route(new Location(0, 0, 0), 0, new Timestamp(5000000), 0);
  463. journey.setRoutes(new ArrayList<>());
  464. journey.addRoute(r);
  465. journey.addRoute(r1);
  466. when(db.getJourneyCredits(29, new Location(29, 29, 29))).thenReturn(5000);
  467. //
  468. }
  469.  
  470. @Test
  471. public void testCalculateEnergyBetweenParksEletricBicycle() {
  472.  
  473. System.out.println("testCalculateEnergyBetweenParksEletricBicycle");
  474. GraphController graphController = new GraphController(new User("linhaDeSintra-AmorDeMae", 80.5, 12.5f));
  475. Set<Point> points = new HashSet<>();
  476. Point p1 = new TouristicPoint(12, 12, 21, "TESTE");
  477. Point p2 = new Park("", new Location(13, 13, 13), 0, 0);
  478. points.add(p1);
  479. points.add(p2);
  480. graphController.getGraphHandler().addPoints(points);
  481. graphController.getGraphHandler().insertPath(1, p1, p2, 0, 0, true);
  482.  
  483. graphController.getGraphHandler().setWind(p1, p2, 5.0, 0);
  484. graphController.getGraphHandler().setDistance(p1, p2, 25.1);
  485.  
  486. User user = new User("linhaDeSintra-AmorDeMae", 80.5, 12.5f);
  487. user.setHeight(180.4);
  488. user.setAverageSpeed(10.5);
  489.  
  490. Battery bat = new Battery(2, 120.5, 30.4, new Timestamp(10));
  491. EBicycle eb = new EBicycle("", 1, 1, "y", 15.6, bat, "abc@gmail.com");
  492. eb.setAerodynamic(0.65f);
  493. double airV1 = graphController.getGraphHandler().getWind(p1, p2);
  494. graphController.getGraphHandler().setCoeficient(p1, p2, 0.5);
  495. //--------------------------------------------//
  496. Location li = p1.getLocation();
  497. Location lf = p2.getLocation();
  498. double bang = Wind.calculatePathDirection(li, lf);
  499. double inicialHeight = (double) li.getAltitude();
  500. double finalHeight = (double) lf.getAltitude();
  501.  
  502. double distance = graphController.getGraphHandler().getDistance(p1, p2);
  503. System.out.println(distance);
  504.  
  505. double bodyArea = Math.sqrt(((user.getWeight() + eb.getWeigth()) * user.getHeight()) / 3600);
  506. System.out.println(bodyArea);
  507.  
  508. double heightDifference = finalHeight - inicialHeight;
  509. System.out.println(heightDifference);
  510. double angle = (Math.asin(heightDifference / distance));
  511. System.out.println(angle);
  512.  
  513. double resAng = bang - angle;
  514.  
  515. double fa = ((eb.getWeigth() + user.getWeight()) * 9.8 * graphController.getGraphHandler().getCoefficient(p1, p2));
  516. System.out.println(fa);
  517.  
  518. double df = (0.5 * 1.2041 * (Math.pow(Bicycle.ELETRICBICYCLEVELOCITY - airV1 * Math.cos(resAng), 2)) * eb.getAerodynamic() * bodyArea);
  519. System.out.println(df);
  520.  
  521. double gf = (user.getWeight() + eb.getWeigth()) * 9.8 * heightDifference * Math.sin(angle);
  522. System.out.println(gf);
  523.  
  524. double arf = bodyArea * 1.2041 * eb.getAerodynamic() * (Math.pow((user.getAverageSpeed() - airV1 * Math.cos(resAng)), 2));
  525. System.out.println(arf);
  526.  
  527. double total = ((fa * distance) + (df * distance) + (gf * distance) + (arf * distance));
  528. System.out.println(total);
  529.  
  530. double expResult = total * 2.77777778E-7;
  531. double result = Journey.calculateEnergyBetweenTwoLocations(li, lf, user, user.getAverageSpeed(), eb, graphController.getGraphHandler());
  532. assertEquals(expResult, result, 0.01);
  533.  
  534. }
  535.  
  536. @Test
  537. public void testCalculateEnergyBetweenParksRoadBicycle() {
  538. System.out.println("testCalculateEnergyBetweenParksRoadBicycle");
  539. GraphController graphController = new GraphController(new User("linhaDeSintra-AmorDeMae", 80.5, 12.5f));
  540. Set<Point> points = new HashSet<>();
  541. Point p1 = new TouristicPoint(12, 12, 21, "TESTE");
  542. Point p2 = new Park("", new Location(13, 13, 13), 0, 0);
  543. points.add(p1);
  544. points.add(p2);
  545. graphController.getGraphHandler().addPoints(points);
  546. graphController.getGraphHandler().insertPath(1, p1, p2, 0, 0, true);
  547.  
  548. graphController.getGraphHandler().setWind(p1, p2, 5.0, 5);
  549. graphController.getGraphHandler().setDistance(p1, p2, 25.1);
  550.  
  551. User user = new User("linhaDeSintra-AmorDeMae", 80.5, 12.5f);
  552. user.setHeight(180.4);
  553. user.setAverageSpeed(10.5);
  554.  
  555. Bicycle eb = new Bicycle("", 1, 1, "y", 15.6, "abc@gmail.com");
  556. eb.setAerodynamic(0.65f);
  557. double airV1 = graphController.getGraphHandler().getWind(p1, p2);
  558. graphController.getGraphHandler().setCoeficient(p1, p2, 0.5);
  559. //--------------------------------------------//
  560. Location li = p1.getLocation();
  561. Location lf = p2.getLocation();
  562. double bang = Wind.calculatePathDirection(li, lf);
  563. double inicialHeight = (double) li.getAltitude();
  564. double finalHeight = (double) lf.getAltitude();
  565.  
  566. double distance = graphController.getGraphHandler().getDistance(p1, p2);
  567. System.out.println(distance);
  568.  
  569. double bodyArea = Math.sqrt(((user.getWeight() + eb.getWeigth()) * user.getHeight()) / 3600);
  570. System.out.println(bodyArea);
  571.  
  572. double heightDifference = finalHeight - inicialHeight;
  573. System.out.println(heightDifference);
  574. double angle = (Math.asin(heightDifference / distance));
  575. System.out.println(angle);
  576.  
  577. double resAng = bang - angle;
  578.  
  579. double fa = ((eb.getWeigth() + user.getWeight()) * 9.8 * graphController.getGraphHandler().getCoefficient(p1, p2));
  580. System.out.println(fa);
  581.  
  582. double df = (0.5 * 1.2041 * (Math.pow(Bicycle.ROADBICYCLEVELOCITY - airV1 * Math.cos(resAng), 2)) * eb.getAerodynamic() * bodyArea);
  583. System.out.println(df);
  584.  
  585. double gf = (user.getWeight() + eb.getWeigth()) * 9.8 * heightDifference * Math.sin(angle);
  586. System.out.println(gf);
  587.  
  588. double arf = bodyArea * 1.2041 * eb.getAerodynamic() * (Math.pow((user.getAverageSpeed() - airV1 * Math.cos(resAng)), 2));
  589. System.out.println(arf);
  590.  
  591. double total = ((fa * distance) + (df * distance) + (gf * distance) + (arf * distance));
  592. System.out.println(total);
  593.  
  594. double expResult = total * 2.77777778E-7;
  595. double result = Journey.calculateEnergyBetweenTwoLocations(li, lf, user, user.getAverageSpeed(), eb, graphController.getGraphHandler());
  596. assertEquals(expResult, result, 0.01);
  597. }
  598.  
  599. @Test
  600. public void testEnergyDuringJourney() {
  601. System.out.println("testEnergyDuringJourney");
  602. GraphController graphController = new GraphController(new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0));
  603. Set<Point> points = new HashSet<>();
  604. Point p1 = new TouristicPoint(10, 10, 10, "TESTE");
  605. Point p2 = new Park("", new Location(12, 12, 12), 0, 0);
  606. points.add(p1);
  607. points.add(p2);
  608. graphController.getGraphHandler().addPoints(points);
  609. graphController.getGraphHandler().insertPath(1, p1, p2, 0, 0, true);
  610.  
  611. Route r = new Route(new Location(10, 10, 10), 1, new Timestamp(0), 0.0);
  612. Route r1 = new Route(new Location(12, 12, 12), 1, new Timestamp(3600000 * 4), 0.0);
  613.  
  614. List<Route> rl = new ArrayList<>();
  615. rl.add(r);
  616. rl.add(r1);
  617.  
  618. graphController.getGraphHandler().setWind(p1, p2, 5.0, 0);
  619.  
  620. Journey journey = new Journey(1, new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 5, null, rl);
  621. journey.getUser().setAverageSpeed(10.5);
  622. double expResult = 2.7056009670732324E-5;
  623. double result = Journey.calculateEnergyDuringJourney(journey, graphController.getGraphHandler());
  624. assertEquals(expResult, result, 0.01);
  625.  
  626. }
  627.  
  628. /**
  629. * Test of calculateBurnedCalories method, of class Journey.
  630. */
  631. @Test
  632. public void testCalculateBurnedCalories() {
  633. System.out.println("calculateBurnedCalories");
  634.  
  635. GraphController graphController = new GraphController(new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0));
  636. Set<Point> points = new HashSet<>();
  637. Point p1 = new TouristicPoint(10, 10, 10, "TESTE");
  638. Point p2 = new Park("", new Location(12, 12, 12), 0, 0);
  639. points.add(p1);
  640. points.add(p2);
  641. graphController.getGraphHandler().addPoints(points);
  642. graphController.getGraphHandler().insertPath(1, p1, p2, 0, 0, true);
  643.  
  644. Route r = new Route(new Location(10, 10, 10), 1, new Timestamp(0), 0.0);
  645. Route r1 = new Route(new Location(12, 12, 12), 1, new Timestamp(3600000 * 4), 0.0);
  646.  
  647. List<Route> rl = new ArrayList<>();
  648. rl.add(r);
  649. rl.add(r1);
  650.  
  651. graphController.getGraphHandler().setWind(p1, p2, 5.0, 0);
  652.  
  653. Journey journey = new Journey(1, new User("", "adminbikeshare@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0), new Timestamp(10), new Bicycle("", 1, 1, "y", 15.6, null), 5, null, rl);
  654.  
  655. double expResult = 5.6102685487062536E7;
  656. double result = Journey.calculateBurnedCalories(journey, graphController.getGraphHandler());
  657. assertEquals(expResult, result, 0.01);
  658.  
  659. journey.setBicycle(new Bicycle("", 2, 2, "y", 15.6, null));
  660.  
  661. expResult = 2.068090551724417E8;
  662. result = Journey.calculateBurnedCalories(journey, graphController.getGraphHandler());
  663. assertEquals(expResult, result, 0.01);
  664. }
  665.  
  666. /**
  667. * Test of getTotalMonth method, of class Invoice.
  668. */
  669. @Test
  670. public void testGetTotalMonth() {
  671. System.out.println("getTotalMonth");
  672. Set<Journey> journeys = new HashSet<>();
  673. Journey j1 = new Journey();
  674. j1.setPrice(10);
  675. Journey j2 = new Journey();
  676. j2.setPrice(12);
  677. j1.setPrice(12);
  678. journeys.add(j1);
  679. journeys.add(j2);
  680. double expResult = 12.0;
  681. double result = Journey.getTotalMonth(journeys);
  682. assertEquals(expResult, result, 0.001);
  683. }
  684.  
  685. @Test
  686. public void testGetSetCredits() {
  687. System.out.println("testgetSetCredits");
  688. Integer exp = 2;
  689. instance2.setCredits(exp);
  690. assertEquals(exp, instance2.getCredits());
  691. }
  692.  
  693. @Test
  694. public void testgetIdBicycle() {
  695. System.out.println("testgetSetCredits");
  696. Bicycle b = new Bicycle("a", 1, 1, "Y", 20.0, "name");
  697. instance2.setIdBicycle(b);
  698. assertEquals(b, instance2.getBicycle());
  699. }
  700.  
  701. @Test
  702. public void testsetUser() {
  703. System.out.println("testgetSetCredits");
  704. User u = new User("", "1161263@isep.ipp.pt", "12345678912", 180.4, 85.6, null, 0, 0);
  705. instance2.setUser(u);
  706. assertEquals(u, instance2.getUser());
  707. }
  708.  
  709. @Test
  710. public void testSetIdReservation() {
  711. System.out.println("test id Reservation");
  712. int exp = 12;
  713. instance2.setIdReservation(exp);
  714. assertEquals(exp, instance2.getIdReservation());
  715. }
  716. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement