|
1 | 1 | package org.biojava.nbio.core.util; |
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.assertAll; |
3 | 4 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
4 | 6 |
|
5 | 7 | import org.junit.jupiter.api.BeforeEach; |
6 | | -import org.junit.jupiter.api.Disabled; |
7 | 8 | import org.junit.jupiter.api.DisplayName; |
8 | 9 | import org.junit.jupiter.api.RepeatedTest; |
9 | 10 | import org.junit.jupiter.api.Test; |
@@ -75,20 +76,36 @@ void allRangeIsSameAsAllArray (){ |
75 | 76 | } |
76 | 77 |
|
77 | 78 | @Test |
78 | | - @Disabled |
79 | | - // this doesn't work as expected |
80 | | - // and doesn't behave according to interface. The 3rd argument |
81 | | - // is treated as an index rather than a number of bytes to include |
82 | | - void partialbyteRange (){ |
| 79 | + void partialByteRange (){ |
83 | 80 | byte [] testBytes = new byte [] {1,2,3,4,5}; |
84 | | - // should update with testBytes[2] but doesn't |
85 | 81 | crc64.update(testBytes, 2, 1); |
86 | 82 | String partialBytesHex = crc64.toString(); |
87 | 83 | crc64.reset(); |
88 | 84 | crc64.update(testBytes[2]); |
89 | 85 | assertEquals(partialBytesHex, crc64.toString()); |
90 | 86 | } |
91 | 87 |
|
| 88 | + @Test |
| 89 | + void partialByteRangeRejectsInvalidInput (){ |
| 90 | + byte [] testBytes = new byte [] {1,2,3,4,5}; |
| 91 | + assertAll( |
| 92 | + ()->assertThrows(IllegalArgumentException.class, |
| 93 | + ()->crc64.update(testBytes, -1, 0)), |
| 94 | + ()->assertThrows(IllegalArgumentException.class, |
| 95 | + ()->crc64.update(testBytes, 0, -1)), |
| 96 | + ()->assertThrows(IllegalArgumentException.class, |
| 97 | + ()->crc64.update(testBytes, 0, testBytes.length+1)), |
| 98 | + ()->assertThrows(IllegalArgumentException.class, |
| 99 | + ()->crc64.update(testBytes, testBytes.length, 1)) |
| 100 | + ); |
| 101 | + crc64.update(testBytes, 2, 1); |
| 102 | + String partialBytesHex = crc64.toString(); |
| 103 | + crc64.reset(); |
| 104 | + crc64.update(testBytes[2]); |
| 105 | + assertEquals(partialBytesHex, crc64.toString()); |
| 106 | + } |
| 107 | + |
| 108 | + |
92 | 109 | @Test |
93 | 110 | void hexStringIsEqualToValue(){ |
94 | 111 | Long value = Long.parseLong(helloInCrc64Hex, 16); |
|
0 commit comments