-
Notifications
You must be signed in to change notification settings - Fork 5
Add comprehensive tests for ModifiableLong modifications #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bebb65a
Add comprehensive tests for ModifiableLong modifications
ic0ns 4260a4b
Add comprehensive tests for individual Long modification classes
ic0ns 72675e3
Add tests for LongModificationFactory
ic0ns 732cbbf
Merge remote-tracking branch 'origin/main' into enhance-modifiable-lo…
ic0ns a3eebed
adjusted code
ic0ns 16d907d
formatted
ic0ns 5b3a707
adjusted code
ic0ns 5cf988d
removed value of
ic0ns 16d096d
removed value of and pointless assertion
ic0ns cb48634
added assert for not same
ic0ns 866811c
formatted
ic0ns 44ab635
fixed issues
ic0ns 5d70508
added assert not same
ic0ns 4f83e9f
made modifications return null on null input
ic0ns b2d5f92
adjusted tests to reflect new behavior
ic0ns 4121f70
removed dead code
ic0ns File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
src/test/java/de/rub/nds/modifiablevariable/mlong/LongAddModificationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * ModifiableVariable - A Variable Concept for Runtime Modifications | ||
| * | ||
| * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH | ||
| * | ||
| * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package de.rub.nds.modifiablevariable.mlong; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| import de.rub.nds.modifiablevariable.longint.LongAddModification; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class LongAddModificationTest { | ||
|
|
||
| private LongAddModification modification; | ||
| private final Long summand = 5L; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| modification = new LongAddModification(summand); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateCopy() { | ||
| LongAddModification copy = modification.createCopy(); | ||
| assertNotNull(copy); | ||
| assertEquals(modification, copy); | ||
| assertEquals(modification.getSummand(), copy.getSummand()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testEquals() { | ||
| LongAddModification equalModification = new LongAddModification(summand); | ||
| LongAddModification differentModification = new LongAddModification(10L); | ||
|
|
||
| // Test reflexivity | ||
| assertEquals(modification, modification); | ||
|
|
||
| // Test symmetry | ||
| assertEquals(modification, equalModification); | ||
| assertEquals(equalModification, modification); | ||
|
|
||
| // Test with different values | ||
| assertNotEquals(modification, differentModification); | ||
|
|
||
| // Test with null and different object type | ||
| assertNotEquals(modification, null); | ||
| assertNotEquals(modification, "string"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testHashCode() { | ||
| LongAddModification equalModification = new LongAddModification(summand); | ||
|
|
||
| // Equal objects should have equal hash codes | ||
| assertEquals(modification.hashCode(), equalModification.hashCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetSummand() { | ||
| assertEquals(summand, modification.getSummand()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetSummand() { | ||
| Long newSummand = 20L; | ||
| modification.setSummand(newSummand); | ||
| assertEquals(newSummand, modification.getSummand()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToString() { | ||
| String expected = "LongAddModification{summand=5}"; | ||
| assertEquals(expected, modification.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructors() { | ||
| // Test default constructor | ||
| LongAddModification defaultConstructor = new LongAddModification(); | ||
| assertNotNull(defaultConstructor); | ||
|
|
||
| // Test copy constructor | ||
| LongAddModification copy = new LongAddModification(modification); | ||
| assertEquals(modification.getSummand(), copy.getSummand()); | ||
| } | ||
| } | ||
95 changes: 95 additions & 0 deletions
95
src/test/java/de/rub/nds/modifiablevariable/mlong/LongExplicitValueModificationTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * ModifiableVariable - A Variable Concept for Runtime Modifications | ||
| * | ||
| * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH | ||
| * | ||
| * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package de.rub.nds.modifiablevariable.mlong; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| import de.rub.nds.modifiablevariable.longint.LongExplicitValueModification; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class LongExplicitValueModificationTest { | ||
|
|
||
| private LongExplicitValueModification modification; | ||
| private final Long explicitValue = 42L; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| modification = new LongExplicitValueModification(explicitValue); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateCopy() { | ||
| LongExplicitValueModification copy = modification.createCopy(); | ||
| assertNotNull(copy); | ||
| assertEquals(modification, copy); | ||
| assertEquals(modification.getExplicitValue(), copy.getExplicitValue()); | ||
ic0ns marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Test | ||
| public void testEquals() { | ||
| LongExplicitValueModification equalModification = | ||
| new LongExplicitValueModification(explicitValue); | ||
| LongExplicitValueModification differentModification = | ||
| new LongExplicitValueModification(10L); | ||
|
|
||
| // Test reflexivity | ||
| assertEquals(modification, modification); | ||
|
|
||
| // Test symmetry | ||
| assertEquals(modification, equalModification); | ||
| assertEquals(equalModification, modification); | ||
|
|
||
| // Test with different values | ||
| assertNotEquals(modification, differentModification); | ||
|
|
||
| // Test with null and different object type | ||
| assertNotEquals(modification, null); | ||
| assertNotEquals(modification, "string"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testHashCode() { | ||
| LongExplicitValueModification equalModification = | ||
| new LongExplicitValueModification(explicitValue); | ||
|
|
||
| // Equal objects should have equal hash codes | ||
| assertEquals(modification.hashCode(), equalModification.hashCode()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetExplicitValue() { | ||
| assertEquals(explicitValue, modification.getExplicitValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSetExplicitValue() { | ||
| Long newValue = 20L; | ||
| modification.setExplicitValue(newValue); | ||
| assertEquals(newValue, modification.getExplicitValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testToString() { | ||
| String expected = "LongExplicitValueModification{explicitValue=42}"; | ||
| assertEquals(expected, modification.toString()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConstructors() { | ||
| // Test default constructor | ||
| LongExplicitValueModification defaultConstructor = new LongExplicitValueModification(); | ||
| assertNotNull(defaultConstructor); | ||
|
|
||
| // Test copy constructor | ||
| LongExplicitValueModification copy = new LongExplicitValueModification(modification); | ||
| assertEquals(modification.getExplicitValue(), copy.getExplicitValue()); | ||
| } | ||
| } | ||
185 changes: 185 additions & 0 deletions
185
src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationFactoryTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| /* | ||
| * ModifiableVariable - A Variable Concept for Runtime Modifications | ||
| * | ||
| * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH | ||
| * | ||
| * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 | ||
| */ | ||
| package de.rub.nds.modifiablevariable.mlong; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import de.rub.nds.modifiablevariable.VariableModification; | ||
| import de.rub.nds.modifiablevariable.longint.LongAddModification; | ||
| import de.rub.nds.modifiablevariable.longint.LongExplicitValueModification; | ||
| import de.rub.nds.modifiablevariable.longint.LongModificationFactory; | ||
| import de.rub.nds.modifiablevariable.longint.LongMultiplyModification; | ||
| import de.rub.nds.modifiablevariable.longint.LongShiftLeftModification; | ||
| import de.rub.nds.modifiablevariable.longint.LongShiftRightModification; | ||
| import de.rub.nds.modifiablevariable.longint.LongSubtractModification; | ||
| import de.rub.nds.modifiablevariable.longint.LongSwapEndianModification; | ||
| import de.rub.nds.modifiablevariable.longint.LongXorModification; | ||
| import java.lang.reflect.Constructor; | ||
| import java.lang.reflect.Modifier; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class LongModificationFactoryTest { | ||
|
|
||
| @Test | ||
| public void testAddWithLong() { | ||
| Long summand = 10L; | ||
| VariableModification<Long> modification = LongModificationFactory.add(summand); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongAddModification); | ||
| assertEquals(summand, ((LongAddModification) modification).getSummand()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAddWithString() { | ||
| String summandString = "10"; | ||
| Long summand = 10L; | ||
| VariableModification<Long> modification = LongModificationFactory.add(summandString); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongAddModification); | ||
| assertEquals(summand, ((LongAddModification) modification).getSummand()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testAddWithInvalidString() { | ||
| assertThrows(NumberFormatException.class, () -> LongModificationFactory.add("invalid")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSubWithLong() { | ||
| Long subtrahend = 10L; | ||
| VariableModification<Long> modification = LongModificationFactory.sub(subtrahend); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongSubtractModification); | ||
| assertEquals(subtrahend, ((LongSubtractModification) modification).getSubtrahend()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSubWithString() { | ||
| String subtrahendString = "10"; | ||
| Long subtrahend = 10L; | ||
| VariableModification<Long> modification = LongModificationFactory.sub(subtrahendString); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongSubtractModification); | ||
| assertEquals(subtrahend, ((LongSubtractModification) modification).getSubtrahend()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSubWithInvalidString() { | ||
| assertThrows(NumberFormatException.class, () -> LongModificationFactory.sub("invalid")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testXorWithLong() { | ||
| Long xorValue = 10L; | ||
| VariableModification<Long> modification = LongModificationFactory.xor(xorValue); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongXorModification); | ||
| assertEquals(xorValue, ((LongXorModification) modification).getXor()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testXorWithString() { | ||
| String xorString = "10"; | ||
| Long xorValue = 10L; | ||
| VariableModification<Long> modification = LongModificationFactory.xor(xorString); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongXorModification); | ||
| assertEquals(xorValue, ((LongXorModification) modification).getXor()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testXorWithInvalidString() { | ||
| assertThrows(NumberFormatException.class, () -> LongModificationFactory.xor("invalid")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSwapEndian() { | ||
| VariableModification<Long> modification = LongModificationFactory.swapEndian(); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongSwapEndianModification); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExplicitValueWithLong() { | ||
| Long explicitValue = 10L; | ||
| VariableModification<Long> modification = | ||
| LongModificationFactory.explicitValue(explicitValue); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongExplicitValueModification); | ||
| assertEquals( | ||
| explicitValue, ((LongExplicitValueModification) modification).getExplicitValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExplicitValueWithString() { | ||
| String valueString = "10"; | ||
| Long explicitValue = 10L; | ||
| VariableModification<Long> modification = | ||
| LongModificationFactory.explicitValue(valueString); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongExplicitValueModification); | ||
| assertEquals( | ||
| explicitValue, ((LongExplicitValueModification) modification).getExplicitValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testExplicitValueWithInvalidString() { | ||
| assertThrows( | ||
| NumberFormatException.class, | ||
| () -> LongModificationFactory.explicitValue("invalid")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMultiply() { | ||
| Long factor = 10L; | ||
| VariableModification<Long> modification = LongModificationFactory.multiply(factor); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongMultiplyModification); | ||
| assertEquals(factor, ((LongMultiplyModification) modification).getFactor()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testShiftLeft() { | ||
| int shift = 5; | ||
| VariableModification<Long> modification = LongModificationFactory.shiftLeft(shift); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongShiftLeftModification); | ||
| assertEquals(shift, ((LongShiftLeftModification) modification).getShift()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testShiftRight() { | ||
| int shift = 5; | ||
| VariableModification<Long> modification = LongModificationFactory.shiftRight(shift); | ||
|
|
||
| assertNotNull(modification); | ||
| assertTrue(modification instanceof LongShiftRightModification); | ||
| assertEquals(shift, ((LongShiftRightModification) modification).getShift()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPrivateConstructor() throws NoSuchMethodException { | ||
| Constructor<LongModificationFactory> constructor = | ||
| LongModificationFactory.class.getDeclaredConstructor(); | ||
| assertTrue(Modifier.isPrivate(constructor.getModifiers())); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.