Skip to content

Commit

Permalink
chore: add unit tests for BitString
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian G <cristian.castro@iohk.io>
  • Loading branch information
cristianIOHK committed Aug 20, 2024
1 parent 832bb62 commit 7653f88
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ class PolluxImplTest {
"id": "",
"type": "StatusList2021",
"statusPurpose": "Revocation",
"encodedList": "H4sIAAAAAAAA_-3BIQEAAAACIBf4f64zLEADAAAAAAAAAAAAAAAAAAAAvA34c39nAEAAAA=="
"encodedList": "H4sIAAAAAAAA_-3BMQ0AAAwDoCX1N_9yKqMP8DkAAAAAAAAAAAAAAAAAAABgrMaHlsQAQAAA"
},
"proof": {
"type": "DataIntegrityProof",
Expand All @@ -1090,6 +1090,12 @@ class PolluxImplTest {
assertTrue(pollux.checkEncodedListRevoked(revocationRegistryJson, 2))
assertTrue(pollux.checkEncodedListRevoked(revocationRegistryJson, 3))
assertFalse(pollux.checkEncodedListRevoked(revocationRegistryJson, 4))
assertFalse(pollux.checkEncodedListRevoked(revocationRegistryJson, 5))
assertTrue(pollux.checkEncodedListRevoked(revocationRegistryJson, 6))
assertFalse(pollux.checkEncodedListRevoked(revocationRegistryJson, 7))
assertTrue(pollux.checkEncodedListRevoked(revocationRegistryJson, 8))
assertTrue(pollux.checkEncodedListRevoked(revocationRegistryJson, 9))
assertFalse(pollux.checkEncodedListRevoked(revocationRegistryJson, 10))
}

private suspend fun createVerificationTestCase(testCaseOptions: VerificationTestCase): Triple<String, String, String> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.hyperledger.identus.walletsdk.pollux.utils

import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.util.*

class BitStringTest {

@Test
fun `test BitString with some 0s`() {
val byteArray = byteArrayOf(0.toByte())
val bitSet = BitSet.valueOf(byteArray)
val bitString = BitString(bitSet, byteArray.size * 8)

for (i in 0 until bitString.size) {
assertFalse("Index $i should not be revoked", bitString.isRevoked(i))
}
}

@Test
fun `test BitString with some 1s`() {
val byteArray = byteArrayOf(128.toByte(), 1.toByte())
val bitSet = BitSet.valueOf(byteArray)
val bitString = BitString(bitSet, byteArray.size * 8)

assertTrue("Index 7 should be revoked", bitString.isRevoked(7))
assertTrue("Index 8 should be revoked", bitString.isRevoked(8))
for (i in 0 until 7) {
assertFalse("Index $i should not be revoked", bitString.isRevoked(i))
}
for (i in 9 until bitString.size) {
assertFalse("Index $i should not be revoked", bitString.isRevoked(i))
}
}

}

0 comments on commit 7653f88

Please sign in to comment.