RegressionTests__WeakCollectionTest.st
author Claus Gittinger <cg@exept.de>
Fri, 21 Dec 2001 16:43:38 +0100
changeset 146 b86931293eb3
child 181 a56517005229
permissions -rw-r--r--
initial checkin

"{ Package: 'exept:regression' }"

"{ NameSpace: RegressionTests }"

TestCase subclass:#WeakCollectionTest
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'Tests-Regression'
!


!WeakCollectionTest methodsFor:'tests'!

fetchValueAtKey:k from:aWeakValueDict

    ^ aWeakValueDict at:k

    "
     self run:#testWeakValueDictionary3
    "
!

fetchValueAtKey:k from:aWeakValueDict ifAbsent:exArg

    ^ aWeakValueDict at:k ifAbsent:exArg

    "
     self run:#testWeakValueDictionary3
    "
!

testWeakValueDictionary1
    |ww N|

    N := 10000.

    ww := WeakValueDictionary new.

    1 "100" timesRepeat:[
        (1 to:N) do:[:idx |
            |k v|

            k := 'k_' , idx printString , '_12345678901234567890'.
            v := 'v_' , idx printString , '_12345678901234567890'.
            ww at:k put:v.
        ].

        (1 to:N) do:[:idx |
            |k v|

            k := 'k_' , idx printString , '_12345678901234567890'.
            v := ww at:k ifAbsent:nil.
            v notNil ifTrue:[
                self halt.
            ]
        ].
    ].

    "
     self run:#testWeakValueDictionary1
    "
!

testWeakValueDictionary2
    |ww k v|

    ww := WeakValueDictionary new.

    ObjectMemory scavenge.

    k := 'k_' , 1 printString , '_12345678901234567890'.
    v := 'v_' , 1 printString , '_12345678901234567890'.
    ww at:k put:v.

    self assert: ( (ww at:k) == v ).
    ObjectMemory scavenge.
    self assert: ( (ww at:k) == v ).
    v := v copy.
    self assert: ( (ww at:k) = v ).
    ObjectMemory scavenge.
    self assert: ( (ww at:k ifAbsent:nil) == nil ).


    "
     self run:#testWeakValueDictionary2
    "
!

testWeakValueDictionary3
    |ww k v v2|

    ww := WeakValueDictionary new.

    ObjectMemory scavenge.

    k := 'k_' , 1 printString , '_12345678901234567890'.
    v := 'v_' , 1 printString , '_12345678901234567890'.
    ww at:k put:v.

    v2 := self fetchValueAtKey:k from:ww.
    self assert: ( v2 == v ).
    v2 := nil.

    v := v copy.
    ObjectMemory scavenge.
    v2 := self fetchValueAtKey:k from:ww ifAbsent:nil.
    self assert: ( v2 == nil ).
    v2 := nil.


    "
     self run:#testWeakValueDictionary3
    "
! !

!WeakCollectionTest class methodsFor:'documentation'!

version
    ^ '$Header$'
! !