Giter Club home page Giter Club logo

javaworkspace's People

Watchers

 avatar  avatar

javaworkspace's Issues

That is NOT how a JUnit test works...

THIS is a JUnit test. O.o
I wrote this a year ago in the same Java class you are taking currently... the code kinda sucks, but you get the idea :-)

import org.junit.After;
import org.junit.AfterClass;
import org.unit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

public class MyDateTest {

    private MyDate d;
    private MyDate d1;
    private MyDate d2;
    private MyDate d3;

    @Before
    public void setUp() {
        d = new MyDate(2015,5,5);       // THE JAVA HOMEWORK DEADLINE
        d1 = new MyDate();
        d2 = new MyDate(2000,2,26);     // My 7th birthday =)
        d3 = new MyDate(2000,2,29);
    }

    @Test(expected= IllegalArgumentException.class)
    public void notLeap(){
        MyDate dtest = new MyDate(2001, 2, 29);
    }
    @Test(expected= IllegalArgumentException.class)
    public void notLeap1(){
        MyDate dtest = new MyDate(1700, 2, 29);
    }
    @Test(expected= IllegalArgumentException.class)
    public void invalidDate(){
        MyDate dtest = new MyDate(2001, 12, 32);
    }
    @Test(expected= IllegalArgumentException.class)
    public void invalidDate1(){
        MyDate dtest = new MyDate(2001, 13, 3);
    }
    @Test(expected= IllegalArgumentException.class)
    public void invalidDate2(){
        MyDate dtest = new MyDate(2001, 0, 3);
    }
    @Test(expected= IllegalArgumentException.class)
    public void invalidDate3(){
        MyDate dtest = new MyDate();
        dtest.set(-2001, 12, -3);
    }
    @Test(expected= IndexOutOfBoundsException.class)
    public void invalidGet(){
        d1.get(3);
    }
    @Test(expected= IndexOutOfBoundsException.class)
    public void invalidGet1(){
        d1.get(-1);
    }

    @Test
    public void get_set(){          // A not-so-interesting fact:
        d1.set(2009,10,26);         // This is the first time I met my boyfriend.
        assertEquals("Get/set does not return desired value",d1.get(0),2009);
        assertEquals("Get/set does not return desired value",d1.get(1),10);
        assertEquals("Get/set does not return desired value",d1.get(2),26);
    }
    @Test
    public void compare(){
        d2.add(3);
        assertTrue("(1)Should be equal",d2.equals(d3));
        assertFalse("(2)Should not be equal",d2.equals(d1));
        assertFalse("(3)Different type comparison failed",d2.equals(23333));

        assertTrue("(4)Should be greater than",d3.compareTo(d1) > 0);
        assertTrue("(5)Should be equal",d3.compareTo(d2) == 0);        
    }
    @Test(expected= NullPointerException.class)
    public void compareNull(){
        MyDate dtest = null;
        d2.equals(test);
    }
    @Test
    public void weekday(){
        assertTrue("(1)Wrong day of the week!",d.getWeekday() == MyDate.weekday.TUESDAY);
        assertTrue("(2)Wrong day of the week!",d2.getWeekday() == MyDate.weekday.SATURDAY);
    }
    @Test
    public void add(){
        d2.add(366);
        assertTrue("(1) Wrong addition in leap year",d2.equals(new MyDate(2001,2,26)));
        d2.add(366);
        assertTrue("(2) Wrong addition in non-leap year", d2.equals(new MyDate(2002,2,27)));
        d2.add(-367);
        assertTrue("(3) Wrong negative addition in non-leap year", d2.equals(new MyDate(2001,2,25)));
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.