diff --git a/src/Math-Random/PMBinomialGenerator.class.st b/src/Math-Random/PMBinomialGenerator.class.st index 44d4ce551..fa3537ed3 100644 --- a/src/Math-Random/PMBinomialGenerator.class.st +++ b/src/Math-Random/PMBinomialGenerator.class.st @@ -21,6 +21,11 @@ PMBinomialGenerator class >> numberOfTrials: numberOfTrials probabilityOfSuccess yourself ] +{ #category : #accessing } +PMBinomialGenerator >> expectedValue [ + ^ numberOfTrials * probability . +] + { #category : #initialization } PMBinomialGenerator >> initialize [ self generator: PMParkMillerMinimumRandomGenerator new. diff --git a/src/Math-Random/PMLehmerRandomGenerator.class.st b/src/Math-Random/PMLehmerRandomGenerator.class.st index 3659ff66c..3dc1ba7a6 100644 --- a/src/Math-Random/PMLehmerRandomGenerator.class.st +++ b/src/Math-Random/PMLehmerRandomGenerator.class.st @@ -5,7 +5,7 @@ PMLehmerRandomGenerator new next " Class { #name : #PMLehmerRandomGenerator, - #superclass : #PMRandomGenerator, + #superclass : #PMPseudoRandomNumberGenerator, #category : #'Math-Random' } diff --git a/src/Math-Random/PMLinearCongruentialRandomGenerator.class.st b/src/Math-Random/PMLinearCongruentialRandomGenerator.class.st index c8b99c60a..543ad6704 100644 --- a/src/Math-Random/PMLinearCongruentialRandomGenerator.class.st +++ b/src/Math-Random/PMLinearCongruentialRandomGenerator.class.st @@ -5,7 +5,7 @@ PMLinearCongruentialRandomGenerator new next. " Class { #name : #PMLinearCongruentialRandomGenerator, - #superclass : #PMRandomGenerator, + #superclass : #PMPseudoRandomNumberGenerator, #category : #'Math-Random' } diff --git a/src/Math-Random/PMMarsagliaKissRandom.class.st b/src/Math-Random/PMMarsagliaKissRandomGenerator.class.st similarity index 79% rename from src/Math-Random/PMMarsagliaKissRandom.class.st rename to src/Math-Random/PMMarsagliaKissRandomGenerator.class.st index cfa6fd571..1660910c9 100644 --- a/src/Math-Random/PMMarsagliaKissRandom.class.st +++ b/src/Math-Random/PMMarsagliaKissRandomGenerator.class.st @@ -10,8 +10,8 @@ Instance Variables " Class { - #name : #PMMarsagliaKissRandom, - #superclass : #PMRandomGenerator, + #name : #PMMarsagliaKissRandomGenerator, + #superclass : #PMPseudoRandomNumberGenerator, #instVars : [ 'kernelRand1', 'kernelRand2' @@ -20,20 +20,20 @@ Class { } { #category : #'instance creation' } -PMMarsagliaKissRandom class >> default [ +PMMarsagliaKissRandomGenerator class >> default [ ^self seed: #( 123456789 362436069 521288629 316191069 987654321 458629013 582859209 438195021) ] { #category : #'instance creation' } -PMMarsagliaKissRandom class >> new [ +PMMarsagliaKissRandomGenerator class >> new [ ^ self seed: (PMMarsagliaKissRandomKernel new next: 8) ] { #category : #'stream access' } -PMMarsagliaKissRandom >> next [ +PMMarsagliaKissRandomGenerator >> next [ "Answer a Float in interval [0.0,1.0) with uniform distribution. Note that constant 16rFFFFF800 is computed so as to truncate the 64 bits to Float precision. It is thus ((1 << 32 - 1 << (64 - Float precision) bitAnd: 1 << 32 - 1)) hex" @@ -42,23 +42,23 @@ PMMarsagliaKissRandom >> next [ ] { #category : #'stream access' } -PMMarsagliaKissRandom >> peek [ +PMMarsagliaKissRandomGenerator >> peek [ ^self copy next ] { #category : #copying } -PMMarsagliaKissRandom >> postCopy [ +PMMarsagliaKissRandomGenerator >> postCopy [ kernelRand1 := kernelRand1 copy. kernelRand2 := kernelRand2 copy ] { #category : #accessing } -PMMarsagliaKissRandom >> seed [ +PMMarsagliaKissRandomGenerator >> seed [ ^ kernelRand1 seed , kernelRand2 seed ] { #category : #accessing } -PMMarsagliaKissRandom >> seed: aWordArray [ +PMMarsagliaKissRandomGenerator >> seed: aWordArray [ "Initialize with an Array of eight 32-bits Integer" kernelRand1 := PMMarsagliaKissRandomKernel seed: (aWordArray first: 4). kernelRand2 := PMMarsagliaKissRandomKernel seed: (aWordArray last: 4) diff --git a/src/Math-Random/PMMersenneTwisterRandomGenerator.class.st b/src/Math-Random/PMMersenneTwisterRandomGenerator.class.st index 616aa72fb..dd16ed7f7 100644 --- a/src/Math-Random/PMMersenneTwisterRandomGenerator.class.st +++ b/src/Math-Random/PMMersenneTwisterRandomGenerator.class.st @@ -11,7 +11,7 @@ MersenneTwisterRandom new nextInteger. " Class { #name : #PMMersenneTwisterRandomGenerator, - #superclass : #PMRandomGenerator, + #superclass : #PMPseudoRandomNumberGenerator, #instVars : [ 'states', 'mti' @@ -26,7 +26,7 @@ Class { 'TemperingMaskB', 'TemperingMaskC' ], - #category : 'Math-Random' + #category : #'Math-Random' } { #category : #'class initialization' } diff --git a/src/Math-Random/PMParkMillerMinimumRandomGenerator.class.st b/src/Math-Random/PMParkMillerMinimumRandomGenerator.class.st index b67d468d9..53c0653c0 100644 --- a/src/Math-Random/PMParkMillerMinimumRandomGenerator.class.st +++ b/src/Math-Random/PMParkMillerMinimumRandomGenerator.class.st @@ -5,7 +5,7 @@ PMParkMillerMinimumRandomGenerator new next " Class { #name : #PMParkMillerMinimumRandomGenerator, - #superclass : #PMRandomGenerator, + #superclass : #PMPseudoRandomNumberGenerator, #category : #'Math-Random' } diff --git a/src/Math-Random/PMRandomGenerator.class.st b/src/Math-Random/PMPseudoRandomNumberGenerator.class.st similarity index 84% rename from src/Math-Random/PMRandomGenerator.class.st rename to src/Math-Random/PMPseudoRandomNumberGenerator.class.st index 68c775b64..c6e1c03d2 100644 --- a/src/Math-Random/PMRandomGenerator.class.st +++ b/src/Math-Random/PMPseudoRandomNumberGenerator.class.st @@ -31,16 +31,16 @@ And finally, there's a taxonomy more related with the internal implementation, b " Class { - #name : #PMRandomGenerator, + #name : #PMPseudoRandomNumberGenerator, #superclass : #Object, #instVars : [ 'seed' ], - #category : 'Math-Random' + #category : #'Math-Random' } { #category : #testing } -PMRandomGenerator class >> chiSquare: range repeating: anInteger [ +PMPseudoRandomNumberGenerator class >> chiSquare: range repeating: anInteger [ "Run a 'chi-square' test on a random number generator, over a range of integers given by range, repeating anInteger times. Answer an Array containing the result of the chi-square test (which should be the same as the range), and the upper and lower bounds for 'good' randomness (assuming that anInteger is at least 10 * range)." @@ -64,21 +64,21 @@ PMRandomGenerator class >> chiSquare: range repeating: anInteger [ ] { #category : #'instance creation' } -PMRandomGenerator class >> new [ +PMPseudoRandomNumberGenerator class >> new [ "Answer a new instance of the receiver" ^ (self seed: Time millisecondClockValue) initialize ] { #category : #'instance creation' } -PMRandomGenerator class >> seed: anInteger [ +PMPseudoRandomNumberGenerator class >> seed: anInteger [ "Anwer a new Random stream with the initial seed anInteger." ^ self basicNew seed: anInteger; yourself ] { #category : #testing } -PMRandomGenerator >> atEnd [ +PMPseudoRandomNumberGenerator >> atEnd [ "Answer whether the receiver is at its end - never true for a stream of Random numbers" ^ false @@ -86,7 +86,7 @@ PMRandomGenerator >> atEnd [ ] { #category : #accessing } -PMRandomGenerator >> contents [ +PMPseudoRandomNumberGenerator >> contents [ "Answer all of the objects in the collection accessed by the receiver. Implementation Notes: Random streams are infinite, so there is no implementation possible." @@ -95,7 +95,7 @@ PMRandomGenerator >> contents [ ] { #category : #testing } -PMRandomGenerator >> isReadable [ +PMPseudoRandomNumberGenerator >> isReadable [ "Answer whether the receiver can be read from (i.e. it implements the gettableStream protocol)." ^ true @@ -103,7 +103,7 @@ PMRandomGenerator >> isReadable [ ] { #category : #testing } -PMRandomGenerator >> isWriteable [ +PMPseudoRandomNumberGenerator >> isWriteable [ "Answer whether the receiver can be written to (i.e. it implements the puttableStream protocol)." ^ false @@ -111,14 +111,14 @@ PMRandomGenerator >> isWriteable [ ] { #category : #'stream access' } -PMRandomGenerator >> next [ +PMPseudoRandomNumberGenerator >> next [ "Answer a pseudo-Random number" ^ self subclassResponsibility ] { #category : #'stream access' } -PMRandomGenerator >> next: anInteger [ +PMPseudoRandomNumberGenerator >> next: anInteger [ "Answer a collection of size anInteger of pseudo-random Floats between 0 and 1. " ^ ( 1 to: anInteger ) collect: [ :i | self next ] @@ -126,21 +126,21 @@ PMRandomGenerator >> next: anInteger [ ] { #category : #'stream access' } -PMRandomGenerator >> peek [ +PMPseudoRandomNumberGenerator >> peek [ "Answer a pseudo-Random number generated from the next seed, but do not advance down the stream (i.e. self peek = self peek). " ^ self subclassResponsibility ] { #category : #accessing } -PMRandomGenerator >> seed [ +PMPseudoRandomNumberGenerator >> seed [ "Returns the instance var of the receiver for external manipulation" ^ seed ] { #category : #accessing } -PMRandomGenerator >> seed: anObject [ +PMPseudoRandomNumberGenerator >> seed: anObject [ "Sets the instance var of the receiver with anObject. (No checking is done)" seed := anObject diff --git a/src/Math-Tests-Random/PMBernoulliGeneratorTest.class.st b/src/Math-Tests-Random/PMBernoulliGeneratorTest.class.st index 2ff085cdb..ec209a95a 100644 --- a/src/Math-Tests-Random/PMBernoulliGeneratorTest.class.st +++ b/src/Math-Tests-Random/PMBernoulliGeneratorTest.class.st @@ -7,17 +7,6 @@ Class { #category : #'Math-Tests-Random' } -{ #category : #tests } -PMBernoulliGeneratorTest >> testGenerator [ - | g bern | - g := PMLinearCongruentialRandomGenerator new. - bern := PMBernoulliGenerator new. - self - assert: (bern generator isKindOf: PMBernoulliGenerator defaultGeneratorClass). - bern generator: g. - self assert: (bern generator isKindOf: PMLinearCongruentialRandomGenerator) -] - { #category : #tests } PMBernoulliGeneratorTest >> testNextYieldsOneOrZero [ | gen | diff --git a/src/Math-Tests-Random/PMBinomialGeneratorTest.class.st b/src/Math-Tests-Random/PMBinomialGeneratorTest.class.st index 42196e9af..0b5adaf46 100644 --- a/src/Math-Tests-Random/PMBinomialGeneratorTest.class.st +++ b/src/Math-Tests-Random/PMBinomialGeneratorTest.class.st @@ -4,27 +4,6 @@ Class { #category : #'Math-Tests-Random' } -{ #category : #tests } -PMBinomialGeneratorTest >> testBinomialGeneratorConvergesToMean [ - "Its purpose is to verify correct convergence of the binomial distribution, - should be Normal (np, np(1-p))" - - | gen nums mean probabilityOfSuccess numberOfTrials | - probabilityOfSuccess := (Random seed: 0.0) next sqrt. - numberOfTrials := 1000. - gen := PMBinomialGenerator - numberOfTrials: numberOfTrials - probabilityOfSuccess: probabilityOfSuccess. - - nums := OrderedCollection new. - (1 to: numberOfTrials) do: [ :ea | nums add: gen next ]. - - mean := numberOfTrials * probabilityOfSuccess. - self assert: nums min > (mean * (1 - 0.2)). - self assert: nums max < (mean * (1 + 0.2)). - self assert: (nums average - mean) abs < 5 -] - { #category : #tests } PMBinomialGeneratorTest >> testBinomialGeneratorWithSuccessProbabilityOfOneAlwaysReturnNumberOfTrials [ | g numberOfTrials | @@ -56,3 +35,23 @@ PMBinomialGeneratorTest >> testBinomialGeneratorWithSuccessProbabilityOfZeroAlwa g generator: PMMersenneTwisterRandomGenerator new. self assert: g next equals: 0 ] + +{ #category : #tests } +PMBinomialGeneratorTest >> testSampleMeanConvergesToExpectedValue [ + "Its purpose is to verify correct convergence of the binomial distribution, + should be Normal (np, np(1-p))" + + | gen sample probabilityOfSuccess numberOfTrials | + probabilityOfSuccess := (Random seed: 0.0) next sqrt. + numberOfTrials := 1000. + gen := PMBinomialGenerator + numberOfTrials: numberOfTrials + probabilityOfSuccess: probabilityOfSuccess. + + sample := OrderedCollection new. + numberOfTrials timesRepeat: [ sample add: gen next ]. + + self assert: sample min > (gen expectedValue * (1 - 0.2)). + self assert: sample max < (gen expectedValue * (1 + 0.2)). + self assert: (sample average - gen expectedValue) abs < 5 +] diff --git a/src/Math-Tests-Random/PMExponentialGeneratorTest.class.st b/src/Math-Tests-Random/PMExponentialGeneratorTest.class.st index a951ef334..c18e39354 100644 --- a/src/Math-Tests-Random/PMExponentialGeneratorTest.class.st +++ b/src/Math-Tests-Random/PMExponentialGeneratorTest.class.st @@ -13,14 +13,14 @@ PMExponentialGeneratorTest >> testGenerator [ eg := PMExponentialGenerator new. self assert: (eg generator isKindOf: PMExponentialGenerator defaultGeneratorClass). - self assert: (eg generator isKindOf: PMRandomGenerator). + self assert: (eg generator isKindOf: PMPseudoRandomNumberGenerator). eg generator: PMMersenneTwisterRandomGenerator new. self assert: (eg generator isKindOf: PMMersenneTwisterRandomGenerator). self assert: (eg next isKindOf: Number) ] { #category : #tests } -PMExponentialGeneratorTest >> testPeekAlwaysAnswersTheSame [ +PMExponentialGeneratorTest >> testPeekIsIdempotent [ | eg | eg := PMExponentialGenerator new. self assert: eg peek equals: eg peek. @@ -31,10 +31,11 @@ PMExponentialGeneratorTest >> testPeekAlwaysAnswersTheSame [ PMExponentialGeneratorTest >> testSampleMeanConvergesToDistributionMean [ "testing a random sample seems suspect. We use a 5% interval here" - | eg arr | - eg := PMExponentialGenerator mean: 10. - arr := Array new: 10000. - arr := arr collect: [ :each | eg next ]. + | gen sample | + gen := PMExponentialGenerator mean: 10. + sample := Array new: 10000. + sample := sample collect: [ :each | gen next ]. + self - assert: (arr average between: eg mean * 0.95 and: eg mean * 1.05) + assert: (sample average between: gen mean * 0.95 and: gen mean * 1.05) ] diff --git a/src/Math-Tests-Random/PMLaplaceGeneratorTest.class.st b/src/Math-Tests-Random/PMLaplaceGeneratorTest.class.st index 1b1cb51d8..2573b654e 100644 --- a/src/Math-Tests-Random/PMLaplaceGeneratorTest.class.st +++ b/src/Math-Tests-Random/PMLaplaceGeneratorTest.class.st @@ -4,14 +4,9 @@ Class { #category : #'Math-Tests-Random' } -{ #category : #'as yet unclassified' } -PMLaplaceGeneratorTest >> classToTest [ - ^ PMLaplaceGenerator -] - -{ #category : #accessing } -PMLaplaceGeneratorTest >> testPeekAlwaysReplyTheSameValue [ +{ #category : #tests } +PMLaplaceGeneratorTest >> testPeekIsIdempotent [ | g | - g := self classToTest shape: 0.5 scale: 0.3. + g := PMLaplaceGenerator shape: 0.5 scale: 0.3. self assert: g peek equals: g peek ] diff --git a/src/Math-Tests-Random/PMLehmerRandomTest.class.st b/src/Math-Tests-Random/PMLehmerRandomTest.class.st index 21f3ce4a4..55740df49 100644 --- a/src/Math-Tests-Random/PMLehmerRandomTest.class.st +++ b/src/Math-Tests-Random/PMLehmerRandomTest.class.st @@ -14,15 +14,15 @@ PMLehmerRandomTest >> testNextBetweenZeroAndOne [ ] { #category : #tests } -PMLehmerRandomTest >> testPeekAlwaysReplyTheSameValue [ +PMLehmerRandomTest >> testPeekAnswersSameAsNext [ | g | g := PMLehmerRandomGenerator new. - self assert: g peek equals: g peek + self assert: g peek equals: g next ] { #category : #tests } -PMLehmerRandomTest >> testPeekAnswersSameAsNext [ +PMLehmerRandomTest >> testPeekIsIdempotent [ | g | g := PMLehmerRandomGenerator new. - self assert: g peek equals: g next + self assert: g peek equals: g peek ] diff --git a/src/Math-Tests-Random/PMLinearCongruentialRandomTest.class.st b/src/Math-Tests-Random/PMLinearCongruentialRandomTest.class.st index d1dafadb4..08ae003cb 100644 --- a/src/Math-Tests-Random/PMLinearCongruentialRandomTest.class.st +++ b/src/Math-Tests-Random/PMLinearCongruentialRandomTest.class.st @@ -14,15 +14,15 @@ PMLinearCongruentialRandomTest >> testNextBetweenZeroAndOne [ ] { #category : #tests } -PMLinearCongruentialRandomTest >> testPeekAlwaysReplyTheSameValue [ +PMLinearCongruentialRandomTest >> testPeekAnswersSameAsNext [ | g | g := PMLinearCongruentialRandomGenerator new. - self assert: g peek equals: g peek + self assert: g peek equals: g next ] { #category : #tests } -PMLinearCongruentialRandomTest >> testPeekAnswersSameAsNext [ +PMLinearCongruentialRandomTest >> testPeekIsIdempotent [ | g | g := PMLinearCongruentialRandomGenerator new. - self assert: g peek equals: g next + self assert: g peek equals: g peek ] diff --git a/src/Math-Tests-Random/PMNumberGeneratorTest.class.st b/src/Math-Tests-Random/PMNumberGeneratorTest.class.st index cd37c918c..82c45070b 100644 --- a/src/Math-Tests-Random/PMNumberGeneratorTest.class.st +++ b/src/Math-Tests-Random/PMNumberGeneratorTest.class.st @@ -5,7 +5,7 @@ Class { } { #category : #tests } -PMNumberGeneratorTest >> testPeekAnswersSame [ +PMNumberGeneratorTest >> testPeekIsIdempotent [ "every subclass should implement some basic behavior." PMNumberGenerator subclasses diff --git a/src/Math-Tests-Random/PMPoissonGeneratorTest.class.st b/src/Math-Tests-Random/PMPoissonGeneratorTest.class.st index 7f1607863..c8e399e1d 100644 --- a/src/Math-Tests-Random/PMPoissonGeneratorTest.class.st +++ b/src/Math-Tests-Random/PMPoissonGeneratorTest.class.st @@ -5,19 +5,17 @@ Class { } { #category : #tests } -PMPoissonGeneratorTest >> testPeekReturnsSameAsNext [ - | poisson random | +PMPoissonGeneratorTest >> testPeekIsIdempotent [ + | poisson | poisson := PMPoissonGenerator lambda: 0.1. - random := poisson peek. - self assert: random equals: poisson next + self assert: poisson peek equals: poisson peek ] { #category : #tests } -PMPoissonGeneratorTest >> testPeekReturnsSameTwice [ - | poisson random | +PMPoissonGeneratorTest >> testPeekReturnsSameAsNext [ + | poisson | poisson := PMPoissonGenerator lambda: 0.1. - random := poisson peek. - self assert: random equals: poisson peek + self assert: poisson peek equals: poisson next ] { #category : #tests } @@ -31,16 +29,18 @@ PMPoissonGeneratorTest >> testPeekWorksAfterSampling [ ] { #category : #tests } -PMPoissonGeneratorTest >> testSampleAverageConvergesToLambda [ +PMPoissonGeneratorTest >> testSampleMeanConvergesToLambda [ "law of large numbers" "made non-random, old random version in comments" - | poisson samples | - samples := OrderedCollection new. - poisson := PMPoissonGenerator lambda: 5. "((1000 atRandom: Random new) -1)" - poisson generator seed: 42. "added for non-randomness" - 1000 timesRepeat: [ samples add: poisson next ]. - self assert: samples average >= (poisson lambda * 0.8). - self assert: samples average <= (poisson lambda * 1.2) + | gen sample | + gen := PMPoissonGenerator lambda: 5. "((1000 atRandom: Random new) -1)" + gen generator seed: 42. "added for non-randomness" + + sample := OrderedCollection new. + 1000 timesRepeat: [ sample add: gen next ]. + + self assert: sample average >= (gen lambda * 0.8). + self assert: sample average <= (gen lambda * 1.2) ] diff --git a/src/Math-Tests-Random/PMPseudoRandomNumberGeneratorTest.class.st b/src/Math-Tests-Random/PMPseudoRandomNumberGeneratorTest.class.st new file mode 100644 index 000000000..7145cc0d5 --- /dev/null +++ b/src/Math-Tests-Random/PMPseudoRandomNumberGeneratorTest.class.st @@ -0,0 +1,75 @@ +Class { + #name : #PMPseudoRandomNumberGeneratorTest, + #superclass : #TestCase, + #category : #'Math-Tests-Random' +} + +{ #category : #private } +PMPseudoRandomNumberGeneratorTest >> pseudoRandomNumberGeneratorsDo: aBlock [ + "Instanciates a pseudo random number generator + to yield to the block" + + PMPseudoRandomNumberGenerator subclasses + do: [ :typeOfGenerator | + | generator | + generator := typeOfGenerator new. + aBlock value: generator ] +] + +{ #category : #tests } +PMPseudoRandomNumberGeneratorTest >> testGeneratorStreamDoesntRespondToContents [ + self + pseudoRandomNumberGeneratorsDo: [ :gen | self should: [ gen contents ] raise: Error ] +] + +{ #category : #tests } +PMPseudoRandomNumberGeneratorTest >> testGeneratorStreamIsReadOnly [ + self + pseudoRandomNumberGeneratorsDo: [ :gen | + self shouldnt: [ gen isWriteable ]. + self assert: gen isReadable ] +] + +{ #category : #tests } +PMPseudoRandomNumberGeneratorTest >> testGeneratorStreamNeverEnds [ + self + pseudoRandomNumberGeneratorsDo: [ :gen | self shouldnt: [ gen atEnd ] ] +] + +{ #category : #tests } +PMPseudoRandomNumberGeneratorTest >> testGeneratorStreamPeekIsNext [ + self + pseudoRandomNumberGeneratorsDo: [ :gen | + | value | + value := gen peek. + self assert: gen peek equals: value. + self assert: gen next equals: value ] +] + +{ #category : #tests } +PMPseudoRandomNumberGeneratorTest >> testGeneratorStreamProducesNumbers [ + self + pseudoRandomNumberGeneratorsDo: [ :gen | + self assert: gen next isNumber. + self assert: gen next isFloat ] +] + +{ #category : #tests } +PMPseudoRandomNumberGeneratorTest >> testGeneratorStreamProducesRandomNumbers [ + self + pseudoRandomNumberGeneratorsDo: [ :gen | + | value | + value := gen next. + self shouldnt: [ gen next = value ] ] +] + +{ #category : #tests } +PMPseudoRandomNumberGeneratorTest >> testNextGivesArrayOfNumbers [ + self + pseudoRandomNumberGeneratorsDo: [ :gen | + | samples | + samples := gen next: 10. + self assert: samples size equals: 10. + self assert: (samples at: 1) isFloat. + self assert: samples asSet size equals: 10 ] +] diff --git a/src/Math-Tests-Random/PMRandomGeneratorTest.class.st b/src/Math-Tests-Random/PMRandomGeneratorTest.class.st deleted file mode 100644 index ca33218ce..000000000 --- a/src/Math-Tests-Random/PMRandomGeneratorTest.class.st +++ /dev/null @@ -1,74 +0,0 @@ -Class { - #name : #PMRandomGeneratorTest, - #superclass : #TestCase, - #category : #'Math-Tests-Random' -} - -{ #category : #tests } -PMRandomGeneratorTest >> testGeneratorStreamDoesntRespondToContents [ - PMRandomGenerator subclasses - do: [ :cls | - | gen | - gen := cls new. - self should: [ gen contents ] raise: Error ] -] - -{ #category : #tests } -PMRandomGeneratorTest >> testGeneratorStreamIsReadOnly [ - PMRandomGenerator subclasses - do: [ :cls | - | gen | - gen := cls new. - self shouldnt: [ gen isWriteable ]. - self assert: gen isReadable ] -] - -{ #category : #tests } -PMRandomGeneratorTest >> testGeneratorStreamNeverEnds [ - PMRandomGenerator subclasses do: - [:cls | | gen | - gen := cls new. - self shouldnt: [gen atEnd]]. -] - -{ #category : #tests } -PMRandomGeneratorTest >> testGeneratorStreamPeekIsNext [ - PMRandomGenerator subclasses - do: [ :cls | - | gen value | - gen := cls new. - value := gen peek. - self assert: gen peek equals: value. - self assert: gen next equals: value ] -] - -{ #category : #tests } -PMRandomGeneratorTest >> testGeneratorStreamProducesNumbers [ - PMRandomGenerator subclasses - do: [ :cls | - | gen | - gen := cls new. - self assert: gen next isNumber. - self assert: gen next isFloat ] -] - -{ #category : #tests } -PMRandomGeneratorTest >> testGeneratorStreamProducesRandomNumbers [ - PMRandomGenerator subclasses do: - [:cls | | gen value | - gen := cls new. - value := gen next. - self shouldnt: [gen next = value]]. -] - -{ #category : #tests } -PMRandomGeneratorTest >> testNextGivesArrayOfNumbers [ - PMRandomGenerator subclasses - do: [ :cls | - | gen samples | - gen := cls new. - samples := gen next: 10. - self assert: samples size equals: 10. - self assert: (samples at: 1) isFloat. - self assert: samples asSet size equals: 10 ] -]