Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package project1;
- import org.junit.Assert;
- import org.junit.Test;
- import static org.junit.Assert.*;
- public class TestGeoCountDownTimer {
- @Test
- public void testConstructor1() {
- GeoCountDownTimer s = new GeoCountDownTimer();
- assertEquals(s.toString(),"January 1, 2019");
- // Create more, many more tests
- }
- @Test
- public void testConstructor4(){
- GeoCountDownTimer s1 = new GeoCountDownTimer("5/10/2019");
- GeoCountDownTimer s = new GeoCountDownTimer(s1);
- assertEquals(s1, s);
- }
- @Test
- public void testConstructor2() {
- GeoCountDownTimer s = new GeoCountDownTimer("1/1/2019");
- assertTrue(s.toString().equals("January 1, 2019"));
- // Create more, many more tests
- }
- @Test
- public void testSaveLoad() {
- GeoCountDownTimer s = new GeoCountDownTimer("5/10/2019");
- s.save("xD");
- GeoCountDownTimer s2= new GeoCountDownTimer();
- s2.load("xD");
- assertEquals(s, s2);
- // Create more, many more tests
- }
- @Test (expected = IllegalArgumentException.class)
- public void testConstructor3() {
- GeoCountDownTimer s = new GeoCountDownTimer("2/29/2019");
- assertTrue(s.toDateString().equals("2/29/2019"));
- }
- @Test (expected = IllegalArgumentException.class)
- public void testConstructorBreak() {
- GeoCountDownTimer s = new GeoCountDownTimer("-2/-29/-2019");
- assertTrue(s.toDateString().equals("2/29/2019"));
- }
- @Test
- public void testAddMethod () {
- GeoCountDownTimer s1 = new GeoCountDownTimer(5,10,2019);
- s1.inc(365);
- System.out.println (s1.toDateString().equals("5/9/2020"));
- assertTrue (s1.toDateString().equals("5/9/2020"));
- s1 = new GeoCountDownTimer(5,10,2020);
- for (int i = 0; i < 365; i++)
- s1.inc();
- System.out.println (s1);
- assertTrue (s1.toDateString().equals("5/10/2021"));
- s1 = new GeoCountDownTimer(5,10,2020);
- System.out.println ("Start:" + s1);
- for (int i = 0; i < 31665; i++)
- s1.inc();
- System.out.println ("Middle:" + s1);
- for (int i = 0; i < 31665; i++)
- s1.dec();
- System.out.println ("End: " + s1);
- }
- // must have a separate test for each Exception
- @Test (expected = IllegalArgumentException.class)
- public void testContuctor1() {
- new GeoCountDownTimer(2,-3,-3);
- }
- @Test (expected = IllegalArgumentException.class)
- public void testContuctor2() {
- new GeoCountDownTimer("2,-3/-3");
- }
- @Test (expected = IllegalArgumentException.class)
- public void testDecBreak()
- {
- GeoCountDownTimer s = new GeoCountDownTimer();
- s.dec(-5);
- }
- @Test (expected = IllegalArgumentException.class)
- public void testIncBreak()
- {
- GeoCountDownTimer s = new GeoCountDownTimer();
- s.inc(-5);
- }
- @Test (expected = IllegalArgumentException.class)
- public void testEqualsNull()
- {
- GeoCountDownTimer s = new GeoCountDownTimer(2,5,2016);
- s.equals(null);
- }
- @Test (expected = IllegalArgumentException.class)
- public void testEqualsBadObject()
- {
- GeoCountDownTimer s = new GeoCountDownTimer(2,5,2016);
- s.equals(new Object());
- }
- @Test
- public void testloadBreak()
- {
- GeoCountDownTimer s = new GeoCountDownTimer();
- s.load("doesntexistststst");
- }
- @Test
- public void testEqual () {
- GeoCountDownTimer s1 = new GeoCountDownTimer(5,9,3000);
- GeoCountDownTimer s2 = new GeoCountDownTimer(6,1,2019);
- GeoCountDownTimer s3 = new GeoCountDownTimer(5,5,2019);
- GeoCountDownTimer s4 = new GeoCountDownTimer(5,9,3000);
- assertEquals(s1, s4);
- assertFalse(s1.equals(s2));
- assertTrue (s1.equals(s4));
- }
- @Test
- public void testInc() {
- GeoCountDownTimer s = new GeoCountDownTimer(9,11,2019);
- for (int i=0; i<31046; i++){
- s.inc();
- }
- assertEquals(s, new GeoCountDownTimer("9/11/2104"));
- }
- @Test
- public void testIncSmall() {
- GeoCountDownTimer s = new GeoCountDownTimer(9,11,2019);
- for (int i=0; i<3000; i++){
- s.inc();
- }
- assertEquals(s, new GeoCountDownTimer("11/28/2027"));
- }
- @Test
- public void testIncNum() {
- GeoCountDownTimer s = new GeoCountDownTimer(9,11,2019);
- s.inc(31046);
- assertEquals(s, new GeoCountDownTimer("9/11/2104"));
- // GeoCountDownTimer
- }
- @Test
- public void testDec() {
- GeoCountDownTimer s = new GeoCountDownTimer(9,11,2104);
- for (int i=0; i<31046; i++){
- s.dec();
- }
- assertEquals(s, new GeoCountDownTimer("9/11/2019"));
- }
- @Test
- public void testDecNum() {
- GeoCountDownTimer s = new GeoCountDownTimer(9,11,2104);
- s.dec(31046);
- assertEquals(s, new GeoCountDownTimer("9/11/2019"));
- }
- @Test
- public void testDaysToGo () {
- GeoCountDownTimer s1 = new GeoCountDownTimer(1,1,2020);
- assertEquals(s1.daysToGo("1/1/2020"), 0);
- assertEquals(s1.daysToGo("1/1/2019"), 365);
- // assertEquals(s1.daysToGo("1/1/2016"), 365);
- }
- @Test
- public void testCompareTo () {
- GeoCountDownTimer s1 = new GeoCountDownTimer(5,9,2019);
- GeoCountDownTimer s2 = new GeoCountDownTimer(6,1,2019);
- GeoCountDownTimer s3 = new GeoCountDownTimer(5,8,2019);
- GeoCountDownTimer s4 = new GeoCountDownTimer(5,9,2019);
- assertTrue (s2.compareTo(s1) > 0);
- assertTrue (s3.compareTo(s1) < 0);
- assertTrue (s1.compareTo(s4) == 0);
- }
- @Test
- public void testLoadSave () {
- GeoCountDownTimer s1 = new GeoCountDownTimer(5,9,2019);
- GeoCountDownTimer s2 = new GeoCountDownTimer(5,9,2019);
- s1.save("file1");
- s1 = new GeoCountDownTimer(1,1,2020); // resets to zero
- s1.load("file1");
- assertTrue (s2.equals(s1));
- }
- @Test
- public void testDaysToGo2 () {
- GeoCountDownTimer s1 = new GeoCountDownTimer(2,9,2019);
- assertTrue (s1.daysToGo("2/1/2019") == 8);
- assertTrue (s1.daysToGo("2/8/2019") == 1);
- assertTrue (s1.daysToGo("2/9/2019") == 0);
- s1 = new GeoCountDownTimer(2,9,5019);
- System.out.println (s1.daysToGo("2/9/2019"));
- }
- @Test (expected = IllegalArgumentException.class)
- public void testfuture(){
- GeoCountDownTimer s1 = new GeoCountDownTimer(12,1,2019);
- s1.daysInTheFuture(0);
- }
- @Test
- public void testfuture2(){
- GeoCountDownTimer s1 = new GeoCountDownTimer(12,1,2019);
- assertEquals(s1.daysInTheFuture(10).toDateString() , "12/11/2019");
- }
- @Test
- public void testfuture3(){
- GeoCountDownTimer s1 = new GeoCountDownTimer(9,17,2019);
- assertEquals(s1.daysInTheFuture(200000).toDateString() , "4/17/2567");
- }
- @Test (expected = IllegalArgumentException.class)
- public void testfuture4(){
- GeoCountDownTimer s1 = new GeoCountDownTimer(12,1,2019);
- s1.daysInTheFuture(-1);
- }
- @Test (expected = IllegalArgumentException.class)
- public void testfuture5(){
- GeoCountDownTimer s1 = new GeoCountDownTimer(12,1,2019);
- s1.daysInTheFuture(-200000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement