RegressionTests__SoundexStringComparatorTest.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 18:53:03 +0200
changeset 2327 bf482d49aeaf
parent 2153 3bcad3f6dd0b
permissions -rw-r--r--
#QUALITY by exept class: RegressionTests::StringTests added: #test82c_expanding

"{ Package: 'stx:goodies/regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#SoundexStringComparatorTest
	instanceVariableNames:'sc'
	classVariableNames:''
	poolDictionaries:''
	category:'tests-Regression-Collections-Utilities'
!


!SoundexStringComparatorTest methodsFor:'initialize / release'!

setUp
    sc := PhoneticStringUtilities::SoundexStringComparator new
! !

!SoundexStringComparatorTest methodsFor:'tests'!

test01_SomeCombinations
    "tests if all char combinations up to size 4 can be soundexed"
    
    |code s|

    ^ self.
    
    self skip:'this test does not really test anything (except if all 4-char string combinations can be soundexed)'.

    $A to:$Z do:[:c1 |
        s := String with:c1.
        code := (sc phoneticStringsFor:s) first.

        $A to:$Z do:[:c2 |
            s := String with:c1 with:c2.
            code := (sc phoneticStringsFor:s) first.

            $A to:$Z do:[:c3 |
                s := String with:c1 with:c2 with:c3.
                code := (sc phoneticStringsFor:s) first.

                $A to:$Z do:[:c4 |
                    s := String with:c1 with:c2 with:c3 with:c4.
                    code := (sc phoneticStringsFor:s) first.
                    self assert:( code = s asSoundexCode).
                ].
            ].
        ].
    ].

    "Created: / 27-07-2017 / 15:14:53 / cg"
    "Modified: / 31-07-2017 / 17:51:21 / cg"
!

