Advertisement
Guest User

Untitled

a guest
Sep 11th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. package tests;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import org.junit.Assert;
  6. import org.junit.Test;
  7.  
  8. import controller.LoginController;
  9. import controller.QueryController;
  10. import controller.RegistrationController;
  11. import entity.User;
  12. import exceptions.GalaxyNotExistsException;
  13. import exceptions.PositionTableEmptyException;
  14.  
  15. public class QueryTest {
  16. private QueryController cntr = QueryController.getInstance();
  17. private String userID;
  18. private String password;
  19.  
  20. @Test
  21. public void testRegistrationLogin() {
  22. RegistrationController controller = RegistrationController.getInstance();
  23. LoginController controller2 = LoginController.getInstance();
  24. try {
  25. controller.registerUser("mario", "de angelis", "mariodea", "prova@prova", "password", 1);
  26. controller.registerUser("giulia", "frascaria", "giuliafra", "prova1@prova1", "password", 0);
  27. userID = "mariodea";
  28. password= "password";
  29. User user = controller2.login(userID, password);
  30. Assert.assertEquals(userID, user.getUserID());
  31. Assert.assertEquals(password, user.getPassword());
  32. Assert.assertEquals(1, user.getAccountType());
  33. userID = "giuliafra";
  34. user = controller2.login(userID, password);
  35. Assert.assertEquals(userID, user.getUserID());
  36. Assert.assertEquals(password, user.getPassword());
  37. Assert.assertEquals(0, user.getAccountType());
  38. } catch (Exception e) {
  39. e.printStackTrace();
  40. fail("Errore");
  41. }
  42. }
  43.  
  44. @Test
  45. public void testFindGalaxy() {
  46. try {
  47. String[][] result = cntr.findGalaxy("izw1");
  48. Assert.assertEquals("izw1", result[0][0]);
  49. } catch (GalaxyNotExistsException e) {
  50. System.err.println("Galassia non trovata, assicurarsi di aver caricato il file con le galassie.");
  51. fail("Galassia 'izw1' non trovata");
  52. } catch (Exception e) {
  53. e.printStackTrace();
  54. fail("Galassie non corrispondento");
  55. }
  56. }
  57.  
  58. @Test
  59. public void testInCircle() {
  60. try {
  61. String[] inputs = {"240", "1", "0_11_6.5412", "-_12_6_27.66"};
  62. String[][] result = cntr.galaxyInACircle(inputs);
  63. for (String s : result[0]) {
  64. if (s.equals("mrk938")) {
  65. return;
  66. }
  67. }
  68. fail("Galassia non trovata");
  69. } catch (PositionTableEmptyException e){
  70. System.err.println("Non ci sono posizioni memorizzate.");
  71. fail("Galassia non trovata");
  72. } catch (Exception e) {
  73. e.printStackTrace();
  74. fail("Errore");
  75. }
  76. }
  77.  
  78. @Test
  79. public void testByRed() {
  80. try {
  81. String[] inputs = {"0.4", ">", "240"};
  82. String[][] result = cntr.findRedShift(inputs);
  83. for (String s : result[0]) {
  84. if (s.equals("iras09104+4109")) {
  85. return;
  86. }
  87. }
  88. fail("Risultato errato");
  89. } catch (Exception e) {
  90. e.printStackTrace();
  91. fail("Errore");
  92. }
  93. }
  94.  
  95. @Test
  96. public void testFindRow() {
  97. try {
  98. String[] flux = {"siv10"};
  99. String[][] result = cntr.findFluxes("mrk938", flux);
  100. for (String s : result[7]) {
  101. if (s.equals("siv10") && result[4][0].equals("1.46") && result[5][0].equals("0")) {
  102. return;
  103. }
  104. }
  105. fail("Risultato errato");
  106. } catch (Exception e) {
  107. e.printStackTrace();
  108. fail("Errore");
  109. }
  110. }
  111.  
  112. @Test
  113. public void testRatio() {
  114. try {
  115. String[][] result = cntr.fluxRatio("mrk938", "siv10", "nev14", null, null);
  116. float ratio = Float.parseFloat(result[0][0]);
  117. if (ratio > 0.66 && ratio < 0.67) {
  118. return;
  119. }
  120. fail("Risultato errato");
  121. } catch (Exception e) {
  122. e.printStackTrace();
  123. fail("Errore");
  124. }
  125. }
  126.  
  127. @Test
  128. public void testFluxStats() {
  129. try {
  130. String[][] result = cntr.fluxStats("s1", "oi63", "oi63", null, 5);
  131. float avg = Float.parseFloat(result[0][0]);
  132. float med = Float.parseFloat(result[0][1]);
  133. float dev = Float.parseFloat(result[0][2]);
  134. float devAbs = Float.parseFloat(result[0][3]);
  135. if (avg>1.4 && avg<1.5 && med==1 && devAbs==1 && dev>1.3 && dev<1.4) {
  136. return;
  137. }
  138. fail("Risultato errato");
  139. } catch (Exception e) {
  140. e.printStackTrace();
  141. fail("Errore");
  142. }
  143. }
  144.  
  145. @Test
  146. public void testRatioRowCont() {
  147. try {
  148. String[][] result = cntr.fluxContRowRatio("izw1", "oi63", "c");
  149. float ratio = Float.parseFloat(result[0][0]);
  150. if (ratio > 1.7 && ratio < 1.8) {
  151. return;
  152. }
  153. fail("Risultato errato");
  154. } catch (Exception e) {
  155. e.printStackTrace();
  156. fail("Errore");
  157. }
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement