You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/03/29 10:28:32 UTC
[incubator-nlpcraft] branch NLPCRAFT-28 updated: All tests
refactored as junit tests.
This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-28
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-28 by this push:
new 1c3e87a All tests refactored as junit tests.
1c3e87a is described below
commit 1c3e87adabab117189cfa38a2749e328fdc07087
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Sun Mar 29 13:28:26 2020 +0300
All tests refactored as junit tests.
---
.../nlpcraft/common/ascii/NCAsciiTableSpec.scala | 15 ++++++-----
.../common/blowfish/NCBlowfishHasherSpec.scala | 9 +++----
.../nlpcraft/common/crypto/NCCipherSpec.scala | 27 ++++++++++---------
.../nlpcraft/common/makro/NCMacroParserSpec.scala | 31 ++++++++++++----------
.../apache/nlpcraft/common/util/NCUtilsSpec.scala | 20 ++++++++------
.../intent/impl/NCIntentSolverEngineSpec.scala | 13 +++++----
.../model/tools/NCSqlModelEngineSpec.scala | 24 +++++++++--------
7 files changed, 74 insertions(+), 65 deletions(-)
diff --git a/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala b/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala
index 3a73921..2b44d93 100644
--- a/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/common/ascii/NCAsciiTableSpec.scala
@@ -17,15 +17,14 @@
package org.apache.nlpcraft.common.ascii
-import org.scalatest.FlatSpec
+import org.junit.jupiter.api.Test
/**
* Test for ASCII text table.
*/
-class NCAsciiTableSpec extends FlatSpec {
- behavior of "ASCII table"
-
- it should "render" in {
+class NCAsciiTableSpec {
+ @Test
+ def test() {
val t = NCAsciiTable()
t.headerStyle = "leftPad: 10, rightPad: 5"
@@ -42,7 +41,8 @@ class NCAsciiTableSpec extends FlatSpec {
t.render()
}
- it should "render with sequence header" in {
+ @Test
+ def testWithSequenceHeader() {
val t = NCAsciiTable()
t.headerStyle = "leftPad: 10, rightPad: 5"
@@ -57,7 +57,8 @@ class NCAsciiTableSpec extends FlatSpec {
t.render()
}
- it should "render a very big table" in {
+ @Test
+ def testWithVeryBigTable() {
val NUM = 1000
val start = System.currentTimeMillis()
diff --git a/src/test/scala/org/apache/nlpcraft/common/blowfish/NCBlowfishHasherSpec.scala b/src/test/scala/org/apache/nlpcraft/common/blowfish/NCBlowfishHasherSpec.scala
index c853d21..93901e6 100644
--- a/src/test/scala/org/apache/nlpcraft/common/blowfish/NCBlowfishHasherSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/common/blowfish/NCBlowfishHasherSpec.scala
@@ -17,15 +17,14 @@
package org.apache.nlpcraft.common.blowfish
-import org.scalatest.FlatSpec
+import org.junit.jupiter.api.Test
/**
* Tests for Blowfish hasher.
*/
-class NCBlowfishHasherSpec extends FlatSpec {
- behavior of "Blowfish hasher"
-
- it should "properly hash password" in {
+class NCBlowfishHasherSpec {
+ @Test
+ def testWithSequenceHeader() {
val email = "dev@nlpcraft.org"
val passwd = "test"
diff --git a/src/test/scala/org/apache/nlpcraft/common/crypto/NCCipherSpec.scala b/src/test/scala/org/apache/nlpcraft/common/crypto/NCCipherSpec.scala
index 69d2210..a1398fc 100644
--- a/src/test/scala/org/apache/nlpcraft/common/crypto/NCCipherSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/common/crypto/NCCipherSpec.scala
@@ -20,24 +20,24 @@ package org.apache.nlpcraft.common.crypto
import java.util.Base64
import org.apache.nlpcraft.common._
-import org.scalatest.{BeforeAndAfter, FlatSpec}
-
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
/**
* Tests for crypto and PKI support.
*/
-class NCCipherSpec extends FlatSpec with BeforeAndAfter {
- behavior of "Cipher"
-
+class NCCipherSpec {
private final val IN = "abcdefghijklmnopqrstuvwxyz0123456789"
- it should "properly encrypt and decrypt" in {
+ @Test
+ def testEncryptDecrypt() {
val s1 = NCCipher.encrypt(IN)
val s2 = NCCipher.decrypt(s1)
- assertResult(IN)(s2)
+ assertEquals(IN, s2)
}
- it should "produce different encrypted string for the same input" in {
+ @Test
+ def testDifference() {
val s1 = NCCipher.encrypt(IN)
val s2 = NCCipher.encrypt(IN)
val s3 = NCCipher.encrypt(IN)
@@ -49,12 +49,13 @@ class NCCipherSpec extends FlatSpec with BeforeAndAfter {
val r2 = NCCipher.decrypt(s2)
val r3 = NCCipher.decrypt(s3)
- assertResult(r1)(IN)
- assertResult(r2)(IN)
- assertResult(r3)(IN)
+ assertEquals(IN, r1)
+ assertEquals(IN, r2)
+ assertEquals(IN, r3)
}
-
- it should "properly encrypt" in {
+
+ @Test
+ def testCorrectness() {
val buf = new StringBuilder
// Max long string.
diff --git a/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala b/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
index 6de969b..1068d21 100644
--- a/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
@@ -18,7 +18,7 @@
package org.apache.nlpcraft.common.makro
import org.apache.nlpcraft.common._
-import org.scalatest.FlatSpec
+import org.junit.jupiter.api.Test
import scala.compat.Platform._
import scala.util.control.Exception._
@@ -26,9 +26,7 @@ import scala.util.control.Exception._
/**
* Tests for text parser.
*/
-class NCMacroParserSpec extends FlatSpec {
- behavior of "Text parser"
-
+class NCMacroParserSpec {
private val parser = NCMacroParser(
"<A>" → "aaa",
"<B>" → "<A> bbb",
@@ -87,8 +85,9 @@ class NCMacroParserSpec extends FlatSpec {
assert(grps == elms.map(_.head))
}
-
- it should "measure performance" in {
+
+ @Test
+ def testPerformance() {
val start = currentTime
val N = 50000
@@ -100,8 +99,9 @@ class NCMacroParserSpec extends FlatSpec {
println(s"${N * 1000 / duration} ops/second.")
}
-
- it should "expand string" in {
+
+ @Test
+ def testExpand() {
// Make sure we can parse these.
parser.expand("<OF>")
parser.expand("<QTY>")
@@ -217,8 +217,9 @@ class NCMacroParserSpec extends FlatSpec {
ignoreNCE { testParser("a}}", Seq.empty); assert(false) }
ignoreNCE { testParser("a {a|b} *", Seq.empty); assert(false) }
}
-
- it should "parse option group" in {
+
+ @Test
+ def testOptionGroup() {
testGroup("{a {b|c} | d}", Seq("a {b|c} ", " d"))
testGroup("{a|b}", Seq("a", "b"))
testGroup("{a}", Seq("a"))
@@ -231,8 +232,9 @@ class NCMacroParserSpec extends FlatSpec {
ignoreNCE { parser.parseGroup("{a"); assert(false) }
ignoreNCE { parser.parseGroup("a}"); assert(false) }
}
-
- it should "parse token" in {
+
+ @Test
+ def testParseTokens() {
testToken("""a \* b""", """a \* b""", "")
testToken("""a \\\* b""", """a \\\* b""", "")
testToken("""a \{\*\*\*\} b""", """a \{\*\*\*\} b""", "")
@@ -252,8 +254,9 @@ class NCMacroParserSpec extends FlatSpec {
assert(parser.nextToken("").isEmpty)
assert(parser.nextToken(" ").isDefined)
}
-
- it should "obey max limit" in {
+
+ @Test
+ def testLimit() {
ignoreNCE {
parser.expand("<METRICS> <USER> <BY> <WEBSITE> <BY> <SES> <BY> <METRICS> <BY> <USER> <BY> <METRICS>")
diff --git a/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala b/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala
index 569b32e..d4b5e5c 100644
--- a/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/common/util/NCUtilsSpec.scala
@@ -18,13 +18,14 @@
package org.apache.nlpcraft.common.util
import org.apache.nlpcraft.common._
-import org.scalatest.FlatSpec
+import org.junit.jupiter.api.Test
/**
* Utilities tests.
*/
-class NCUtilsSpec extends FlatSpec {
- "inflate() and deflate() methods" should "work" in {
+class NCUtilsSpec {
+ @Test
+ def testInflateDeflate() {
val rawStr = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when " +
"an unknown printer took a galley of type and scrambled it to make a type specimen book. " +
@@ -42,20 +43,23 @@ class NCUtilsSpec extends FlatSpec {
assert(rawStr == rawStr2)
}
-
- "getDups() method" should "properly work" in {
+
+ @Test
+ def testGetDups() {
assert(U.getDups(Seq("a", "b", "a")) == Set("a"))
assert(U.getDups(Seq("a", "a", "a", "b", "a")) == Set("a"))
assert(U.getDups(Seq("a", "d", "c", "b", "e")) == Set())
}
-
- "toFirstLastName() method" should "properly work" in {
+
+ @Test
+ def testToFirstLastName() {
assert(U.toFirstLastName("A BbbBB") == ("A", "Bbbbb"))
assert(U.toFirstLastName("aBC BbbBB CCC") == ("Abc", "Bbbbb ccc"))
assert(U.toFirstLastName("abc b C C C") == ("Abc", "B c c c"))
}
- "sleep method" should "work without unnecessary logging" in {
+ @Test
+ def testWorkWithoutUnnecessaryLogging() {
val t = new Thread() {
override def run(): Unit = {
while (!isInterrupted) {
diff --git a/src/test/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngineSpec.scala b/src/test/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngineSpec.scala
index c52e291..6bd7f1c 100644
--- a/src/test/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngineSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngineSpec.scala
@@ -18,14 +18,12 @@
package org.apache.nlpcraft.model.intent.impl
import org.apache.nlpcraft.model.intent.utils.NCDslFlowItem
-import org.scalatest.FlatSpec
+import org.junit.jupiter.api.Test
/**
* Unit tests for intent solver engine.
*/
-class NCIntentSolverEngineSpec extends FlatSpec {
- behavior of "Intent solver engine"
-
+class NCIntentSolverEngineSpec {
/**
*
* @param hist Matched intents.
@@ -34,12 +32,13 @@ class NCIntentSolverEngineSpec extends FlatSpec {
*/
private def matchFlow(hist: String, flow: (String/*Intent ID*/, Int/*min*/, Int/*max*/)*): Boolean = {
NCIntentSolverEngine.matchFlow(
- flow.toArray.map(x ⇒ new NCDslFlowItem(x._1.split('|').map(_.trim), x._2, x._3)),
+ flow.toArray.map(x ⇒ NCDslFlowItem(x._1.split('|').map(_.trim), x._2, x._3)),
hist.split(" ").map(_.trim)
)
}
-
- it should "match dialog flow" in {
+
+ @Test
+ def testMatchDialogFlow() {
assert(!matchFlow("", ("a", 1, 1)))
assert(matchFlow("a c", ("a", 1, 1), ("b", 0, 2), ("c", 1, 1)))
assert(matchFlow("a b c", ("a", 1, 1), ("b", 0, 2), ("c", 1, 1)))
diff --git a/src/test/scala/org/apache/nlpcraft/model/tools/NCSqlModelEngineSpec.scala b/src/test/scala/org/apache/nlpcraft/model/tools/NCSqlModelEngineSpec.scala
index 6b9fe73..11c7729 100644
--- a/src/test/scala/org/apache/nlpcraft/model/tools/NCSqlModelEngineSpec.scala
+++ b/src/test/scala/org/apache/nlpcraft/model/tools/NCSqlModelEngineSpec.scala
@@ -17,14 +17,12 @@
package org.apache.nlpcraft.model.tools
-import org.scalatest.FlatSpec
+import org.junit.jupiter.api.Test
/**
* TODO: add description.
*/
-class NCSqlModelEngineSpec extends FlatSpec {
- behavior of "SQL model engine"
-
+class NCSqlModelEngineSpec {
/**
* Copy of the private method from 'NCSqlModelEngine'.
*
@@ -74,8 +72,9 @@ class NCSqlModelEngineSpec extends FlatSpec {
case Some(head) if head == w ⇒ list // Skip duplicate 'w'.
case _ ⇒ w :: list
}).mkString(" ")
-
- it should "correctly remove prefix" in {
+
+ @Test
+ def testRemovePrefix() {
val fun1 = mkPrefixFun("tbl_, col_")
val fun2 = mkPrefixFun("")
val fun3 = mkPrefixFun("tbl_tbl_, col_")
@@ -87,8 +86,9 @@ class NCSqlModelEngineSpec extends FlatSpec {
assert(fun1("_col_column") == "_col_column")
assert(fun2("col_column") == "col_column")
}
-
- it should "correctly remove suffix" in {
+
+ @Test
+ def testRemoveSuffix() {
val fun1 = mkSuffixFun("_tmp, _old")
val fun2 = mkSuffixFun("")
val fun3 = mkSuffixFun("_tmp_tmp")
@@ -101,13 +101,15 @@ class NCSqlModelEngineSpec extends FlatSpec {
assert(fun2("column_old") == "column_old")
}
- it should "correctly substitute macros" in {
+ @Test
+ def testSubstituteMacros() {
assert(substituteMacros("a id") == "a <ID>")
assert(substituteMacros("a id ") == "a <ID>")
assert(substituteMacros("id") == "<ID>")
}
-
- it should "correctly remove sequential dups" in {
+
+ @Test
+ def testRemoveSequentialDups() {
assert(removeSeqDups("a a b b") == "a b")
assert(removeSeqDups("aa b b") == "aa b")
assert(removeSeqDups("aa b b") == "aa b")