Skip to content

Commit

Permalink
add assert2DArrayEquals
Browse files Browse the repository at this point in the history
  • Loading branch information
creme332 committed Jun 8, 2024
1 parent 7dc9c96 commit 9b1e28d
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions src/test/java/com/github/creme332/tests/utils/TestHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.creme332.tests.utils;

import static org.junit.Assert.assertEquals;

import java.awt.Point;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -13,13 +15,13 @@ private TestHelper() {
* pixels in the actualPixels array.
* Additionally, it identifies any duplicate pixels in the actualPixels array.
*
* This method does NOT perform assertions.
* This method does NOT perform JUnit assertions.
*
* @param expectedPixels The expected array of pixel coordinates.
* @param actualPixels The actual array of pixel coordinates to be compared
* with the expected array.
*/
public static void compare2DArrays(int[][] expectedPixels, int[][] actualPixels) {
public static void compare2DArraysDebug(int[][] expectedPixels, int[][] actualPixels) {
// Set to store the expected pixel coordinates
Set<Point> expectedSet = new HashSet<>();
// Populate the set with expected pixel coordinates
Expand All @@ -29,7 +31,7 @@ public static void compare2DArrays(int[][] expectedPixels, int[][] actualPixels)

// Set to store the actual pixel coordinates
Set<Point> actualSet = new HashSet<>();

// Set to store duplicate actual pixel coordinates
Set<Point> duplicatePixels = new HashSet<>();
// Populate the set with actual pixel coordinates
Expand Down Expand Up @@ -76,4 +78,28 @@ public static void compare2DArrays(int[][] expectedPixels, int[][] actualPixels)
}
}
}
}

/**
* Asserts that 2 arrays of pixels are identical. Order of pixels is ignored.
*
* @param expectedPixels
* @param actualPixels
*/
public static void assert2DArrayEquals(int[][] expectedPixels, int[][] actualPixels) {
// Set to store the expected pixel coordinates
Set<Point> expectedSet = new HashSet<>();
// Populate the set with expected pixel coordinates
for (int[] coord : expectedPixels) {
expectedSet.add(new Point(coord[0], coord[1]));
}

// Set to store the actual pixel coordinates
Set<Point> actualSet = new HashSet<>();
// Populate the set with actual pixel coordinates
for (int[] coord : actualPixels) {
actualSet.add(new Point(coord[0], coord[1]));
}

assertEquals(expectedSet, actualSet);
}
}

0 comments on commit 9b1e28d

Please sign in to comment.