Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // original facebook post:
- // https://www.facebook.com/groups/javaharikrishna/permalink/1596271237165097/
- // Implementation class:
- // https://pastebin.com/xjyyaBm0
- // Related "Six Sided Star" classes:
- // Implementation:
- // https://pastebin.com/7g2keFVE
- // Tests:
- // https://pastebin.com/zmdNaJ7k
- import junit.framework.TestCase;
- import java.util.BitSet;
- public class IntersectingTrianglesImplementationTest extends TestCase {
- public void testSingleTriangleLines1() {
- assertSingleTriangleLinesEquals(new String[]{
- "*",
- }, 1);
- }
- public void testSingleTriangleLines2() {
- assertSingleTriangleLinesEquals(new String[]{
- " *",
- "* *",
- }, 2);
- }
- public void testSingleTriangleLines3() {
- assertSingleTriangleLinesEquals(new String[]{
- " *",
- " * *",
- "* * *",
- }, 3);
- }
- public void testSingleTriangleLines4() {
- assertSingleTriangleLinesEquals(new String[]{
- " *",
- " * *",
- " * *",
- "* * * *",
- }, 4);
- }
- public void testSingleTriangleLines5() {
- assertSingleTriangleLinesEquals(new String[]{
- " *",
- " * *",
- " * *",
- " * *",
- "* * * * *",
- }, 5);
- }
- private static void assertSingleTriangleLinesEquals(final String[] expectedStarPattern, final int triangleLines) {
- assertEquals("Error in test data: Number of lines should match;", expectedStarPattern.length, triangleLines);
- for (int lineIndex = 0; lineIndex < triangleLines; ++lineIndex) {
- final BitSet starsOnThisLine = new BitSet();
- IntersectingTriangles.setTriangleBits(starsOnThisLine, triangleLines, lineIndex);
- assertEquals("Line index <" + lineIndex + "> of <" + triangleLines + "> line triangle;",
- expectedStarPattern[lineIndex], IntersectingTriangles.bitsToStars(starsOnThisLine));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement