[squeak-dev] The Inbox: VersionNumberTests-it.2.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] The Inbox: VersionNumberTests-it.2.mcz

commits-2
A new version of VersionNumberTests was added to project The Inbox:
http://source.squeak.org/inbox/VersionNumberTests-it.2.mcz

==================== Summary ====================

Name: VersionNumberTests-it.2
Author: it
Time: 17 July 2009, 10:23:16 am
UUID: e4d19f1e-407f-0944-9778-f9f5e92f4dca
Ancestors: VersionNumberTests-it.1

Added tests for methods VersionNumber>>=, VersionNumber>>initializeNumbers and String>>asVersion.

29% Code Coverage.

==================== Snapshot ====================

SystemOrganization addCategory: #VersionNumberTests!

ClassTestCase subclass: #VersionNumberTest
        instanceVariableNames: ''
        classVariableNames: ''
        poolDictionaries: ''
        category: 'VersionNumberTests'!

!VersionNumberTest commentStamp: 'it 7/15/2009 23:32' prior: 0!
This is the unit tests for the class VersionNumber.

VersionNumber has no specification beyond its implementation. There are few important elements to be noted:

        * Does NOT support 0 in versioning, i.e. 0, 1.0, 5.0.843, etc.
        * Does support empty version from a string, e.g. '', or a collection, e.g. #().
        * VersionNumber>>fromString will ignore trailing numbers if not sperated by a dot.
        * VersionNumber>>next advances the minor number (last value), without turn over.
        * VersionNumber>>branchNext creates a sub-minor version number, e.g. 1.5 becomes 1.5.1.
        * VersionNumber>>previous reduces may truncate the number, e.g. 9.1 -> 9, 1 to empty.
        * An annoying character improperly displayed as "" should be removed from source code.!

----- Method: VersionNumberTest>>classToBeTested (in category 'Coverage') -----
classToBeTested

        ^ VersionNumber!

----- Method: VersionNumberTest>>selectorsToBeIgnored (in category 'Coverage') -----
selectorsToBeIgnored
        ^ super selectorsToBeIgnored.!

----- Method: VersionNumberTest>>setUp (in category 'Running') -----
setUp
        super setUp.!

----- Method: VersionNumberTest>>tearDown (in category 'Running') -----
tearDown
        super tearDown.!

----- Method: VersionNumberTest>>testAsVersion (in category 'Tests') -----
testAsVersion
        "note: a version number string '3 2 1' will only consider the first number as a version, ignoring the trailing '2 1'. Whether it is a desired feature or not should be determined."
       
        | numbers version |
        numbers := {
                '' -> #(). '1 '-> #(1). '1.2' -> #(1 2). '3.4.5' -> #(3 4 5).
                '6.7.890' -> #(6 7 890). '9 8' -> #(9). '98 7 6' -> #(98). '54.3 2 1' -> #(54 3)
        }.
       
        numbers do: [:item |
                version := (item key) asVersion.
       
                self assert: (VersionNumber = version class).
                self assert: ((item value) = version numbers).
        ].

        self shouldnt: ['9999999999999999999' asVersion] raise: TestResult error.
       
        self should: ['-1' asVersion] raise: TestResult error.
        self should: [' 1' asVersion] raise: TestResult error. "notice leading space!!"
        self should: ['version' asVersion] raise: TestResult error.
        self should: ['1.2.10.20.-1.4' asVersion] raise: TestResult error.
        self should: ['1.2.10.20.R4' asVersion] raise: TestResult error.
        !

----- Method: VersionNumberTest>>testBranchNext (in category 'Tests') -----
testBranchNext
        | numbers version temp |
        numbers := #(#(1) #(9) #(1 2) #(1 9) #(1 9 1) #(1 9 9) #(1 1 1 1 1 99)).
       
        numbers do: [:item |
                version := VersionNumber fromCollection: item.
               
                temp := item asOrderedCollection.
                temp add: 1.

                self assert: (temp asArray = version branchNext numbers).
        ].!

