diff --git a/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java b/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java index 012874dd98..b818c7e466 100644 --- a/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java +++ b/cscore/src/main/java/edu/wpi/first/cscore/VideoMode.java @@ -4,6 +4,8 @@ package edu.wpi.first.cscore; +import java.util.Objects; + /** Video mode. */ @SuppressWarnings("MemberName") public class VideoMode { @@ -75,4 +77,28 @@ public class VideoMode { /** Frames per second. */ public int fps; + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; + } + if (other == null) { + return false; + } + if (getClass() != other.getClass()) { + return false; + } + VideoMode mode = (VideoMode) other; + + return pixelFormat == mode.pixelFormat + && width == mode.width + && height == mode.height + && fps == mode.fps; + } + + @Override + public int hashCode() { + return Objects.hash(pixelFormat, width, height, fps); + } } diff --git a/cscore/src/test/java/edu/wpi/first/cscore/VideoModeTest.java b/cscore/src/test/java/edu/wpi/first/cscore/VideoModeTest.java new file mode 100644 index 0000000000..738888d7fe --- /dev/null +++ b/cscore/src/test/java/edu/wpi/first/cscore/VideoModeTest.java @@ -0,0 +1,21 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +package edu.wpi.first.cscore; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +import org.junit.jupiter.api.Test; + +class VideoModeTest { + @Test + void equalityTest() { + VideoMode a = new VideoMode(VideoMode.PixelFormat.kMJPEG, 1920, 1080, 30); + VideoMode b = new VideoMode(VideoMode.PixelFormat.kMJPEG, 1920, 1080, 30); + + assertEquals(a, b); + assertNotEquals(a, null); + } +}