RegressionTests__MetaphoneStringComparatorTest.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 18:53:03 +0200
changeset 2327 bf482d49aeaf
parent 2164 3df2a2265f4e
permissions -rw-r--r--
#QUALITY by exept class: RegressionTests::StringTests added: #test82c_expanding
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1670
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:goodies/regression' }"
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"{ NameSpace: RegressionTests }"
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
TestCase subclass:#MetaphoneStringComparatorTest
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:'sc'
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:''
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
	category:'tests-Regression-Collections-Utilities'
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
2164
3df2a2265f4e #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 1675
diff changeset
    13
!MetaphoneStringComparatorTest methodsFor:'initialize / release'!
1670
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
setUp
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
    sc := PhoneticStringUtilities::MetaphoneStringComparator new
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
    "Modified: / 02-08-2017 / 13:03:33 / cg"
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
! !
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!MetaphoneStringComparatorTest methodsFor:'tests'!
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
test01_SomeCombinations
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
    "tests if all char combinations up to size 4 can be soundexed"
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
    
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
    |code s|
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
    ^ self.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
    
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
    self skip:'this test does not really test anything (except if all 4-char string combinations can be soundexed)'.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
    $A to:$Z do:[:c1 |
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
        s := String with:c1.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
        code := (sc phoneticStringsFor:s) first.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
        $A to:$Z do:[:c2 |
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
            s := String with:c1 with:c2.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
            code := (sc phoneticStringsFor:s) first.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
            $A to:$Z do:[:c3 |
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
                s := String with:c1 with:c2 with:c3.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
                code := (sc phoneticStringsFor:s) first.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
                $A to:$Z do:[:c4 |
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
                    s := String with:c1 with:c2 with:c3 with:c4.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
                    code := (sc phoneticStringsFor:s) first.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
                    self assert:( code = s asSoundexCode).
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
                ].
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
            ].
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        ].
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
    ].
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    "Created: / 27-07-2017 / 15:14:53 / cg"
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    "Modified: / 31-07-2017 / 17:51:21 / cg"
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
!
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
test02_WellKnownResults
1675
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    58
    "tests some wellknown metaphone codes"
1670
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    #(
1675
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    61
        'a'         'A'
1670
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
        'Miller'    'MLR'
1675
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    63
        'ch'        'X'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    64
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    65
        'ANASTHA'         'ANS0'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    66
        'DAVIS-CARTER'    'TFSKRTR'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    67
        'ESCARMANT'       'ESKRMNT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    68
        'MERSEAL'         'MRSL'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    69
        'PIEURISSAINT'    'PRSNT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    70
        'ROTMAN'          'RTMN' 
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    71
        'SEAL'            'SL'   
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    72
        'SPARR'           'SPR' 
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    73
        'STARLEPER'       'STRLPR'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    74
        'THRASH'          '0RX' 
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    75
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    76
        'LOGGING'         'LKNK'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    77
        'LOGIC'           'LJK'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    78
        'JUDGES'          'JJS'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    79
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    80
        'SHOOS'           'XS'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    81
        'SHOES'           'XS'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    82
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    83
        'OTTO'            'OT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    84
        'ERIC'            'ERK'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    85
        'DAVE'            'TF'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    86
        'CATHERINE'       'K0RN'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    87
        'KATHERINE'       'K0RN'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    88
        'AUBREY'          'ABR'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    89
        'BRYAN'           'BRYN'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    90
        'BRYCE'           'BRS'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    91
        'STEVEN'          'STFN'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    92
        'HEIDI'           'HT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    93
        'AUTO'            'AT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    94
        'MAURICE'         'MRS'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    95
        'RANDY'           'RNT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    96
        'CAMBRILLO'       'KMBRL'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    97
        'BRIAN'           'BRN'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    98
        'RAY'             'R'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
    99
        'GEOFF'           'JF'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   100
        'BOB'             'BB'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   101
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   102
        'AHA'             'AH'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   103
        'AAH'             'A'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   104
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   105
        'PAUL'            'PL'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   106
        'BATTLEY'         'BTL'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   107
        'WROTE'           'RT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   108
        'THIS'            '0S'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   109
        
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   110
        'MCCALL'          'MKL'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   111
        'MCCROREY'        'MKRR'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   112
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   113
        'Sch'       'SX'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   114
        'Schi'      'SX'
1670
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
        'Schmid'    'SXMT'
1675
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   116
        'Schmidt'   'SXMTT'     "/ bad, but that is how metaphone works
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   117
        'Schmit'    'SXMT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   118
        'Schmitt'   'SXMDT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   119
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   120
        'CHUTE'           'XT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   121
        'SCHEVEL'         'SXFL'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   122
        'SCHROM'          'SXRM'  
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   123
        'SCHUSS'          'SXS'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   124
        'RICHARD'         'RXRT'
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   125
1670
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    ) pairWiseDo:[:word :expected |   
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
        |whatIGot|
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
        whatIGot := sc encode:word.
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
        self assert: (whatIGot = expected).
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    ].
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    "Created: / 27-07-2017 / 15:14:59 / cg"
1675
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   134
    "Modified (comment): / 03-08-2017 / 14:57:10 / cg"
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   135
!
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   136
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   137
test03_SomeCombinations
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   138
    |code|
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   139
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   140
    "/ code := (sc phoneticStringsFor:'AAH') first.
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   141
    code := (sc encode:'AAH').
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   142
    self assert:( code = 'A').
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   143
af8e61132c06 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1670
diff changeset
   144
    "Created: / 03-08-2017 / 14:53:40 / cg"
1670
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
! !
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
!MetaphoneStringComparatorTest class methodsFor:'documentation'!
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
version
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    ^ '$Header$'
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
!
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
version_CVS
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
    ^ '$Header$'
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
! !
281404c7afd4 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156