test02_WellKnownResults
    "tests some wellknown soundex codes"

    |code soundex xx|

    soundex := [:w | (sc phoneticStringsFor:w) first].

    self assert: ( soundex value:( 'Swhgler' )) = 'S246' .  "/ DIFFERENT from miracode (american) soundex

    code := (sc phoneticStringsFor:'Miller') first.
    self assert:( code = 'Miller' asSoundexCode).

    #( 'Acton' 'Ashdown' 'Ashton' 'Astin' 'Aston' 'Austen' 'Austin' 'Austine' 'Axten')
    do:[:w |
        code := soundex value:(w).
        self assert:( code = 'A235').
    ].

    #( 'Reader' 'Reeder' 'Rider' 'Ritter' 'Rothera' 'Rothra' 'Ruder' 'Rutter' 'Ryder')
    do:[:w |
        code := soundex value:(w).
        self assert:( code = 'R360').
    ].

    #( 'Wace' 'Waugh' 'Wookey')
    do:[:w |
        code := soundex value:(w).
        self assert:( code = 'W200').
    ].

    code := soundex value:('Abbot').
    self assert:( code = 'Abbot' asSoundexCode).
    self assert:( code = 'A130' ).

    code := soundex value:('Abbots').
    self assert:( code = 'Abbots' asSoundexCode).
    self assert:( code = 'A132' ).

    code := soundex value:('Ashcroft').
    self assert:( code = 'Ashcroft' asSoundexCode).
    self assert:( code = 'A226' ).

    code := soundex value:('Lloyd').
    self assert:( code = 'Lloyd' asSoundexCode).
    self assert:( code = 'L300' ).

    code := soundex value:('Pfister').
    self assert:( code = 'Pfister' asSoundexCode).
    self assert:( code = 'P236' ).

    "/ self assert: ( soundex value:( 'A' )) = 'A000' .
    "/ ...
    "/ self assert: ( soundex value:( 'Z' )) = 'Z000' .
    $A to:$Z do:[:singleChar |
        self assert: ( soundex value:( singleChar asString )) = (singleChar asString,'000') .
    ].    

    self assert: ( soundex value:( 'AEHIOW' )) = 'A000' .
    self assert: ( soundex value:( 'BPFV' )) = 'B000' .
    self assert: ( soundex value:( 'CGJKQSXZ' )) = 'C000' .
    self assert: ( soundex value:( 'DT' )) = 'D000' .
    self assert: ( soundex value:( 'MN' )) = 'M000' .

    self assert: ( soundex value:( 'ADAD' )) = 'A330' .
    self assert: ( soundex value:( 'ADHD' )) = 'A330' .  "/ DIFFERENT from miracode (american) soundex
    self assert: ( soundex value:( 'ADWD' )) = 'A330' .  "/ DIFFERENT from miracode (american) soundex

    "/ self assert: ( soundex value:( 'Ashcroft' )) = 'A22613' .
    self assert: ( soundex value:( 'Ashcroft' )) = 'A226' . "/ DIFFERENT from miracode (american) soundex
    self assert: ( soundex value:( 'Tymczak' )) = 'T522' .
    self assert: ( soundex value:( 'Jackson' )) = 'J250' .
    self assert: ( soundex value:( 'Pfister' )) = 'P236' .
    self assert: ( soundex value:( 'Gutierrez' )) = 'G362' .
    self assert: ( soundex value:( 'Lee' )) = 'L000' .
    "/ self assert: ( soundex value:( 'Washington' )) = 'W25235' .
    self assert: ( soundex value:( 'Washington' )) = 'W252' .

    self assert: ( soundex value:( 'Williams' )) = 'W452' .
    "/ self assert: ( soundex value:( 'Baragwanath' )) = 'B6253' .
    self assert: ( soundex value:( 'Baragwanath' )) = 'B625' .
    self assert: ( soundex value:( 'Donnell' )) = 'D540' .
    self assert: ( soundex value:( 'Lloyd' )) = 'L300' .
    self assert: ( soundex value:( 'Woolcock' )) = 'W422' .

    self assert: ( soundex value:( 'Cook' )) = 'C200' .

    self assert: ( soundex value:( 'Allricht' )) = 'A462' .
    self assert: ( soundex value:( 'Eberhard' )) = 'E166' .
    self assert: ( soundex value:( 'Engebrethson' )) = 'E521' .
    self assert: ( soundex value:( 'Heimbach' )) = 'H512' .
    self assert: ( soundex value:( 'Hanselmann' )) = 'H524' .
    self assert: ( soundex value:( 'Henzelmann' )) = 'H524' .
    self assert: ( soundex value:( 'Hildebrand' )) = 'H431' .
    self assert: ( soundex value:( 'Kavanagh' )) = 'K152' .
    "/ self assert: ( soundex value:( 'Lind, Van' )) = 'L530' .
    self assert: ( soundex value:( 'Lind' )) = 'L530' .
    self assert: ( soundex value:( 'Lukaschowsky' )) = 'L222' .
    self assert: ( soundex value:( 'McDonnell' )) = 'M235' .
    self assert: ( soundex value:( 'McGee' )) = 'M200' .
    self assert: ( soundex value:( 'Miller' )) = 'M460' .
    self assert: ( soundex value:( 'Muller' )) = 'M460' .
    self assert: ( soundex value:( 'Mueller' )) = 'M460' .
    self assert: ( soundex value:( 'Milner' )) = 'M456' .
    self assert: ( soundex value:( 'Millner' )) = 'M456' .
    self assert: ( soundex value:( 'Miner' )) = 'M560' .
    self assert: ( soundex value:( 'Mimer' )) = 'M560' .
    self assert: ( soundex value:( 'O''Brien' )) = 'O165' .
    self assert: ( soundex value:( 'Opnian' )) = 'O155' .
    self assert: ( soundex value:( 'Oppenheimer' )) = 'O155' .
    self assert: ( soundex value:( 'Swhgler' )) = 'S246' .    "/ DIFFERENT from miracode (american) soundex
    self assert: ( soundex value:( 'Riedemanas' )) = 'R355' .
    self assert: ( soundex value:( 'Zita' )) = 'Z300' .
    self assert: ( soundex value:( 'Zitzmeinn' )) = 'Z325' .

    self assert: ( soundex value:( 'Robert' )) = 'R163' .
    self assert: ( soundex value:( 'Rupert' )) = 'R163' .
    self assert: ( soundex value:( 'Rubin' )) = 'R150' .

    #('Fusedale') 
        do:[:each | self assert: ( soundex value:each) = 'F234'].

    #('Genthner' 'Gentner' 'Gianettini' 'Gunton') 
        do:[:each | self assert: ( code := soundex value:each) = 'G535'].

    #('Garlee' 'Garley' 'Garwell' 'Garwill' 'Gerrell' 'Gerrill' 'Giral' 'Gorelli' 'Gorioli' 'Gourlay' 'Gourley' 'Gourlie' 'Graal' 'Grahl' 'Grayley' 'Grealey' 'Greally' 'Grealy' 'Grioli' 'Groll' 'Grolle' 'Guerola' 'Gurley') 
        do:[:each | self assert: ( code := soundex value:each) = 'G640'].

    #('Hadcroft' 'Hadgraft' 'Hatchard' 'Hatcher' 'Hatzar' 'Hedger' 'Hitscher' 'Hodcroft') 
        do:[:each | xx := each. self assert: ( code := soundex value:each) = 'H326'].

    #('Hutchcraft') 
        do:[:each | xx := each. self assert: ( code := soundex value:each) = 'H322'].

    #('Parade' 'Pardew' 'Pardey' 'Pardi' 'Pardie' 'Pardoe' 'Pardue' 'Pardy' 'Parradye' 'Parratt' 'Parrett' 'Parrot' 'Parrott' 'Pearde' 'Peart' 'Peaurt' 'Peert' 'Perdue' 'Peret' 'Perett' 'Perot' 'Perott' 'Perotti' 'Perrat' 'Perrett' 'Perritt' 'Perrot' 'Perrott' 'Pert' 'Perutto' 'Pirdue' 'Pirdy' 'Pirot' 'Pirouet' 'Pirt' 'Porrett' 'Porritt' 'Port' 'Porte' 'Portt' 'Prate' 'Prati' 'Pratt' 'Pratte' 'Pratty' 'Preddy' 'Preedy' 'Preto' 'Pretti' 'Pretty' 'Prewett' 'Priddey' 'Priddie' 'Priddy' 'Pride' 'Pridie' 'Pritty' 'Prott' 'Proud' 'Prout' 'Pryde' 'Prydie' 'Purdey' 'Purdie' 'Purdy') 
        do:[:each | xx := each. self assert: ( code := soundex value:each) = 'P630'].

    "Created: / 27-07-2017 / 15:14:59 / cg"
    "Modified: / 03-08-2017 / 15:04:05 / cg"
! !

!SoundexStringComparatorTest class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !