Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 KB | None | 0 0
  1. package project1;
  2.  
  3. import org.junit.Assert;
  4. import org.junit.Test;
  5. import static org.junit.Assert.*;
  6.  
  7. public class TestGeoCountDownTimer {
  8.  
  9. @Test
  10. public void testConstructor1() {
  11. GeoCountDownTimer s = new GeoCountDownTimer();
  12. assertEquals(s.toString(),"January 1, 2019");
  13.  
  14.  
  15. // Create more, many more tests
  16.  
  17. }
  18.  
  19. @Test
  20. public void testConstructor4(){
  21. GeoCountDownTimer s1 = new GeoCountDownTimer("5/10/2019");
  22. GeoCountDownTimer s = new GeoCountDownTimer(s1);
  23. assertEquals(s1, s);
  24. }
  25.  
  26. @Test
  27. public void testConstructor2() {
  28. GeoCountDownTimer s = new GeoCountDownTimer("1/1/2019");
  29. assertTrue(s.toString().equals("January 1, 2019"));
  30.  
  31. // Create more, many more tests
  32.  
  33. }
  34.  
  35. @Test
  36. public void testSaveLoad() {
  37. GeoCountDownTimer s = new GeoCountDownTimer("5/10/2019");
  38. s.save("xD");
  39. GeoCountDownTimer s2= new GeoCountDownTimer();
  40. s2.load("xD");
  41. assertEquals(s, s2);
  42.  
  43. // Create more, many more tests
  44.  
  45. }
  46.  
  47.  
  48.  
  49. @Test (expected = IllegalArgumentException.class)
  50. public void testConstructor3() {
  51. GeoCountDownTimer s = new GeoCountDownTimer("2/29/2019");
  52. assertTrue(s.toDateString().equals("2/29/2019"));
  53.  
  54. }
  55. @Test (expected = IllegalArgumentException.class)
  56. public void testConstructorBreak() {
  57. GeoCountDownTimer s = new GeoCountDownTimer("-2/-29/-2019");
  58. assertTrue(s.toDateString().equals("2/29/2019"));
  59.  
  60. }
  61.  
  62.  
  63. @Test
  64. public void testAddMethod () {
  65. GeoCountDownTimer s1 = new GeoCountDownTimer(5,10,2019);
  66. s1.inc(365);
  67. System.out.println (s1.toDateString().equals("5/9/2020"));
  68. assertTrue (s1.toDateString().equals("5/9/2020"));
  69.  
  70. s1 = new GeoCountDownTimer(5,10,2020);
  71.  
  72. for (int i = 0; i < 365; i++)
  73. s1.inc();
  74. System.out.println (s1);
  75. assertTrue (s1.toDateString().equals("5/10/2021"));
  76.  
  77. s1 = new GeoCountDownTimer(5,10,2020);
  78.  
  79. System.out.println ("Start:" + s1);
  80. for (int i = 0; i < 31665; i++)
  81. s1.inc();
  82. System.out.println ("Middle:" + s1);
  83.  
  84. for (int i = 0; i < 31665; i++)
  85. s1.dec();
  86. System.out.println ("End: " + s1);
  87.  
  88. }
  89.  
  90.  
  91. // must have a separate test for each Exception
  92. @Test (expected = IllegalArgumentException.class)
  93. public void testContuctor1() {
  94. new GeoCountDownTimer(2,-3,-3);
  95. }
  96.  
  97. @Test (expected = IllegalArgumentException.class)
  98. public void testContuctor2() {
  99. new GeoCountDownTimer("2,-3/-3");
  100.  
  101. }
  102.  
  103. @Test (expected = IllegalArgumentException.class)
  104. public void testDecBreak()
  105. {
  106. GeoCountDownTimer s = new GeoCountDownTimer();
  107. s.dec(-5);
  108. }
  109.  
  110. @Test (expected = IllegalArgumentException.class)
  111. public void testIncBreak()
  112. {
  113. GeoCountDownTimer s = new GeoCountDownTimer();
  114. s.inc(-5);
  115. }
  116.  
  117. @Test (expected = IllegalArgumentException.class)
  118. public void testEqualsNull()
  119. {
  120. GeoCountDownTimer s = new GeoCountDownTimer(2,5,2016);
  121. s.equals(null);
  122. }
  123.  
  124. @Test (expected = IllegalArgumentException.class)
  125. public void testEqualsBadObject()
  126. {
  127. GeoCountDownTimer s = new GeoCountDownTimer(2,5,2016);
  128. s.equals(new Object());
  129. }
  130.  
  131. @Test
  132. public void testloadBreak()
  133. {
  134. GeoCountDownTimer s = new GeoCountDownTimer();
  135. s.load("doesntexistststst");
  136.  
  137. }
  138.  
  139. @Test
  140. public void testEqual () {
  141. GeoCountDownTimer s1 = new GeoCountDownTimer(5,9,3000);
  142. GeoCountDownTimer s2 = new GeoCountDownTimer(6,1,2019);
  143. GeoCountDownTimer s3 = new GeoCountDownTimer(5,5,2019);
  144. GeoCountDownTimer s4 = new GeoCountDownTimer(5,9,3000);
  145.  
  146. assertEquals(s1, s4);
  147. assertFalse(s1.equals(s2));
  148. assertTrue (s1.equals(s4));
  149.  
  150.  
  151.  
  152. }
  153.  
  154. @Test
  155. public void testInc() {
  156. GeoCountDownTimer s = new GeoCountDownTimer(9,11,2019);
  157. for (int i=0; i<31046; i++){
  158. s.inc();
  159. }
  160. assertEquals(s, new GeoCountDownTimer("9/11/2104"));
  161. }
  162. @Test
  163. public void testIncSmall() {
  164. GeoCountDownTimer s = new GeoCountDownTimer(9,11,2019);
  165. for (int i=0; i<3000; i++){
  166. s.inc();
  167. }
  168. assertEquals(s, new GeoCountDownTimer("11/28/2027"));
  169. }
  170.  
  171. @Test
  172. public void testIncNum() {
  173. GeoCountDownTimer s = new GeoCountDownTimer(9,11,2019);
  174. s.inc(31046);
  175. assertEquals(s, new GeoCountDownTimer("9/11/2104"));
  176. // GeoCountDownTimer
  177. }
  178.  
  179. @Test
  180. public void testDec() {
  181. GeoCountDownTimer s = new GeoCountDownTimer(9,11,2104);
  182. for (int i=0; i<31046; i++){
  183. s.dec();
  184. }
  185. assertEquals(s, new GeoCountDownTimer("9/11/2019"));
  186. }
  187.  
  188. @Test
  189. public void testDecNum() {
  190. GeoCountDownTimer s = new GeoCountDownTimer(9,11,2104);
  191. s.dec(31046);
  192. assertEquals(s, new GeoCountDownTimer("9/11/2019"));
  193. }
  194.  
  195. @Test
  196. public void testDaysToGo () {
  197. GeoCountDownTimer s1 = new GeoCountDownTimer(1,1,2020);
  198. assertEquals(s1.daysToGo("1/1/2020"), 0);
  199.  
  200. assertEquals(s1.daysToGo("1/1/2019"), 365);
  201. // assertEquals(s1.daysToGo("1/1/2016"), 365);
  202. }
  203.  
  204.  
  205. @Test
  206. public void testCompareTo () {
  207. GeoCountDownTimer s1 = new GeoCountDownTimer(5,9,2019);
  208. GeoCountDownTimer s2 = new GeoCountDownTimer(6,1,2019);
  209. GeoCountDownTimer s3 = new GeoCountDownTimer(5,8,2019);
  210. GeoCountDownTimer s4 = new GeoCountDownTimer(5,9,2019);
  211.  
  212. assertTrue (s2.compareTo(s1) > 0);
  213. assertTrue (s3.compareTo(s1) < 0);
  214. assertTrue (s1.compareTo(s4) == 0);
  215.  
  216. }
  217.  
  218. @Test
  219. public void testLoadSave () {
  220. GeoCountDownTimer s1 = new GeoCountDownTimer(5,9,2019);
  221. GeoCountDownTimer s2 = new GeoCountDownTimer(5,9,2019);
  222.  
  223. s1.save("file1");
  224. s1 = new GeoCountDownTimer(1,1,2020); // resets to zero
  225. s1.load("file1");
  226. assertTrue (s2.equals(s1));
  227.  
  228. }
  229.  
  230. @Test
  231. public void testDaysToGo2 () {
  232. GeoCountDownTimer s1 = new GeoCountDownTimer(2,9,2019);
  233. assertTrue (s1.daysToGo("2/1/2019") == 8);
  234. assertTrue (s1.daysToGo("2/8/2019") == 1);
  235. assertTrue (s1.daysToGo("2/9/2019") == 0);
  236.  
  237. s1 = new GeoCountDownTimer(2,9,5019);
  238. System.out.println (s1.daysToGo("2/9/2019"));
  239. }
  240.  
  241. @Test (expected = IllegalArgumentException.class)
  242. public void testfuture(){
  243. GeoCountDownTimer s1 = new GeoCountDownTimer(12,1,2019);
  244. s1.daysInTheFuture(0);
  245. }
  246.  
  247. @Test
  248. public void testfuture2(){
  249. GeoCountDownTimer s1 = new GeoCountDownTimer(12,1,2019);
  250. assertEquals(s1.daysInTheFuture(10).toDateString() , "12/11/2019");
  251. }
  252.  
  253. @Test
  254. public void testfuture3(){
  255. GeoCountDownTimer s1 = new GeoCountDownTimer(9,17,2019);
  256. assertEquals(s1.daysInTheFuture(200000).toDateString() , "4/17/2567");
  257. }
  258.  
  259. @Test (expected = IllegalArgumentException.class)
  260. public void testfuture4(){
  261. GeoCountDownTimer s1 = new GeoCountDownTimer(12,1,2019);
  262. s1.daysInTheFuture(-1);
  263.  
  264. }
  265.  
  266. @Test (expected = IllegalArgumentException.class)
  267. public void testfuture5(){
  268. GeoCountDownTimer s1 = new GeoCountDownTimer(12,1,2019);
  269. s1.daysInTheFuture(-200000);
  270.  
  271. }
  272. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement