Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package de.rub.nds.modifiablevariable.integer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import de.rub.nds.modifiablevariable.VariableModification;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -16,7 +17,6 @@
public class IntegerModificationTest {

private ModifiableInteger start;

private Integer expectedResult, result;

@BeforeEach
Expand All @@ -38,6 +38,27 @@ public void testAdd() {
assertEquals(Integer.valueOf(10), start.getOriginalValue());
}

/** Test of add method with String, of class IntegerModification. */
@Test
public void testAddWithString() {
VariableModification<Integer> modifier = IntegerModificationFactory.add("1");
start.setModifications(modifier);
expectedResult = 11;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of add method with null input, of class IntegerModification. */
@Test
public void testAddWithNullInput() {
VariableModification<Integer> modifier = IntegerModificationFactory.add(1);
start.setOriginalValue(null);
start.setModifications(modifier);
expectedResult = 1;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of sub method, of class IntegerModification. */
@Test
public void testSub() {
Expand All @@ -49,6 +70,27 @@ public void testSub() {
assertEquals(Integer.valueOf(10), start.getOriginalValue());
}

/** Test of sub method with String, of class IntegerModification. */
@Test
public void testSubWithString() {
VariableModification<Integer> modifier = IntegerModificationFactory.sub("1");
start.setModifications(modifier);
expectedResult = 9;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of sub method with null input, of class IntegerModification. */
@Test
public void testSubWithNullInput() {
VariableModification<Integer> modifier = IntegerModificationFactory.sub(1);
start.setOriginalValue(null);
start.setModifications(modifier);
expectedResult = -1;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of xor method, of class IntegerModification. */
@Test
public void testXor() {
Expand All @@ -60,6 +102,27 @@ public void testXor() {
assertEquals(Integer.valueOf(10), start.getOriginalValue());
}

/** Test of xor method with String, of class IntegerModification. */
@Test
public void testXorWithString() {
VariableModification<Integer> modifier = IntegerModificationFactory.xor("2");
start.setModifications(modifier);
expectedResult = 8;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of xor method with null input, of class IntegerModification. */
@Test
public void testXorWithNullInput() {
VariableModification<Integer> modifier = IntegerModificationFactory.xor(2);
start.setOriginalValue(null);
start.setModifications(modifier);
expectedResult = 2;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of explicitValue method, of class IntegerModification. */
@Test
public void testExplicitValue() {
Expand All @@ -71,6 +134,28 @@ public void testExplicitValue() {
assertEquals(Integer.valueOf(10), start.getOriginalValue());
}

/** Test of explicitValue method with String, of class IntegerModification. */
@Test
public void testExplicitValueWithString() {
VariableModification<Integer> modifier = IntegerModificationFactory.explicitValue("7");
start.setModifications(modifier);
expectedResult = 7;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of explicitValue method with null input, of class IntegerModification. */
@Test
public void testExplicitValueWithNullInput() {
VariableModification<Integer> modifier = IntegerModificationFactory.explicitValue(7);
start.setOriginalValue(null);
start.setModifications(modifier);
expectedResult = 7;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of shiftLeft method, of class IntegerModification. */
@Test
public void testShiftLeft() {
VariableModification<Integer> modifier = IntegerModificationFactory.shiftLeft(2);
Expand All @@ -81,6 +166,17 @@ public void testShiftLeft() {
assertEquals(Integer.valueOf(10), start.getOriginalValue());
}

/** Test of shiftLeft method with String, of class IntegerModification. */
@Test
public void testShiftLeftWithString() {
VariableModification<Integer> modifier = IntegerModificationFactory.shiftLeft("2");
start.setModifications(modifier);
expectedResult = 40;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of shiftRight method, of class IntegerModification. */
@Test
public void testShiftRight() {
VariableModification<Integer> modifier = IntegerModificationFactory.shiftRight(2);
Expand All @@ -90,4 +186,94 @@ public void testShiftRight() {
assertEquals(expectedResult, result);
assertEquals(Integer.valueOf(10), start.getOriginalValue());
}

/** Test of shiftRight method with String, of class IntegerModification. */
@Test
public void testShiftRightWithString() {
VariableModification<Integer> modifier = IntegerModificationFactory.shiftRight("2");
start.setModifications(modifier);
expectedResult = 2;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of swapEndian method, of class IntegerModification. */
@Test
public void testSwapEndian() {
VariableModification<Integer> modifier = IntegerModificationFactory.swapEndian();
start.setOriginalValue(0x12345678);
start.setModifications(modifier);
expectedResult = 0x78563412;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of swapEndian method with null input, of class IntegerModification. */
@Test
public void testSwapEndianWithNullInput() {
VariableModification<Integer> modifier = IntegerModificationFactory.swapEndian();
start.setOriginalValue(null);
start.setModifications(modifier);
assertNull(start.getValue());
}

/** Test of multiply method, of class IntegerModification. */
@Test
public void testMultiply() {
VariableModification<Integer> modifier = IntegerModificationFactory.multiply(2);
start.setModifications(modifier);
expectedResult = 20;
result = start.getValue();
assertEquals(expectedResult, result);
assertEquals(Integer.valueOf(10), start.getOriginalValue());
}

/** Test of multiply method with negative value, of class IntegerModification. */
@Test
public void testMultiplyWithNegativeValue() {
VariableModification<Integer> modifier = IntegerModificationFactory.multiply(-1);
start.setModifications(modifier);
expectedResult = -10;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of multiply method with zero, of class IntegerModification. */
@Test
public void testMultiplyWithZero() {
VariableModification<Integer> modifier = IntegerModificationFactory.multiply(0);
start.setModifications(modifier);
expectedResult = 0;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of multiply method with null input, of class IntegerModification. */
@Test
public void testMultiplyWithNullInput() {
VariableModification<Integer> modifier = IntegerModificationFactory.multiply(2);
start.setOriginalValue(null);
start.setModifications(modifier);
expectedResult = 0;
result = start.getValue();
assertEquals(expectedResult, result);
}

/** Test of multiple modifications, of class IntegerModification. */
@Test
public void testMultipleModifications() {
// Instead of chaining, apply modifications one after another
VariableModification<Integer> addModifier = IntegerModificationFactory.add(5);
start.setModifications(addModifier);
assertEquals(15, start.getValue());

// Apply a second modification to a new ModifiableInteger
ModifiableInteger intermediate = new ModifiableInteger(start.getValue());
VariableModification<Integer> multiplyModifier = IntegerModificationFactory.multiply(2);
intermediate.setModifications(multiplyModifier);

expectedResult = 30; // (10 + 5) * 2
result = intermediate.getValue();
assertEquals(expectedResult, result);
}
}
Loading