Last active
August 29, 2015 14:06
-
-
Save QuantumFractal/c7ea72c52981fc178639 to your computer and use it in GitHub Desktop.
CS228 Project 2 Unit Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.iastate.cs228.hw2; | |
import org.junit.Test; | |
import org.junit.Before; | |
import static org.junit.Assert.assertTrue; | |
import static org.junit.Assert.assertEquals; | |
/** | |
* @author ThomasMol | |
* | |
* Should test your discrepancy class for any... ahem.. discrepancies..... | |
* | |
* Note, there's a ton of ways to check the compare too method, but I don't fee | |
* like writing out a new discrepancy for each level. Sorry. | |
*/ | |
public class DiscrepancyTest { | |
Discrepancy dis1; | |
Discrepancy dis2; | |
Discrepancy dis3; | |
@Before | |
public void initialize() | |
{ | |
//Make two equal and one different discrepancies. | |
dis1 = new Discrepancy(false, 10, "Thomas", 10, ", Tom"); | |
dis2 = new Discrepancy(false, 10, "Thomas", 10, ", Tom"); | |
dis3 = new Discrepancy(true, -5, "William", 10, ", Bill"); | |
} | |
@Test | |
public void testCompareTo() | |
{ | |
assertTrue("Dis1 compared to Dis2 should be the same", 0 == dis1.compareTo(dis2)); | |
assertTrue("Dis1 compared to itself should be the same", 0 == dis1.compareTo(dis1)); | |
assertTrue("Dis1 compared to Dis3 should be greater than 0", 0 < dis1.compareTo(dis3)); | |
} | |
@Test | |
public void testStringTo() | |
{ | |
assertEquals("Dis1 output should be +10, Thomas, 10, Tom ", " +10, Thomas, 10, Tom", dis1.toString()); | |
assertEquals("Dis3 output should be *-5, William, 10, Bill", "*-5, William, 10, Bill", dis3.toString()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.iastate.cs228.hw2; | |
import org.junit.Test; | |
import org.junit.Before; | |
import static org.junit.Assert.assertTrue; | |
import static org.junit.Assert.assertFalse; | |
import static org.junit.Assert.assertEquals; | |
/** | |
* | |
* @author ThomasMoll | |
* | |
*/ | |
public class EmployerTest { | |
Employer emp1; | |
Employer emp2; | |
Employer emp3; | |
Filer guy1; | |
String emName; | |
int emID; | |
String emeeName; | |
int emeeSSN; | |
int emeeWage; | |
@Before | |
public void initialize() | |
{ | |
emName = "Google"; | |
emID = 0; | |
emeeName = "Larry Page"; | |
emeeSSN = 123456789; | |
emeeWage= 300; | |
//Make two identical and one different for .equals | |
emp1 = new Employer(emName, emID, emeeName, emeeSSN, emeeWage); | |
emp2 = new Employer(emName, emID, emeeName, emeeSSN, emeeWage); | |
emp3 = new Employer("Yahoo", 222333555, "Tom", 000111222, emeeWage); | |
//Make a filer | |
guy1 = new Filer(emeeName, emeeSSN, emeeWage); | |
} | |
@Test | |
public void testEquals() | |
{ | |
assertEquals("Emp1 and Emp2 should be identical.", emp1, emp2); | |
assertFalse("Emp3 and Emp1 should be different.", emp1.equals(emp3)); | |
} | |
@Test | |
public void testSameEmployer() | |
{ | |
assertTrue("Emp1 and Emp2 should have the same employer.", emp1.sameEmployer(emp2)); | |
assertFalse("Emp1 and Emp3 should have DIFFERENT employers.", emp1.sameEmployer(emp3)); | |
} | |
@Test | |
public void testSameEmployee() | |
{ | |
assertTrue("Emp1 should have the same employee as guy1.", emp1.sameEmployee(guy1)); | |
assertFalse("Emp3 should NOT have the same employee as guy1.", emp3.sameEmployee(guy1)); | |
} | |
@Test | |
public void testGetMethods() | |
{ | |
assertEquals("Employer Name should be the same.", emName, emp1.getName()); | |
assertEquals("Employer ID should be the same.", emID, emp1.getID()); | |
assertEquals("Employee Name should be the same.", emeeName, emp1.getEmployeeName()); | |
assertEquals("Employee SSN should be the same.", emeeSSN, emp1.getEmployeeSSN()); | |
assertEquals("Employee Wages should be the same.", emeeWage, emp1.getEmployeeWages()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.iastate.cs228.hw2; | |
import org.junit.Test; | |
import org.junit.Before; | |
import static org.junit.Assert.assertEquals; | |
/** | |
* | |
* @author ThomasMoll | |
* | |
*/ | |
public class FilerTest { | |
Filer testFiler; | |
String name; | |
int ssn; | |
int income; | |
@Before | |
public void initialize() | |
{ | |
name = "Thomas"; | |
ssn = 123456789; | |
income = 50; | |
testFiler = new Filer(name, ssn, income); | |
} | |
@Test | |
public void testGetName() | |
{ | |
assertEquals("Name is the same once Filer is constructed.", testFiler.getName(), name); | |
} | |
@Test | |
public void testGetSSN() | |
{ | |
assertEquals("SSN is the same once Filer is constructed.", testFiler.getSSN(), ssn); | |
} | |
@Test | |
public void testGetIncome() | |
{ | |
assertEquals("Income is the same once Filer is constructed.", testFiler.getIncome(), income); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Feel free to leave comments either here, or on black board if you see any errors.