Skip to content

Commit

Permalink
EqualityUtilsTests
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinShalit committed Aug 17, 2017
1 parent f3ced33 commit 0e3d28e
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/api.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ dependencies {
implementation(group = "edu.wpi.first.ntcore", name = "ntcore-jni", version = "3.1.7-20170808143930-12-gccfeab5", classifier = "all")
}

if (project.hasProperty("testClasses")) {
junitPlatform {
filters {
includeClassNamePattern(project.property("testClasses").toString())
}
}
}

/*
* Allows you to run the UI tests in headless mode by calling gradle with the -Pheadless argument
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,86 @@
package edu.wpi.first.shuffleboard.api.util;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class EqualityUtilsTest extends UtilityClassTest<EqualityUtils> {

public EqualityUtilsTest() {
super(EqualityUtils.class);
}

@Test
public void isEqualInvalidPrimativeTest() {
assertThrows(UnsupportedOperationException.class, () -> EqualityUtils.isEqual(new long[0], new long[0]));
}

@Test
public void isDifferentArrayTest() {
assertTrue(EqualityUtils.isDifferent(new Object[]{""}, new Object[]{"A"}));
}

@Test
public void isDifferentArrayFalseTest() {
assertFalse(EqualityUtils.isDifferent(new Object[]{""}, new Object[]{""}));
}

@ParameterizedTest
@MethodSource(value = "isEqualArguments")
public void isEqualTest(Object o1, Object o2) {
assertTrue(EqualityUtils.isEqual(o1, o2));
}

@ParameterizedTest
@MethodSource(value = "isDifferentArguments")
public void isDifferentTest(Object o1, Object o2) {
assertTrue(EqualityUtils.isDifferent(o1, o2));
}

@ParameterizedTest
@MethodSource(value = "isEqualArguments")
public void isDifferentFalseTest(Object o1, Object o2) {
assertFalse(EqualityUtils.isDifferent(o1, o2));
}

private static Stream<Arguments> isEqualArguments() {
return Stream.of(
Arguments.of(null, null),
Arguments.of("Test", "Test"),
Arguments.of(new int[]{1}, new int[]{1}),
Arguments.of(new double[]{1.1}, new double[]{1.1}),
Arguments.of(new byte[]{3}, new byte[]{3}),
Arguments.of(new short[]{4}, new short[]{4}),
Arguments.of(new char[]{'a'}, new char[]{'a'}),
Arguments.of(new boolean[]{true}, new boolean[]{true}),
Arguments.of(new float[]{2.2f}, new float[]{2.2f}),
Arguments.of(new Object[]{"Str"}, new Object[]{"Str"})
);
}

private static Stream<Arguments> isDifferentArguments() {
return Stream.of(
Arguments.of(null, "null"),
Arguments.of("null", null),
Arguments.of("", "A"),
Arguments.of(new int[0], ""),
Arguments.of(new int[]{1}, new int[]{2}),
Arguments.of(new double[]{1.1}, new double[]{1.2}),
Arguments.of(new byte[]{3}, new byte[]{4}),
Arguments.of(new short[]{4}, new short[]{5}),
Arguments.of(new char[]{'a'}, new char[]{'b'}),
Arguments.of(new boolean[]{true}, new boolean[]{false}),
Arguments.of(new float[]{2.2f}, new float[]{2.3f}),
Arguments.of(new Object[]{"Test"}, new Object[]{"Tests"}),
Arguments.of(new int[0], new double[0])
);
}

}

0 comments on commit 0e3d28e

Please sign in to comment.