----- Method: VersionNumberTest>>testFirst (in category 'Tests') -----
testFirst
        | version |
        version := VersionNumber first.
        self assert: (VersionNumber = version class).
        self assert: (#(1) = version numbers).!

----- Method: VersionNumberTest>>testFromCollection (in category 'Tests') -----
testFromCollection
        | numbers version |
        numbers := #(#(1) #(1 2) #(3 4 5) #(6 7 890)).
       
        numbers do: [:item |
                version := VersionNumber fromCollection: item.
       
                self assert: (VersionNumber = version class).
                self assert: (item = version numbers).
        ].

        self shouldnt: [VersionNumber fromCollection: #()] raise: TestResult error.
        self shouldnt: [VersionNumber fromCollection: #(9999999999999999999)] raise: TestResult error.
       
        self should: [VersionNumber fromCollection: #(0)] raise: TestResult error.
        self should: [VersionNumber fromCollection: #(-1)] raise: TestResult error.
        self should: [VersionNumber fromCollection: #(1 2 10 20 -1 4)] raise: TestResult error.
        self should: [VersionNumber fromCollection: #(1 2 10 20 '1' 4)] raise: TestResult error.
        self should: [VersionNumber fromCollection: #('version')] raise: TestResult error.
        !

----- Method: VersionNumberTest>>testFromString (in category 'Tests') -----
testFromString
        "note: a version number string '3 2 1' will only consider the first number as a version, ignoring the trailing '2 1'. Whether it is a desired feature or not should be determined."
       
        | numbers version |
        numbers := {
                '' -> #(). '1 '-> #(1). '1.2' -> #(1 2). '3.4.5' -> #(3 4 5).
                '6.7.890' -> #(6 7 890). '9 8' -> #(9). '98 7 6' -> #(98). '54.3 2 1' -> #(54 3)
        }.
       
        numbers do: [:item |
                version := VersionNumber fromString: (item key).
       
                self assert: (VersionNumber = version class).
                self assert: ((item value) = version numbers).
        ].

        self shouldnt: [VersionNumber fromString: '9999999999999999999'] raise: TestResult error.
       
        self should: [VersionNumber fromString: '-1'] raise: TestResult error.
        self should: [VersionNumber fromString: ' 1'] raise: TestResult error. "notice leading space!!"
        self should: [VersionNumber fromString: 'version'] raise: TestResult error.
        self should: [VersionNumber fromString: '1.2.10.20.-1.4'] raise: TestResult error.
        self should: [VersionNumber fromString: '1.2.10.20.R4'] raise: TestResult error.
        !

----- Method: VersionNumberTest>>testInitializeNumbers (in category 'Tests') -----
testInitializeNumbers
        | numbers version |
        numbers := #(#(1) #(1 2) #(3 4 5) #(6 7 890)).
       
        numbers do: [:item |
                version := VersionNumber new initializeNumbers: item.
       
                self assert: (VersionNumber = version class).
                self assert: (item = version numbers).
        ].

        self shouldnt: [VersionNumber new initializeNumbers: #()] raise: TestResult error.
        self shouldnt: [VersionNumber new initializeNumbers: #(9999999999999999999)] raise: TestResult error.
       
        self should: [VersionNumber new initializeNumbers: #(0)] raise: TestResult error.
        self should: [VersionNumber new initializeNumbers: #(-1)] raise: TestResult error.
        self should: [VersionNumber new initializeNumbers: #(1 2 10 20 -1 4)] raise: TestResult error.
        self should: [VersionNumber new initializeNumbers: #(1 2 10 20 '1' 4)] raise: TestResult error.
        self should: [VersionNumber new initializeNumbers: #('version')] raise: TestResult error.
        !

----- Method: VersionNumberTest>>testIsEqual (in category 'Tests') -----
testIsEqual
        "Test VersionNumber>>="
       
        | version |
        version := VersionNumber first.
        self assert: (VersionNumber new initializeNumbers: #(1)) = version.
        self assert: (VersionNumber new initializeNumbers: #(2)) = (version next).
        self assert: (VersionNumber new initializeNumbers: #(1 1)) = (version branchNext).!

----- Method: VersionNumberTest>>testNext (in category 'Tests') -----
testNext
        | numbers version temp |
        numbers := #(#(1) #(9) #(1 2) #(1 9) #(1 9 1) #(1 9 9) #(1 1 1 1 1 99)).
       
        numbers do: [:item |
                version := VersionNumber fromCollection: item.
               
                temp := item copy.
                temp atLast: 1 put: (temp last + 1).

                self assert: (temp = version next numbers).
        ].!

----- Method: VersionNumberTest>>testPrevious (in category 'Tests') -----
testPrevious
        | numbers version |
        numbers := {
                #(1) -> #(). #(2) -> #(1). #(9) -> #(8).
                #(7 9) -> #(7 8). #(7 1) -> #(7). #(9 9 9 9 1) -> #(9 9 9 9).
        }.
       
        numbers do: [:item |
                version := VersionNumber fromCollection: (item key).
               
                self assert: ((item value) = version previous numbers).
        ].!