Skip to content

Instantly share code, notes, and snippets.

@kevinrutherford
Created June 2, 2013 18:21
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 kevinrutherford/5694373 to your computer and use it in GitHub Desktop.
Save kevinrutherford/5694373 to your computer and use it in GitHub Desktop.
import static org.junit.Assert.*;
import org.junit.Test;
public class PotterTester {
private double price(int... books) {
return 0.0;
}
@Test
public void testBasics() {
assertEquals(0, price(), 0.0);
assertEquals(8, price(0), 0.0);
assertEquals(8, price(1), 0.0);
assertEquals(8, price(2), 0.0);
assertEquals(8, price(3), 0.0);
assertEquals(8, price(4), 0.0);
assertEquals(8 * 2, price(0, 0), 0.0);
assertEquals(8 * 3, price(1, 1, 1), 0.0);
}
@Test
public void testSimpleDiscounts() {
assertEquals(8 * 2 * 0.95, price(0, 1), 0.0);
assertEquals(8 * 3 * 0.9, price(0, 2, 4), 0.0);
assertEquals(8 * 4 * 0.8, price(0, 1, 2, 4), 0.0);
assertEquals(8 * 5 * 0.75, price(0, 1, 2, 3, 4), 0.0);
}
@Test
public void testSeveralDiscounts() {
assertEquals(8 + (8 * 2 * 0.95), price(0, 0, 1), 0.0);
assertEquals(2 * (8 * 2 * 0.95), price(0, 0, 1, 1), 0.0);
assertEquals((8 * 4 * 0.8) + (8 * 2 * 0.95), price(0, 0, 1, 2, 2, 3), 0.0);
assertEquals(8 + (8 * 5 * 0.75), price(0, 1, 1, 2, 3, 4), 0.0);
}
@Test
public void testEdgeCases() {
assertEquals(2 * (8 * 4 * 0.8), price(0, 0, 1, 1, 2, 2, 3, 4), 0.0);
assertEquals(3 * (8 * 5 * 0.75) + 2 * (8 * 4 * 0.8),
price(0, 0, 0, 0, 0,
1, 1, 1, 1, 1,
2, 2, 2, 2,
3, 3, 3, 3, 3,
4, 4, 4, 4), 0.0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment