This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-491
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-491 by this push:
new ff326069 WIP.
ff326069 is described below
commit ff3260697231b99e256a60e34eca5966b616d8e7
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Apr 7 16:50:59 2022 +0300
WIP.
---
.../examples/order/PizzeriaModelSpec.scala | 112 +++++++++++++++------
1 file changed, 82 insertions(+), 30 deletions(-)
diff --git
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/order/PizzeriaModelSpec.scala
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/order/PizzeriaModelSpec.scala
index afe36b93..38a13282 100644
---
a/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/order/PizzeriaModelSpec.scala
+++
b/nlpcraft-examples/pizzeria/src/test/java/org/apache/nlpcraft/examples/order/PizzeriaModelSpec.scala
@@ -19,7 +19,7 @@ package org.apache.nlpcraft.examples.order
import org.apache.nlpcraft.*
import org.apache.nlpcraft.NCResultType.*
-import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.{AfterEach, BeforeEach, Test}
import scala.util.Using
import scala.collection.mutable
@@ -27,34 +27,86 @@ import scala.collection.mutable
*
*/
class PizzeriaModelSpec:
+ private val msgs = mutable.ArrayBuffer.empty[mutable.ArrayBuffer[String]]
+ private val errs = mutable.HashMap.empty[Int, Throwable]
+
+ private var client: NCModelClient = _
+ private var testNum: Int = 0
+
+ @BeforeEach def setUp(): Unit = client = new NCModelClient(new
PizzeriaModel)
+ @AfterEach def tearDown(): Unit =
+ if client != null then client.close()
+
+ for ((seq, num) <- msgs.zipWithIndex)
+
println("#################################################################################################")
+ for (line <- seq) println(line)
+ errs.get(num) match
+ case Some(err) => err.printStackTrace()
+ case None => // No-op.
+ println()
+
+ require(errs.isEmpty)
+
+ private def dialog(reqs: String*): Unit =
+ val testMsgs = mutable.ArrayBuffer.empty[String]
+ msgs += testMsgs
+
+ testMsgs += s"Test: $testNum"
+
+ for ((txt, idx) <- reqs.zipWithIndex)
+ try
+ val resp = client.ask(txt, null, "userId")
+
+ testMsgs += s">> Request: $txt"
+ testMsgs += s">> Response: '${resp.getType}': ${resp.getBody}"
+
+ val expType = if idx == reqs.size - 1 then ASK_RESULT else
ASK_DIALOG
+
+ if expType != resp.getType then
+ errs += testNum -> new Exception(s"Error during test
[num=$testNum, expRespType=$expType, type=${resp.getType}]")
+ catch
+ case e: Exception => errs += testNum -> new Exception(s"Error
during test [num=$testNum]", e)
+
+ testNum += 1
+
@Test
def test(): Unit =
- val buf = mutable.ArrayBuffer.empty[String]
-
- def printDialog(): Unit = buf.foreach(println)
-
- Using.resource(new NCModelClient(new PizzeriaModel)) { client =>
- def ask(txt: String, expResType: NCResultType): Unit =
- try
- val resp = client.ask(txt, null, "userId")
-
- buf += s">> Request: $txt"
- buf += s">> Response: '${resp.getType}': ${resp.getBody}"
- buf += ""
-
- if expResType != resp.getType then
- printDialog()
- require(false, s"Unexpected type: ${resp.getType},
expected: $expResType.")
- catch {
- case e: Exception =>
- printDialog()
- throw e
- }
- ask("I want to order carbonara, marinara and tea", ASK_DIALOG)
- ask("large size please", ASK_DIALOG)
- ask("smallest", ASK_DIALOG)
- ask("yes", ASK_DIALOG)
- ask("correct", ASK_RESULT)
-
- printDialog()
- }
\ No newline at end of file
+ dialog(
+ "One tea",
+ "yes",
+ "yes"
+ )
+
+ dialog(
+ "I want to order carbonara, marinara and tea",
+ "large size please",
+ "smallest",
+ "yes",
+ "correct"
+ )
+
+ dialog(
+ "carbonara two small",
+ "yes",
+ "yes"
+ )
+
+ dialog(
+ "carbonara",
+ "small",
+ "yes",
+ "yes"
+ )
+
+ dialog(
+ "carbonara",
+ "stop"
+ )
+
+ dialog(
+ "carbonara two, marinara and 2 tea",
+ "small",
+ "small",
+ "yes",
+ "yes"
+ )
\ No newline at end of file