summaryrefslogtreecommitdiff
path: root/core/src/test/scala/com/rockymadden/stringmetric/StringAlgorithmSpec.scala
blob: 6366685ecf23194c30c7c3e1dc71a35390c3512c (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
package com.rockymadden.stringmetric

import com.rockymadden.stringmetric.phonetic._
import com.rockymadden.stringmetric.transform._

object StringAlgorithmSpec extends org.specs2.mutable.SpecificationWithJUnit {
	"StringAlgorithm convenience methods" should {
		"pass through" in {
			StringAlgorithm.computeWithMetaphone("testone").get must
				beEqualTo(MetaphoneAlgorithm.compute("testone".toCharArray).get)
			StringAlgorithm.computeWithNysiis("testone").get must
				beEqualTo(NysiisAlgorithm.compute("testone".toCharArray).get)
			StringAlgorithm.computeWithRefinedNysiis("testone").get must
				beEqualTo(RefinedNysiisAlgorithm.compute("testone".toCharArray).get)
			StringAlgorithm.computeWithRefinedSoundex("testone").get must
				beEqualTo(RefinedSoundexAlgorithm.compute("testone".toCharArray).get)
			StringAlgorithm.computeWithSoundex("testone").get must
				beEqualTo(SoundexAlgorithm.compute("testone".toCharArray).get)
		}
	}

	"StringAlgorithmDecorator withMemoization()" should {
		"memoize" in {
			val memo = MetaphoneAlgorithm withMemoization

			(0 until 1000000) foreach { i =>
				memo.compute("abc123")
				memo.compute("abc456")
			}

			true must beTrue
		}
	}

	"StringAlgorithmDecorator withTransform()" should {
		"transform" in {
			(MetaphoneAlgorithm withTransform filterAlpha).compute("abc123").get must
				beEqualTo(MetaphoneAlgorithm.compute("abc").get)
		}
	}
}