Skip to content

Instantly share code, notes, and snippets.

@unclebob
Created September 17, 2010 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unclebob/584490 to your computer and use it in GitHub Desktop.
Save unclebob/584490 to your computer and use it in GitHub Desktop.
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static payroll.PayCalculator.calculate;
public class PayCalculatorTest {
private void assertPay(double expectedPay, double actualPay) {
assertEquals(expectedPay, actualPay, .001);
}
@Test
public void ZeroHours_ShouldBeZero() throws Exception {
assertPay(0.0, calculate(0, 10, true));
assertPay(0.0, calculate(0, 10, false));
}
@Test(expected = RuntimeException.class)
public void LessThanZeroHours_ShouldThrow() throws Exception {
calculate(-1, 10, true);
}
@Test(expected = RuntimeException.class)
public void MoreThan80Hours_ShouldThrow() throws Exception {
calculate(81, 10, true);
}
@Test
public void FortyHours_StraightTime() throws Exception {
assertPay(400.0, calculate(40, 10, true));
assertPay(400.0, calculate(40, 10, false));
}
@Test
public void FiftyHoursHourly_TimeAndHalf() throws Exception {
assertPay(550.0, calculate(50, 10, true));
}
@Test
public void FiftyHoursNonHourly_StraightTime() throws Exception {
assertPay(500.0, calculate(50, 10, false));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment