Last active
August 29, 2015 13:56
-
-
Save chischaschos/9055568 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import static org.junit.Assert.assertEquals; | |
import org.junit.Test; | |
import org.junit.Ignore; | |
import org.junit.Rule; | |
import org.junit.Before; | |
import org.junit.rules.ExpectedException; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.JUnit4; | |
import static org.junit.Assert.assertFalse; | |
import static org.junit.Assert.assertTrue; | |
import static org.junit.Assert.assertArrayEquals; | |
/** | |
* Tests for {@link Percolation}. | |
* | |
* @author [email protected] (chischachos) | |
*/ | |
@RunWith(JUnit4.class) | |
public class PercolationTest { | |
@Rule | |
public ExpectedException noException = ExpectedException.none(); | |
private Percolation percolation; | |
@Before | |
public void setup() { | |
percolation = new Percolation(5); | |
} | |
@Test | |
public void isOpenWithinLimits() { | |
for(int x = 1; x <= 5; x++) { | |
for(int y = 1; y <= 5; y++) { | |
assertFalse(percolation.isOpen(y, x)); | |
} | |
} | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void isOpenOutOfLimits1() { | |
percolation.isOpen(0, 0); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void isOpenOutOfLimits2() { | |
percolation.isOpen(1, 0); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void isOpenOutOfLimits3() { | |
percolation.isOpen(6, 6); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void isOpenOutOfLimits4() { | |
percolation.isOpen(1, 6); | |
} | |
@Test | |
public void openWithinLimits() { | |
percolation.open(1, 1); | |
assertTrue(percolation.isOpen(1, 1)); | |
percolation.open(2, 2); | |
assertTrue(percolation.isOpen(2, 2)); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void openOutOfLimits1() { | |
percolation.open(0, 0); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void openOutOfLimits2() { | |
percolation.open(1, 0); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void openOutOfLimits3() { | |
percolation.open(6, 6); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void openOutOfLimits4() { | |
percolation.open(1, 6); | |
} | |
@Test | |
public void isFullWithinLimits() { | |
for(int x = 1; x <= 5; x++) { | |
for(int y = 1; y <= 5; y++) { | |
assertFalse(percolation.isFull(y, x)); | |
} | |
} | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void isFullOutOfLimits1() { | |
percolation.isFull(0, 0); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void isFullOutOfLimits2() { | |
percolation.isFull(1, 0); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void isFullOutOfLimits3() { | |
percolation.isFull(6, 6); | |
} | |
@Test(expected = IndexOutOfBoundsException.class) | |
public void isFullOutOfLimits4() { | |
percolation.isFull(1, 6); | |
} | |
@Test | |
public void openFullSite() { | |
percolation.open(1, 1); | |
assertTrue(percolation.isFull(1, 1)); | |
percolation.open(2, 1); | |
assertTrue(percolation.isFull(2, 1)); | |
percolation.open(3, 2); | |
assertFalse(percolation.isFull(3, 2)); | |
} | |
@Test | |
public void test1() { | |
assertFalse(percolation.percolates()); | |
percolation.open(1, 1); | |
assertFalse(percolation.percolates()); | |
percolation.open(2, 1); | |
assertFalse(percolation.percolates()); | |
percolation.open(3, 1); | |
assertFalse(percolation.percolates()); | |
percolation.open(3, 2); | |
assertFalse(percolation.percolates()); | |
percolation.open(4, 2); | |
assertFalse(percolation.percolates()); | |
percolation.open(5, 2); | |
assertTrue(percolation.percolates()); | |
} | |
@Test public void test2() { | |
Percolation percolation = new Percolation(6); | |
percolation.open(1, 6); | |
assertTrue(percolation.isOpen(1, 6)); | |
assertTrue(percolation.isFull(1, 6)); | |
assertFalse(percolation.percolates()); | |
percolation = new Percolation(8); | |
percolation.open(1, 3); | |
assertTrue(percolation.isOpen(1, 3)); | |
assertTrue(percolation.isFull(1, 3)); | |
assertFalse(percolation.percolates()); | |
percolation.open(1, 6); | |
assertTrue(percolation.isOpen(1, 6)); | |
assertTrue(percolation.isFull(1, 6)); | |
assertFalse(percolation.percolates()); | |
} | |
//@Test | |
//@Ignore | |
//public void translateCoordinate() { | |
//assertEquals(0, percolation.translateCoordinate(1, 1)); | |
//assertEquals(1, percolation.translateCoordinate(1, 2)); | |
//assertEquals(5, percolation.translateCoordinate(2, 1)); | |
//assertEquals(6, percolation.translateCoordinate(2, 2)); | |
//assertEquals(24, percolation.translateCoordinate(5, 5)); | |
//assertEquals(-1, percolation.translateCoordinate(0, 1)); | |
//assertEquals(-1, percolation.translateCoordinate(1, 0)); | |
//assertEquals(-1, percolation.translateCoordinate(3, 6)); | |
//} | |
//@Test | |
//@Ignore | |
//public void getNeighbours() { | |
//int neighbours[] = new int[] {-1, 1, 5, -1}; | |
//assertArrayEquals(neighbours, percolation.getNeighbours(1, 1)); | |
//} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment