Skip to content

Commit

Permalink
final refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
goodefroi committed Aug 4, 2017
1 parent 67bc679 commit 3f8f9b4
Show file tree
Hide file tree
Showing 47 changed files with 74 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ generators
anyOf: anArray
| sample |

sample := anArray atRandom: rng.
sample := anArray atRandom: self rng.
^ (sample isBehavior
ifTrue: [sample]
ifFalse: [sample class]) dataFrom: self.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
initialize-release
initialize

rng := Random new.
self rng: Random new.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
generators
randomBoolean: anUnusedParameter

^ #(true false) atRandom: rng.
^ #(true false) atRandom: self rng.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ generators
randomCharacter: anIterationProgress

^ anIterationProgress < self asciiComplexityThreshhold
ifTrue: [Character value: (rng nextInt: 128)]
ifFalse: [Character value: (rng nextInt: 65536)].
ifTrue: [Character value: (self rng nextInt: 128)]
ifFalse: [Character value: (self rng nextInt: 65536)].
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ randomInteger: anIterationProgress
| complexity |

complexity := self exponentialComplexity: anIterationProgress.
^ (rng nextInt: complexity * 2) - complexity.
^ (self rng nextInt: complexity * 2) - complexity.
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ randomObject: anIterationProgress
| selector |

selector := ((self class allSelectors select: [:name | name beginsWith: 'random'])
reject: [:name | name == #randomObject:]) atRandom: rng.
reject: [:name | name == #randomObject:]) atRandom: self rng.
^ self perform: selector withArguments: {anIterationProgress}.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ generators
randomSequenceableCollection: anIterationProgress
| class result aModerateComplexity |

class := {Array. OrderedCollection} atRandom: rng.
class := {Array. OrderedCollection} atRandom: self rng.
aModerateComplexity := self moderateComplexity: anIterationProgress.
self assert: anIterationProgress <= 1.

result := (1 to: (rng nextInt: aModerateComplexity))
result := (1 to: (self rng nextInt: aModerateComplexity))
inject: class new
into: [:arr :unusedInt | arr , {self randomObject: anIterationProgress / 2}].
^ result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ generators
randomString: anIterationProgress
| stream stringLength |

stringLength := rng nextInt: (self moderateComplexity: anIterationProgress).
stringLength := self rng nextInt: (self moderateComplexity: anIterationProgress).
stream := WriteStream on: (WideString new: stringLength).
stringLength timesRepeat: [stream nextPut: (self randomCharacter: anIterationProgress)].
^ stream contents.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
rng: anObject

rng := anObject.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
rng

^ rng
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
"class" : {
},
"instance" : {
"anyOf:" : "gdf 8/4/2017 14:09",
"anyOf:" : "gdf 8/4/2017 18:16",
"asciiComplexityThreshhold" : "TZ 7/11/2017 16:19",
"dataCollectionOf:" : "gdf 8/4/2017 14:12",
"exponentialComplexity:" : "gdf 8/4/2017 14:13",
"initialize" : "gdf 8/4/2017 14:14",
"initialize" : "gdf 8/4/2017 18:02",
"moderateComplexity:" : "gdf 8/4/2017 14:14",
"numberOfResults" : "TZ 6/28/2017 19:56",
"randomBoolean:" : "gdf 8/4/2017 14:15",
"randomCharacter:" : "gdf 8/4/2017 14:15",
"randomInteger:" : "gdf 8/4/2017 14:16",
"randomObject:" : "gdf 8/4/2017 14:18",
"randomBoolean:" : "gdf 8/4/2017 18:02",
"randomCharacter:" : "gdf 8/4/2017 18:14",
"randomInteger:" : "gdf 8/4/2017 18:02",
"randomObject:" : "gdf 8/4/2017 18:02",
"randomPositiveInteger:" : "gdf 8/4/2017 14:18",
"randomSequenceableCollection:" : "gdf 8/4/2017 14:20",
"randomString:" : "gdf 8/4/2017 14:21" } }
"randomSequenceableCollection:" : "gdf 8/4/2017 18:02",
"randomString:" : "gdf 8/4/2017 18:02",
"rng" : "gdf 8/4/2017 18:01",
"rng:" : "gdf 8/4/2017 18:01" } }
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"commentStamp" : "",
"instvars" : [
"browser" ],
"name" : "BrowserExtensionTests",
"name" : "SqueakCheckBrowserExtensionTests",
"pools" : [
],
"super" : "TestCase",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"printTo:generator:" : "fbs 9/9/2011 17:50" },
"instance" : {
"generator:" : "fbs 9/9/2011 17:49",
"initialize" : "fbs 9/9/2011 21:11",
"print:" : "fbs 9/9/2011 17:28",
"printFailure:withCounterexample:" : "fbs 9/10/2011 16:25",
"printSuccessfulTest" : "fbs 9/9/2011 09:36",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
"commentStamp" : "fbs 9/9/2011 08:07",
"instvars" : [
"output",
"generator",
"testRunSize" ],
"generator" ],
"name" : "TheoryTestRunner",
"pools" : [
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
currentExample: anObject

currentExample := anObject.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ generateIfNecessaryTestCase: aTheorySelector withCounterexample: anObject
(self class >> aTheorySelector pragmaAt: #generateCounterexamples) ifNil: [^ self].
self class
compile: (self contentOfTestCase: aTheorySelector withCounterexample: anObject)
classified: 'counterexamples'
notifying: nil.
classified: 'counterexamples'.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
generator

^ generator
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
initialize-release
initialize

currentExample := NotAssigned.
self generator: self generatorClass new.
self
currentExample: NotAssigned;
generator: self generatorClass new.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
private
performTest: anObject

^ self perform: testSelector asSymbol withArguments: anObject.
^ self perform: self selector asSymbol withArguments: anObject.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ private
performTest

^ self runningATheory
ifTrue: [self performTest: currentExample]
ifTrue: [self performTest: self currentExample]
ifFalse: [super performTest].
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ runCase
"If counterExample is NotAssigned, then we're running the test for the first time. Otherwise, it contains the value of a counterexample to our theory. Run the test using this value."

self runningATheory ifFalse: [^ super runCase].
currentExample = NotAssigned
ifTrue: [ self runCaseOn: (self makeTestData: (self class >> testSelector) with: TrivialDataGenerator new).
self runCaseOn: (self makeTestData: (self class >> testSelector) with: generator)]
self currentExample = NotAssigned
ifTrue: [ self runCaseOn: (self makeTestData: (self class >> self selector) with: TrivialDataGenerator new).
self runCaseOn: (self makeTestData: (self class >> self selector) with: self generator)]
ifFalse: [super runCase].
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ running
runCaseOn: data

data do: [:each |
currentExample := each.
self currentExample: each.
[super runCase] on: TestFailure do: [:exception |
(self expectedFailures includes: testSelector)
ifFalse: [self generateIfNecessaryTestCase: testSelector withCounterexample: currentExample].
(self expectedFailures includes: self selector)
ifFalse: [self generateIfNecessaryTestCase: self selector withCounterexample: self currentExample].
exception signal]].
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
testing
runningATheory

^ testSelector numArgs >= 1.
^ self selector numArgs >= 1.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
accessing
signalFailure: aString

TestResult failure signal: aString, ' with: ', currentExample asString.
TestResult failure signal: aString, ' with: ', self currentExample asString.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ typeTheory: aCompiledMethod
"If the theory uses the <theory> pragma, treat that as <theoryTaking: #Object>. Otherwise, the symbol given in the pragma gives the name of the class used to determine which generator to use."

pragma := aCompiledMethod pragmaAt: #theoryTaking:.
pragma ifNil: [^((1 to: testSelector numArgs) collect: [:unused |
pragma ifNil: [^((1 to: self selector numArgs) collect: [:unused |
self acceptableTypesFor: aCompiledMethod])].

prototypeClassNames := pragma arguments first.
Expand All @@ -16,9 +16,9 @@ typeTheory: aCompiledMethod
self class environment at: each ifAbsent: [MissingPrototypeException signal: each]].

prototypeClasses size = 1 ifTrue: [
prototypeClasses := (1 to: testSelector numArgs) collect: [:unused | prototypeClasses first]].
prototypeClasses := (1 to: self selector numArgs) collect: [:unused | prototypeClasses first]].

testSelector numArgs ~= prototypeClasses size ifTrue: [
MissingPrototypeException signal: ('expected 1 or ',testSelector numArgs,' arguments for #theoryTaking:, but received ',prototypeClassNames size)].
self selector numArgs ~= prototypeClasses size ifTrue: [
MissingPrototypeException signal: ('expected 1 or ', self selector numArgs,' arguments for #theoryTaking:, but received ',prototypeClassNames size)].

^ prototypeClasses
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
"acceptableTypesFor:" : "gdf 7/7/2017 22:18",
"contentOfTestCase:withCounterexample:" : "gdf 8/4/2017 15:11",
"currentExample" : "gdf 8/4/2017 15:08",
"currentExample:" : "gdf 8/4/2017 18:16",
"filterAcceptableTypesFrom:default:" : "fbs 1/30/2012 12:46",
"forbiddenTypes" : "fbs 1/29/2012 17:30",
"generateIfNecessaryTestCase:withCounterexample:" : "gdf 8/4/2017 16:17",
"generateIfNecessaryTestCase:withCounterexample:" : "gdf 8/4/2017 18:22",
"generator" : "gdf 8/4/2017 18:16",
"generator:" : "fbs 9/11/2011 21:27",
"generatorClass" : "fbs 9/11/2011 17:56",
"initialize" : "gdf 8/2/2017 11:19",
"initialize" : "gdf 8/4/2017 18:17",
"makeTestData:with:" : "gdf 8/4/2017 15:12",
"nameOfTestCase:withCounterexample:" : "gdf 8/4/2017 15:13",
"performTest" : "gdf 8/2/2017 12:00",
"performTest:" : "gdf 8/2/2017 12:00",
"performTest" : "gdf 8/4/2017 18:17",
"performTest:" : "gdf 8/4/2017 18:18",
"printString" : "gdf 8/4/2017 15:14",
"runCase" : "gdf 8/2/2017 12:04",
"runCase" : "gdf 8/4/2017 18:19",
"runCase:" : "gdf 8/2/2017 12:04",
"runCaseOn:" : "gdf 8/4/2017 15:15",
"runningATheory" : "gdf 8/2/2017 12:05",
"signalFailure:" : "gdf 8/2/2017 12:05",
"typeTheory:" : "gdf 8/2/2017 12:34" } }
"runCaseOn:" : "gdf 8/4/2017 18:19",
"runningATheory" : "gdf 8/4/2017 18:19",
"signalFailure:" : "gdf 8/4/2017 18:20",
"typeTheory:" : "gdf 8/4/2017 18:20" } }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
as yet unclassified
abstract
isAbstract

^ self name = 'TheoryTestData'.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
generateLeaf: anInteger

^ anInteger > 0
ifTrue: [Leaf value: (rng nextInt: 100)]
ifTrue: [Leaf value: (self rng nextInt: 100)]
ifFalse: [Tree empty].
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*SqueakCheckForAlgebraicDataType
randomTree: anIterationProgress
"Generate a random tree with 0 <= size <= self moderateComplexity."

^ self generateNode: (rng nextInt: (self moderateComplexity: anIterationProgress / 2) + 1) - 1.
^ self generateNode: (self rng nextInt: (self moderateComplexity: anIterationProgress / 2) + 1) - 1.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*SqueakCheckForAlgebraicDataType
treeDataOfMaxSize: anInteger
"Thunking means never having to generate more than you have to."

^ ({[self generateLeaf: anInteger]. [self generateNode: anInteger]} atRandom: rng) value.
^ ({[self generateLeaf: anInteger]. [self generateNode: anInteger]} atRandom: self rng) value.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"class" : {
},
"instance" : {
"generateLeaf:" : "gdf 8/4/2017 14:13",
"generateLeaf:" : "gdf 8/4/2017 18:14",
"generateNode:" : "gdf 8/4/2017 14:14",
"randomTree:" : "gdf 8/4/2017 14:21",
"treeDataOfMaxSize:" : "gdf 8/4/2017 14:23" } }
"randomTree:" : "gdf 8/4/2017 18:10",
"treeDataOfMaxSize:" : "gdf 8/4/2017 18:11" } }

0 comments on commit 3f8f9b4

Please sign in to comment.