RegressionTests__CacheDictionaryTest.st
author sr
Tue, 04 Feb 2020 12:27:07 +0100
changeset 2546 c4dbc7a9249b
parent 1939 9a6e4956515f
permissions -rw-r--r--
#FEATURE by Stefan Reise class: RegressionTests::WebSocketTest removed: #byteArray500 #data500 #testCommunication100WithMasking #testCommunication100WithoutMasking #testCommunication500 #testCommunicationByteArray500 #testMask500 #testMask500Speed category of: #testCommunication100Speed #testMask100Speed #testParallelSocketWrite class: WebSocketTest changed: #testCommunicationFilename #testParallelSocketWrite

"{ Encoding: utf8 }"

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

"{ NameSpace: RegressionTests }"

TestCase subclass:#CacheDictionaryTest
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'tests-Regression-Collections'
!


!CacheDictionaryTest methodsFor:'testing'!

testAdd
    "(self run: #testAdd)"

    | dict |
    dict := CacheDictionary new:4.
    self assert: (dict isEmpty).

    dict add:(1->'one').
    self assert: (dict size == 1).

    dict add:(2->'two').
    self assert: (dict size == 2).

    dict add:(3->'three').
    self assert: (dict size == 3).

    dict add:(4->'four').
    self assert: (dict size == 4).

    dict add:(5->'five').
    self assert: (dict size == 5).

    dict add:(6->'six').
    self assert: (dict size == 6).

    dict add:(7->'seven').
    self assert: (dict size == 7).

    dict add:(8->'eight').
    self assert: (dict size == 7).

    dict add:(9->'nine').
    self assert: (dict size == 7).
!

testAddRemove
    "(self run: #testAddRemove)"

    | dict notThere wasRemoved toRemove keysBefore keysAfter|

    dict := CacheDictionary new:4.
    self assert: (dict isEmpty).

    1 to:50 do:[:i | dict at:i put:i printString].
    self assert: (dict size == 7).

    self assert:(dict includesKey:17) not.
    
    notThere := false.    
    wasRemoved := (dict removeKey:17 ifAbsent:[ notThere := true. nil ]) notNil.
    self assert:notThere.
    self assert:wasRemoved not.
    self assert:(dict size == 7).

    toRemove := dict keys first.
    self assert:(dict includesKey:toRemove).
    notThere := false.    
    wasRemoved := (dict removeKey:toRemove ifAbsent:[ notThere := true. nil ]) notNil.
    self assert:notThere not.
    self assert:wasRemoved.
    self assert:(dict size == 6).

    keysBefore := dict keys copy.
    self assert:(dict size == keysBefore size).
    dict add:(99->'99').
    keysAfter := dict keys copy.
    self assert:(dict size == keysAfter size).
!

testSizes
    "(self run: #testAddRemove)"

    | dict origCapacity|

    dict := CacheDictionary new:500.
    self assert: (dict isEmpty).
    self assert: ((origCapacity := dict capacity) >= 500).

    1 to:50 do:[:i | dict at:i put:i printString].
    self assert: (dict size == 50).
    self assert: (origCapacity == dict capacity).

    1 to:50 do:[:i | dict removeKey:i ifAbsent:[]].
    self assert: (dict size == 0).
    self assert: (origCapacity == dict capacity).
! !

!CacheDictionaryTest class methodsFor:'documentation'!

version
    ^ '$Header$'
!

version_CVS
    ^ '$Header$'
! !