-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae3f9a8
commit c8f84db
Showing
15 changed files
with
465 additions
and
557 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -21,53 +21,44 @@ | |
*/ | ||
package org.firebirdsql.decimal; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.stream.Stream; | ||
|
||
import static org.firebirdsql.decimal.util.ByteArrayHelper.hexToBytes; | ||
import static org.junit.Assert.assertArrayEquals; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assume.assumeTrue; | ||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Rotteveel</a> | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class Decimal128ByteConversionTest { | ||
|
||
@Parameterized.Parameter | ||
public String description; | ||
@Parameterized.Parameter(1) | ||
public byte[] sourceBytes; | ||
@Parameterized.Parameter(2) | ||
public Decimal128 decimalValue; | ||
@Parameterized.Parameter(3) | ||
public byte[] targetBytes; | ||
class Decimal128ByteConversionTest { | ||
|
||
@Test | ||
public void testConversionFromBytesToDecimal128() { | ||
assumeTrue("No source bytes for " + description, sourceBytes != null); | ||
@SuppressWarnings("unused") | ||
@ParameterizedTest(name = "{index}: value {0} ({2})") | ||
@MethodSource("data") | ||
void testConversionFromBytesToDecimal128(String description, byte[] sourceBytes, Decimal128 decimalValue, | ||
byte[] targetBytes) { | ||
assumeTrue(sourceBytes != null, "No source bytes for " + description); | ||
Decimal128 result = Decimal128.parseBytes(sourceBytes); | ||
|
||
assertEquals("Expected " + description, decimalValue, result); | ||
assertEquals(decimalValue, result, "Expected " + description); | ||
} | ||
|
||
@Test | ||
public void testConversionFromDecimal128ToBytes() { | ||
assumeTrue("No target bytes for " + description, targetBytes != null); | ||
@SuppressWarnings("unused") | ||
@ParameterizedTest(name = "{index}: value {0} ({2})") | ||
@MethodSource("data") | ||
void testConversionFromDecimal128ToBytes(String description, byte[] sourceBytes, Decimal128 decimalValue, | ||
byte[] targetBytes) { | ||
assumeTrue(targetBytes != null, "No target bytes for " + description); | ||
byte[] result = decimalValue.toBytes(); | ||
|
||
assertArrayEquals(targetBytes, result); | ||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: value {0} ({2})") | ||
public static Collection<Object[]> data() { | ||
return Arrays.asList( | ||
static Stream<Arguments> data() { | ||
return Stream.of( | ||
testCase("POSITIVE_INFINITY", | ||
new byte[] { 0b0_11110_00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, | ||
Decimal128.POSITIVE_INFINITY), | ||
|
@@ -446,7 +437,7 @@ public static Collection<Object[]> data() { | |
* String encoding of the decimal value (compatible with parsing by {@link BigDecimal} | ||
* @return Test case data | ||
*/ | ||
private static Object[] testCase(String sourceEncodedString, String decimalString) { | ||
private static Arguments testCase(String sourceEncodedString, String decimalString) { | ||
return testCase(decimalString, hexToBytes(sourceEncodedString), dec(decimalString)); | ||
} | ||
|
||
|
@@ -464,7 +455,7 @@ private static Object[] testCase(String sourceEncodedString, String decimalStrin | |
* Hex string of binary encoding of decimal (target) | ||
* @return Test case data | ||
*/ | ||
private static Object[] testCase(String sourceEncodedString, String decimalString, String targetEncodedString) { | ||
private static Arguments testCase(String sourceEncodedString, String decimalString, String targetEncodedString) { | ||
return testCase(decimalString, hexToBytes(sourceEncodedString), dec(decimalString), | ||
hexToBytes(targetEncodedString)); | ||
} | ||
|
@@ -481,7 +472,7 @@ private static Object[] testCase(String sourceEncodedString, String decimalStrin | |
* Decimal128 value | ||
* @return Test case data | ||
*/ | ||
private static Object[] testCase(String description, byte[] sourceBytes, Decimal128 decimal128Value) { | ||
private static Arguments testCase(String description, byte[] sourceBytes, Decimal128 decimal128Value) { | ||
return testCase(description, sourceBytes, decimal128Value, sourceBytes); | ||
} | ||
|
||
|
@@ -499,9 +490,9 @@ private static Object[] testCase(String description, byte[] sourceBytes, Decimal | |
* Binary encoding of decimal (target) | ||
* @return Test case data | ||
*/ | ||
private static Object[] testCase(String description, byte[] sourceBytes, Decimal128 decimal128Value, | ||
private static Arguments testCase(String description, byte[] sourceBytes, Decimal128 decimal128Value, | ||
byte[] targetBytes) { | ||
return new Object[] { description, sourceBytes, decimal128Value, targetBytes }; | ||
return Arguments.of(description, sourceBytes, decimal128Value, targetBytes); | ||
} | ||
|
||
private static Decimal128 dec(String decimalString) { | ||
|
Oops, something went wrong.