RegressionTests__DictionaryTest.st
author sr
Wed, 15 Nov 2017 16:41:47 +0100
changeset 1890 9367c7639c2d
parent 1572 d558d6dc7c45
child 2008 4cfa2ec59dcc
permissions -rw-r--r--
removed not existing Class from project definition
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1447
2351db93aa5b package changes
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
     1
"{ Package: 'stx:goodies/regression' }"
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"{ NameSpace: RegressionTests }"
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
TestCase subclass:#DictionaryTest
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	instanceVariableNames:''
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	classVariableNames:''
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
	poolDictionaries:''
1055
0d0b2641d00b category
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
     9
	category:'tests-Regression-Collections'
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
!DictionaryTest methodsFor:'testing'!
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
testAddAll
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	"(self run: #testAddAll)"
1447
2351db93aa5b package changes
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
    17
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	| dict1 dict2 |
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	dict1 := Dictionary new.
1447
2351db93aa5b package changes
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
    20
	dict1 at: #a put:1 ; at: #b put: 2.
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
	dict2 := Dictionary new.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
	dict2 at: #a put: 3 ; at: #c put: 4.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
	dict1 addAll: dict2.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
	self assert: (dict1 at: #a) = 3.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
	self assert: (dict1 at: #b) = 2.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
	self assert: (dict1 at: #c) = 4.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
!
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
testAssociationsSelect
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
1547
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    31
        "(self selector: #testAssociationsSelect) run"
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
1547
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    33
        | answer d|
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
1547
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    35
        d := Dictionary new.
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    36
        d at: (Array with: #hello with: #world) put: #fooBar.
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    37
        d at: Smalltalk put: #'Smalltalk is the key'.
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    38
        d at: #Smalltalk put: Smalltalk.
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
1547
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    40
        answer := d associationsSelect:
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    41
                [:assoc | (assoc key == #Smalltalk) and: [assoc value == Smalltalk]].
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    42
        self should: [answer isKindOf: Dictionary].
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    43
        self should: [answer size == 1].
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    44
        self should: [(answer at: #Smalltalk) == Smalltalk].
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
1547
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    46
        answer := d associationsSelect:
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    47
                [:assoc | (assoc key == #NoSuchKey) and: [assoc value == #NoSuchValue]].
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    48
        self should: [answer isKindOf: Dictionary].
606e915e2216 #BUGFIX by sr
sr
parents: 1447
diff changeset
    49
        self should: [answer size == 0]
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
!
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
testComma
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
	"(self run: #testComma)"
1447
2351db93aa5b package changes
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
    54
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
	| dict1 dict2 dict3 |
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
	dict1 := Dictionary new.
1447
2351db93aa5b package changes
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
    57
	dict1 at: #a put:1 ; at: #b put: 2.
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
	dict2 := Dictionary new.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
	dict2 at: #a put: 3 ; at: #c put: 4.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
	dict3 := dict1, dict2.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
	self assert: (dict3 at: #a) = 3.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
	self assert: (dict3 at: #b) = 2.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
	self assert: (dict3 at: #c) = 4.
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
!
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
testIncludesAssociation
1553
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    67
        "self debug: #testIncludesAssociation"
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
1553
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    69
        | d |
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    70
        d := Dictionary new
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    71
                at: #five put: 5;
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    72
                at: #givemefive put: 5;
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    73
                at: #six put: 6;
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    74
                yourself.
1447
2351db93aa5b package changes
Claus Gittinger <cg@exept.de>
parents: 1055
diff changeset
    75
1553
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    76
        self assert: (d includesAssociation: (d associationAt: #five)).
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    77
        self assert: (d associationAt: #five) key == #five.
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    78
        self assert: (d associationAt: #five) value == 5.
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    79
        self assert: (d includesAssociation: (#five -> 5)).
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    80
        self assert: (d includesAssociation: (#five -> 6)) not.
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    81
5eecd405c903 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 1547
diff changeset
    82
    "Modified: / 06-12-2016 / 14:19:15 / cg"
1572
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    83
!
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    84
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    85
testRemoveAllDeclareAll
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    86
    "self debug: #testRemoveAllDeclareAll"
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    87
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    88
    "/ verifies that we can restore a dictionaries original contents
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    89
    "/ by making a copy of it, then redeclaring from the copy.
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    90
    "/ (needed by the refactorybrowser)
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    91
    
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    92
    | d copyOfIt |
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    93
    
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    94
    d := Dictionary new
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    95
            at: #five put: (5@5);
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    96
            at: #givemefive put: (55@55);
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    97
            at: #six put: (6@6);
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    98
            yourself.
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
    99
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   100
    copyOfIt := d copy.
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   101
    d keysAndValuesDo:[:k :v |
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   102
        self assert: (copyOfIt at:k) == v.
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   103
    ].
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   104
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   105
    "/ add something
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   106
    d at:#seven put:(7@7).
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   107
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   108
    "/ removeall - redeclare
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   109
    d removeAll; declareAllFrom:copyOfIt.
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   110
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   111
    self assert: (d size = copyOfIt size).
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   112
    self assert: (d keys = copyOfIt keys).
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   113
    d keysAndValuesDo:[:k :v |
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   114
        self assert: (copyOfIt at:k) == v.
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   115
    ].
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   116
d558d6dc7c45 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 1553
diff changeset
   117
    "Created: / 06-02-2017 / 12:26:22 / cg"
296
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
! !
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
!DictionaryTest class methodsFor:'documentation'!
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
version
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    ^ '$Header$'
ddacf68f6660 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
! !
1055
0d0b2641d00b category
Claus Gittinger <cg@exept.de>
parents: 296
diff changeset
   125