mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-04-27 06:45:22 +00:00
resolution of issue with registering a specific number as a GUID
This commit is contained in:
parent
8b5073dcbc
commit
fbb3946857
4 changed files with 49 additions and 19 deletions
|
|
@ -208,7 +208,7 @@ class NumberPoolHub(private val source : NumberSource) {
|
||||||
import net.psforever.objects.guid.selector.SpecificSelector
|
import net.psforever.objects.guid.selector.SpecificSelector
|
||||||
val specific = new SpecificSelector
|
val specific = new SpecificSelector
|
||||||
pool.Selector = specific
|
pool.Selector = specific
|
||||||
specific.SelectionIndex = number
|
specific.SelectionIndex = pool.Numbers.indexOf(number)
|
||||||
pool.Get()
|
pool.Get()
|
||||||
pool.Selector = slctr
|
pool.Selector = slctr
|
||||||
register_GetAvailableNumberFromSource(number)
|
register_GetAvailableNumberFromSource(number)
|
||||||
|
|
@ -281,10 +281,10 @@ class NumberPoolHub(private val source : NumberSource) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private def register_GetMonitorFromSource(number : Int) : Try[LoanedKey] = {
|
private def register_GetMonitorFromSource(number : Int) : Try[LoanedKey] = {
|
||||||
source.Available(number) match {
|
register_GetAvailableNumberFromSource(number) match {
|
||||||
case Some(key) =>
|
case Success(key) =>
|
||||||
Success(key)
|
Success(key)
|
||||||
case _ =>
|
case Failure(_) =>
|
||||||
throw NoGUIDException(s"a pool gave us a number $number that is actually unavailable") //stop the show; this is terrible!
|
throw NoGUIDException(s"a pool gave us a number $number that is actually unavailable") //stop the show; this is terrible!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,15 +136,33 @@ class NumberPoolHubTest extends Specification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"register an object to a specific, pooled number" in {
|
"register an object to a specific, pooled number (list 1)" in {
|
||||||
val hub = new NumberPoolHub(new LimitedNumberSource(51))
|
val src = new LimitedNumberSource(51)
|
||||||
|
val hub = new NumberPoolHub(src)
|
||||||
hub.AddPool("fibonacci", numberList)
|
hub.AddPool("fibonacci", numberList)
|
||||||
val obj = new EntityTestClass()
|
val obj = new EntityTestClass()
|
||||||
obj.GUID must throwA[Exception]
|
obj.GUID must throwA[Exception]
|
||||||
|
hub.register(obj, 5) match {
|
||||||
|
case Success(number) =>
|
||||||
|
obj.GUID mustEqual PlanetSideGUID(number)
|
||||||
|
hub.WhichPool(obj) mustEqual Some("fibonacci")
|
||||||
|
src.Available(5) mustEqual None
|
||||||
|
case _ =>
|
||||||
|
ko
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"register an object to a specific, pooled number (list 2)" in {
|
||||||
|
val src = new LimitedNumberSource(51)
|
||||||
|
val hub = new NumberPoolHub(src)
|
||||||
|
hub.AddPool("fibonacci", numberList2)
|
||||||
|
val obj = new EntityTestClass()
|
||||||
|
obj.GUID must throwA[Exception]
|
||||||
hub.register(obj, 13) match {
|
hub.register(obj, 13) match {
|
||||||
case Success(number) =>
|
case Success(number) =>
|
||||||
obj.GUID mustEqual PlanetSideGUID(number)
|
obj.GUID mustEqual PlanetSideGUID(number)
|
||||||
hub.WhichPool(obj) mustEqual Some("fibonacci")
|
hub.WhichPool(obj) mustEqual Some("fibonacci")
|
||||||
|
src.Available(13) mustEqual None
|
||||||
case _ =>
|
case _ =>
|
||||||
ko
|
ko
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,17 @@ class NumberPoolTest extends Specification {
|
||||||
}
|
}
|
||||||
|
|
||||||
"get a number" in {
|
"get a number" in {
|
||||||
val obj = new SimplePool((0 to 10).toList)
|
val min = 10
|
||||||
|
val max = 20
|
||||||
|
val domain = (min to max).toList
|
||||||
|
val obj = new SimplePool(domain)
|
||||||
obj.Get() match {
|
obj.Get() match {
|
||||||
case Success(number) =>
|
case Success(number) =>
|
||||||
(-1 < number && number < 11) mustEqual true
|
(min <= number && number <= max) mustEqual true
|
||||||
case _ =>
|
case _ =>
|
||||||
ko
|
ko
|
||||||
}
|
}
|
||||||
|
ok
|
||||||
}
|
}
|
||||||
|
|
||||||
"used number count is always zero" in {
|
"used number count is always zero" in {
|
||||||
|
|
@ -70,22 +74,28 @@ class NumberPoolTest extends Specification {
|
||||||
}
|
}
|
||||||
|
|
||||||
"get a number" in {
|
"get a number" in {
|
||||||
val obj = new ExclusivePool((0 to 10).toList)
|
val min = 10
|
||||||
|
val max = 20
|
||||||
|
val domain = (min to max).toList
|
||||||
|
val obj = new ExclusivePool(domain)
|
||||||
obj.Get() match {
|
obj.Get() match {
|
||||||
case Success(number) =>
|
case Success(number) =>
|
||||||
(-1 < number && number < 11) mustEqual true
|
(min <= number && number <= max) mustEqual true
|
||||||
case _ =>
|
case _ =>
|
||||||
ko
|
ko
|
||||||
}
|
}
|
||||||
|
ok
|
||||||
}
|
}
|
||||||
|
|
||||||
"get all the numbers" in {
|
"get all the numbers" in {
|
||||||
val range = 0 to 10
|
val min = 10
|
||||||
val obj = new ExclusivePool((0 to 10).toList)
|
val max = 20
|
||||||
range.foreach(_ => {
|
val domain = (min to max).toList
|
||||||
|
val obj = new ExclusivePool(domain)
|
||||||
|
domain.foreach(_ => {
|
||||||
obj.Get() match {
|
obj.Get() match {
|
||||||
case Success(number) =>
|
case Success(number) =>
|
||||||
(-1 < number && number < 11) mustEqual true
|
(min <= number && number <= max) mustEqual true
|
||||||
case _ =>
|
case _ =>
|
||||||
ko
|
ko
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,26 +5,28 @@ import net.psforever.objects.guid.selector.{RandomSequenceSelector, _}
|
||||||
import org.specs2.mutable.Specification
|
import org.specs2.mutable.Specification
|
||||||
|
|
||||||
class NumberSelectorTest extends Specification {
|
class NumberSelectorTest extends Specification {
|
||||||
def randArrayGen(n : Int = 26) : Array[Int] = {
|
def randArrayGen(n : Int = 26, dx : Int = 0) : Array[Int] = {
|
||||||
val obj = Array.ofDim[Int](n)
|
val obj = Array.ofDim[Int](n)
|
||||||
(0 to 25).foreach(x => { obj(x) = x } )
|
(0 to 25).foreach(x => { obj(x) = x + dx } )
|
||||||
obj
|
obj
|
||||||
}
|
}
|
||||||
|
|
||||||
"RandomSequenceSelector" should {
|
"RandomSequenceSelector (0, default)" should {
|
||||||
"construct" in {
|
"construct" in {
|
||||||
new RandomSequenceSelector
|
new RandomSequenceSelector
|
||||||
ok
|
ok
|
||||||
}
|
}
|
||||||
|
|
||||||
"get a number" in {
|
"get a number" in {
|
||||||
|
val n : Int = 26
|
||||||
val obj = new RandomSequenceSelector
|
val obj = new RandomSequenceSelector
|
||||||
obj.Get(randArrayGen()) mustNotEqual -1
|
obj.Get(randArrayGen(n)) mustNotEqual -1
|
||||||
}
|
}
|
||||||
|
|
||||||
"return a number" in {
|
"return a number" in {
|
||||||
|
val n : Int = 26
|
||||||
val obj = new RandomSequenceSelector
|
val obj = new RandomSequenceSelector
|
||||||
val ary = randArrayGen()
|
val ary = randArrayGen(n)
|
||||||
val number = obj.Get(ary)
|
val number = obj.Get(ary)
|
||||||
number mustNotEqual -1
|
number mustNotEqual -1
|
||||||
ary.head mustEqual -1 //regardless of which number we actually got, the head of the array is now -1
|
ary.head mustEqual -1 //regardless of which number we actually got, the head of the array is now -1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue