Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@
* [VigenereTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/VigenereTest.java)
* [XORCipherTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/ciphers/XORCipherTest.java)
* conversions
* [AffineConverterTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/AffineConverterTest.java)
* [AnyBaseToDecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/AnyBaseToDecimalTest.java)
* [BinaryToDecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/BinaryToDecimalTest.java)
* [BinaryToHexadecimalTest](https://github.com/TheAlgorithms/Java/blob/master/src/test/java/com/thealgorithms/conversions/BinaryToHexadecimalTest.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.thealgorithms.conversions;

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

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class AffineConverterTest {

private AffineConverter converter;

@BeforeEach
void setUp() {
converter = new AffineConverter(2.0, 3.0);
}

@Test
void testConstructor() {
assertEquals(3.0, converter.convert(0.0), "Expected value when input is 0.0");
assertEquals(5.0, converter.convert(1.0), "Expected value when input is 1.0");
assertEquals(7.0, converter.convert(2.0), "Expected value when input is 2.0");
}

@Test
void testConvert() {
assertEquals(3.0, converter.convert(0.0), "Conversion at 0.0 should equal the intercept");
assertEquals(7.0, converter.convert(2.0), "2.0 should convert to 7.0");
assertEquals(11.0, converter.convert(4.0), "4.0 should convert to 11.0");
}

@Test
void testInvert() {
AffineConverter inverted = converter.invert();
assertEquals(0.0, inverted.convert(3.0), "Inverted converter should return 0.0 for input 3.0");
assertEquals(1.0, inverted.convert(5.0), "Inverted converter should return 1.0 for input 5.0");
assertEquals(2.0, inverted.convert(7.0), "Inverted converter should return 2.0 for input 7.0");
}

@Test
void testInvertWithZeroSlope() {
AffineConverter zeroSlopeConverter = new AffineConverter(0.0, 3.0);
assertThrows(AssertionError.class, zeroSlopeConverter::invert, "Invert should throw assertion error when slope is zero");
}

@Test
void testCompose() {
AffineConverter otherConverter = new AffineConverter(1.0, 2.0);
AffineConverter composed = converter.compose(otherConverter);

assertEquals(7.0, composed.convert(0.0), "Expected composed conversion at 0.0");
assertEquals(9.0, composed.convert(1.0), "Expected composed conversion at 1.0");
assertEquals(11.0, composed.convert(2.0), "Expected composed conversion at 2.0");
}
}