uchanka / javaworkspace Goto Github PK
View Code? Open in Web Editor NEWA repository for Java programming curriculum
A repository for Java programming curriculum
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)));
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.