Advertisement
JeffGrigg

IntersectingTrianglesImplementationTest

Jul 22nd, 2018
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.12 KB | None | 0 0
  1. // original facebook post:
  2. // https://www.facebook.com/groups/javaharikrishna/permalink/1596271237165097/
  3.  
  4. // Implementation class:
  5. // https://pastebin.com/xjyyaBm0
  6.  
  7. // Related "Six Sided Star" classes:
  8. // Implementation:
  9. // https://pastebin.com/7g2keFVE
  10. // Tests:
  11. // https://pastebin.com/zmdNaJ7k
  12.  
  13. import junit.framework.TestCase;
  14.  
  15. import java.util.BitSet;
  16.  
  17. public class IntersectingTrianglesImplementationTest extends TestCase {
  18.  
  19.     public void testSingleTriangleLines1() {
  20.         assertSingleTriangleLinesEquals(new String[]{
  21.                 "*",
  22.         }, 1);
  23.     }
  24.  
  25.     public void testSingleTriangleLines2() {
  26.         assertSingleTriangleLinesEquals(new String[]{
  27.                 " *",
  28.                 "* *",
  29.         }, 2);
  30.     }
  31.  
  32.     public void testSingleTriangleLines3() {
  33.         assertSingleTriangleLinesEquals(new String[]{
  34.                 "  *",
  35.                 " * *",
  36.                 "* * *",
  37.         }, 3);
  38.     }
  39.  
  40.     public void testSingleTriangleLines4() {
  41.         assertSingleTriangleLinesEquals(new String[]{
  42.                 "   *",
  43.                 "  * *",
  44.                 " *   *",
  45.                 "* * * *",
  46.         }, 4);
  47.     }
  48.  
  49.     public void testSingleTriangleLines5() {
  50.         assertSingleTriangleLinesEquals(new String[]{
  51.                 "    *",
  52.                 "   * *",
  53.                 "  *   *",
  54.                 " *     *",
  55.                 "* * * * *",
  56.         }, 5);
  57.     }
  58.  
  59.     private static void assertSingleTriangleLinesEquals(final String[] expectedStarPattern, final int triangleLines) {
  60.         assertEquals("Error in test data: Number of lines should match;", expectedStarPattern.length, triangleLines);
  61.         for (int lineIndex = 0; lineIndex < triangleLines; ++lineIndex) {
  62.             final BitSet starsOnThisLine = new BitSet();
  63.             IntersectingTriangles.setTriangleBits(starsOnThisLine, triangleLines, lineIndex);
  64.             assertEquals("Line index <" + lineIndex + "> of <" + triangleLines + "> line triangle;",
  65.                     expectedStarPattern[lineIndex], IntersectingTriangles.bitsToStars(starsOnThisLine));
  66.         }
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement