summaryrefslogtreecommitdiff
path: root/cli/source/test/scala/org/hashtree/stringmetric/cli/similarity/nGramAlgorithmSpec.scala
blob: b041e143f3c334ddb70f3190dc920bc592f18e77 (plain) (blame)
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
package org.hashtree.stringmetric.cli.similarity

import org.hashtree.stringmetric.ScalaTest
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner

@RunWith(classOf[JUnitRunner])
final class nGramAlgorithmSpec extends ScalaTest {
	"nGramAlgorithm" should provide {
		"main method" when passed {
			"valid dashless argument and valid n argument" should executes {
				"print N-Gram representation" in {
					val out = new java.io.ByteArrayOutputStream()

					Console.withOut(out)(
						nGramAlgorithm.main(
							Array(
								"--unitTest",
								"--debug",
								"--n=1",
								"abc"
							)
						)
					)

					out.toString should equal ("a|b|c\n")
					out.reset()

					Console.withOut(out)(
						nGramAlgorithm.main(
							Array(
								"--unitTest",
								"--debug",
								"--n=2",
								"abc"
							)
						)
					)

					out.toString should equal ("ab|bc\n")
					out.reset()
				}
			}
			"valid dashless argument and invalid n argument" should throws {
				"IllegalArgumentException" in {
					evaluating {
						nGramAlgorithm.main(
							Array(
								"--unitTest",
								"abc",
								"abc"
							)
						)
					} should produce [IllegalArgumentException]
				}
			}
			"no dashless argument" should throws {
				"IllegalArgumentException" in {
					evaluating {
						nGramAlgorithm.main(Array("--unitTest", "--debug"))
					} should produce [IllegalArgumentException]
				}
			}
		}
	}
}