forked from oxen-io/session-android
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request oxen-io#1593 from bemusementpark/more-snodes
Optimise SnodeAPI and Add Snode.Version and tests
- Loading branch information
Showing
8 changed files
with
502 additions
and
686 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
52 changes: 52 additions & 0 deletions
52
app/src/test/java/org/session/libsignal/utilities/SnodeTest.kt
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.session.libsignal.utilities | ||
|
||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.core.IsEqual.equalTo | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
|
||
@RunWith(Parameterized::class) | ||
class SnodeVersionTest( | ||
private val v1: String, | ||
private val v2: String, | ||
private val expectedEqual: Boolean, | ||
private val expectedLessThan: Boolean | ||
) { | ||
companion object { | ||
@JvmStatic | ||
@Parameterized.Parameters(name = "{index}: testVersion({0},{1}) = (equalTo: {2}, lessThan: {3})") | ||
fun data(): Collection<Array<Any>> = listOf( | ||
arrayOf("1", "1", true, false), | ||
arrayOf("1", "2", false, true), | ||
arrayOf("2", "1", false, false), | ||
arrayOf("1.0", "1", true, false), | ||
arrayOf("1.0", "1.0.0", true, false), | ||
arrayOf("1.0", "1.0.0.0", true, false), | ||
arrayOf("1.0", "1.0.0.0.0.0", true, false), | ||
arrayOf("2.0", "1.2", false, false), | ||
arrayOf("1.0.0.0", "1.0.0.1", false, true), | ||
// Snode.Version only considers the first 4 integers, so these are equal | ||
arrayOf("1.0.0.0", "1.0.0.0.1", true, false), | ||
arrayOf("1.0.0.1", "1.0.0.1", true, false), | ||
// parts can be up to 16 bits, around 65,535 | ||
arrayOf("65535.65535.65535.65535", "65535.65535.65535.65535", true, false), | ||
// values higher than this are coerced to 65535 (: | ||
arrayOf("65535.65535.65535.65535", "65535.65535.65535.99999", true, false), | ||
) | ||
} | ||
|
||
@Test | ||
fun testVersionEqual() { | ||
val version1 = Snode.Version(v1) | ||
val version2 = Snode.Version(v2) | ||
assertThat(version1 == version2, equalTo(expectedEqual)) | ||
} | ||
|
||
@Test | ||
fun testVersionOnePartLessThan() { | ||
val version1 = Snode.Version(v1) | ||
val version2 = Snode.Version(v2) | ||
assertThat(version1 < version2, equalTo(expectedLessThan)) | ||
} | ||
} |
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
Oops, something went wrong.