-
Notifications
You must be signed in to change notification settings - Fork 3
/
PlanningInstrumentedTest.kt
204 lines (179 loc) · 5.81 KB
/
PlanningInstrumentedTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
package com.softbankrobotics.pddlplanning.test
import android.content.Context
import android.util.Log
import com.example.pddl_planning_test.R
import com.softbankrobotics.pddlplanning.Expression
import com.softbankrobotics.pddlplanning.Task
import com.softbankrobotics.pddlplanning.Tasks
import com.softbankrobotics.pddlplanning.createFact
import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test
typealias ExpressionToTask = Pair<Collection<Expression>, Tasks>
typealias ExpressionsToTasks = List<Pair<Collection<Expression>, Tasks>>
/**
* Provides a set of planning tests to add to your class of Android instrumented tests.
* Extend this interface to inherit exposed tests that will check whether your planner works.
*/
interface PlanningInstrumentedTest : PlanningUnitTest {
/**
* A tag to use for the logs produced by the planning tests.
*/
val logTag: String
/**
* The target context, usually provided by InstrumentationRegistry.
*/
val context: Context
override fun logDebug(message: String) { Log.d(logTag, message) }
@Test
fun plannerSanityCheck() {
val (domain, problem) = domainAndProblemFromRaw(context, R.raw.sample_1)
val expectedPlan = listOf(Task("ask"))
val plan = runBlocking { searchPlan(domain, problem) { Log.d(logTag, it) } }
assertEquals(expectedPlan, plan)
}
@Test
fun simpleServiceDomainInstrumented() {
val (domain, problem) = domainAndProblemFromRaw(context, R.raw.sample_2)
val initsToPlans = mutableListOf<ExpressionToTask>()
initsToPlans.add(
listOf<Expression>() // Nothing to say about user.
to listOf() // Robot has nothing to do.
)
initsToPlans.add(
listOf( // A user entered interaction.
createFact("interacting_with", "user")
) to listOf( // Robots checks them in.
Task.create("greet", "user"),
Task.create("check_in", "user")
)
)
runBlocking { checkPlansForInits(domain, problem, initsToPlans, searchPlan) { Log.d(logTag, it) } }
}
@Test
fun baseExample() {
val plan = searchPlanFromResource(R.raw.example_base)
assertEquals(
plan,
listOf(
Task.create("joke_with", "alice"),
Task.create("joke_with", "bob")
)
)
}
@Test
fun aliceIsAlreadyHappy() {
val plan = searchPlanFromResource(R.raw.example_alice_happy)
assertEquals(
plan,
listOf(
Task.create("joke_with", "bob")
)
)
}
@Test
fun everybodyIsHappy() {
val plan = searchPlanFromResource(R.raw.example_everybody_happy)
assertEquals(
plan,
listOf<Task>()
)
}
@Test
fun nobodyAroundError() {
assertThrows(Throwable::class.java) {
searchPlanFromResource(R.raw.example_nobody_around_error)
}
}
@Test
fun nobodyAroundConditionalGoal() {
val plan = searchPlanFromResource(R.raw.example_nobody_around_conditional_goal)
assertEquals(
plan,
listOf<Task>()
)
}
@Test
fun aliceIsAroundConditionalGoal() {
val plan = searchPlanFromResource(R.raw.example_alice_around_conditional_goal)
assertEquals(
plan,
listOf(
Task.create("joke_with", "alice")
)
)
}
@Test
fun intrinsicAbsence() {
val plan = searchPlanFromResource(R.raw.example_intrinsic_absence)
assertEquals(plan, listOf(Task.create("joke_with", "alice")))
}
@Test
fun nonDeterministic() {
val plan = searchPlanFromResource(R.raw.example_non_deterministic)
assertEquals(
plan,
listOf(
Task.create("find_human", "alice"),
Task.create("find_human", "bob"),
Task.create("joke_with", "bob"),
Task.create("joke_with", "alice")
)
)
}
@Test
fun partialObservability() {
val plan = searchPlanFromResource(R.raw.example_partial_observability)
assertEquals(
plan,
listOf(
Task.create("find_human", "alice"),
Task.create("find_human", "bob"),
Task.create("joke_with", "bob"),
Task.create("joke_with", "alice")
)
)
}
@Test
fun partialObservabilityNext() {
val plan = searchPlanFromResource(R.raw.example_partial_observability_next)
assertEquals(
plan,
listOf(
Task.create("find_human", "bob"),
Task.create("joke_with", "bob")
)
)
}
@Test
fun objectDiscoveryNobody() {
val plan = searchPlanFromResource(R.raw.example_object_discovery_nobody)
assertEquals(
plan,
listOf(
Task.create("find_human", "someone"),
Task.create("joke_with", "someone")
)
)
}
@Test
fun objectDiscovery() {
val plan = searchPlanFromResource(R.raw.example_object_discovery)
assertEquals(
plan,
listOf(
Task.create("find_human", "alice"),
Task.create("joke_with", "alice")
)
)
}
@Test
fun objectDiscoveryNext() {
val plan = searchPlanFromResource(R.raw.example_object_discovery_next)
assertEquals(plan, listOf(Task.create("joke_with", "charles")))
}
private fun searchPlanFromResource(resource: Int): List<Task> {
return searchPlanFromResource(context, resource, searchPlan, ::logDebug)
}
}