Skip to content

Commit

Permalink
[sre][tests] Reimplementing the test for issue #977 with the newt tes…
Browse files Browse the repository at this point in the history
…ting API.

Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed Mar 24, 2020
1 parent fae0566 commit 282ec38
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 20 deletions.
Expand Up @@ -26,12 +26,15 @@ import io.sarl.sre.test.framework.^extension.SreRunExtension
import io.sarl.sre.tests.runtime.bugs.bug977.mocks.HelloChildAgent
import io.sarl.sre.tests.runtime.bugs.bug977.mocks.SharedGuardEvaluationAgent0
import io.sarl.sre.tests.runtime.bugs.bug977.mocks.SharedGuardEvaluationAgent1
import io.sarl.sre.tests.runtime.internal.mocks.Bye
import io.sarl.tests.api.extensions.ContextInitExtension
import io.sarl.tests.api.extensions.JavaVersionCheckExtension
import java.util.UUID
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.RepeatedTest
import org.junit.jupiter.api.RepetitionInfo
import org.junit.jupiter.api.Tag
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.^extension.ExtendWith

import static extension io.sarl.tests.api.tools.TestAssertions.*
Expand All @@ -56,12 +59,22 @@ import static extension io.sarl.tests.api.tools.TestAssertions.*
@Tag("run")
class Bug977Test {

@RepeatedTest(10)
//@RepeatedTest(10)
@Test
@DisplayName("Inheritance of event handlers and functions")
def runInheritanceBehaviorExampleCode(extension rc : SreRunContext) : void {
typeof(HelloChildAgent).runSre
var kern = setupTheSreKernel(null, null)

val all = getResults(bootAgentId)
val id0 = UUID::randomUUID
waitForAgentSpawned(id0) [
kern.startAgentWithID(typeof(HelloChildAgent), id0, buildAgentInitializationParameters(1, null))
]

rootContext.defaultSpace.emit(UUID::randomUUID, new Bye)

waitForTheKernel(-1)//STANDARD_TIMEOUT)

val all = getResults(id0)

all.assertContains(
// Execute: on Initialize
Expand Down
Expand Up @@ -25,33 +25,30 @@ import io.sarl.core.Destroy
import io.sarl.core.Initialize
import io.sarl.sre.test.framework.skills.TestingCapacity
import io.sarl.sre.test.framework.skills.TestingSkill
import java.util.concurrent.atomic.AtomicInteger

abstract agent AbstractAgent {

protected var i : int = 0
protected var i = new AtomicInteger(0)

uses TestingCapacity

def ensureSkill(e : Initialize) : void {
setSkill(new TestingSkill(e))
}

on Initialize {
occurrence.ensureSkill
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("1")
}

on Initialize [i < 0] {
occurrence.ensureSkill
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("-1-")
i++
i.incrementAndGet
}

/* A disjoint condition from the previous */
on Initialize [i >= 0] {
occurrence.ensureSkill
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("2")
i--
i.decrementAndGet
}

def sayGoodBye : void {
Expand Down
Expand Up @@ -24,28 +24,28 @@ package io.sarl.sre.tests.runtime.bugs.bug977.mocks
import io.sarl.core.Destroy
import io.sarl.core.Initialize
import io.sarl.core.Lifecycle
import io.sarl.core.Schedules
import io.sarl.sre.test.framework.skills.TestingCapacity
import io.sarl.sre.test.framework.skills.TestingSkill
import io.sarl.sre.tests.runtime.internal.mocks.Bye

agent HelloChildAgent extends AbstractAgent {

uses Lifecycle, Schedules
uses Lifecycle

uses TestingCapacity

on Initialize {
occurrence.ensureSkill
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("3")
in(1000)[killMe]
}

on Initialize {
occurrence.ensureSkill
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("4")
}

on Initialize [i >= 0] {
occurrence.ensureSkill
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("5")
}

Expand All @@ -57,5 +57,9 @@ agent HelloChildAgent extends AbstractAgent {
on Destroy {
sayGoodBye
}

on Bye {
killMe
}

}
Expand Up @@ -24,6 +24,7 @@ package io.sarl.sre.tests.runtime.bugs.bug977.mocks
import io.sarl.core.Initialize
import io.sarl.sre.test.framework.skills.TestingCapacity
import java.util.concurrent.atomic.AtomicInteger
import io.sarl.sre.test.framework.skills.TestingSkill

agent SharedGuardEvaluationAgent0 {

Expand All @@ -32,34 +33,42 @@ agent SharedGuardEvaluationAgent0 {
uses TestingCapacity

on Initialize {
setSkillIfAbsent(new TestingSkill(occurrence))
killMeSoon
}

on Initialize {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("a")
}

on Initialize [i.get < 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("b")
}

on Initialize [i.get <= 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("c")
}

on Initialize [i.get == 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("d")
}

on Initialize [i.get != 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("e")
}

on Initialize [i.get >= 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("f")
}

on Initialize [i.get > 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("g")
}

Expand Down
Expand Up @@ -33,41 +33,48 @@ agent SharedGuardEvaluationAgent1 {
uses TestingCapacity

on Initialize {
setSkill(new TestingSkill(occurrence))
setSkillIfAbsent(new TestingSkill(occurrence))
killMeSoon
}

on Initialize {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("a")
i.set(10)
}

on Initialize [i.get < 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("b")
i.set(10)
}

on Initialize [i.get <= 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("c")
i.set(10)
}

on Initialize [i.get == 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("d")
i.set(10)
}

on Initialize [i.get != 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("e")
i.set(10)
}

on Initialize [i.get >= 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("f")
i.set(10)
}

on Initialize [i.get > 3] {
setSkillIfAbsent(new TestingSkill(occurrence))
addResult("g")
i.set(10)
}
Expand Down

0 comments on commit 282ec38

Please sign in to comment.