Andreas Raab uploaded a new version of VersionNumberTests to project The Trunk:
http://source.squeak.org/trunk/VersionNumberTests-it.1.mcz ==================== Summary ==================== Name: VersionNumberTests-it.1 Author: it Time: 15 July 2009, 11:42:33 am UUID: 36dc0b69-b38c-8843-ad3d-2456d65540e3 Ancestors: Introducing VersionNumber unit tests with 10 tests and 23% 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>>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>>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). ].! |
Free forum by Nabble | Edit this page |