You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
enumBit:Int,CaseIterable,SupportsRandomGeneration{case zero =0case one
}
In order to test that this setup works, I have a custom RandomNumberGenerator type that returns fixed values, like so:
structFixedRNG:RandomNumberGenerator{letvalues:[UInt64]vark=0mutatingfunc next()->UInt64{letvalue=values[k]
k =(k +1)% values.count
return value
}}
and a test file
import XCTest
import Dependencies
finalclassBitTests:XCTestCase{func test_random(){letn=7letexpBits=[Bit.zero,.one,.one,.zero,.zero,.one,.zero]let _ =withDependencies{
$0.withRandomNumberGenerator =WithRandomNumberGenerator(FixedRNG(values:[0,1,1,0,0,1,0]))} operation:{
for k in 0..< n {letres=Bit.random()letexp=expBits[k]XCTAssert(res == exp)}}}}
The problem is that the test fails because Bit.random() is returning .zero every time and, for the life of me, I can't figure out why. I could use some extra pairs of eyes to look at it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I have a protocol for types that support random values,
and several such types, one of which is
In order to test that this setup works, I have a custom
RandomNumberGenerator
type that returns fixed values, like so:and a test file
The problem is that the test fails because
Bit.random()
is returning.zero
every time and, for the life of me, I can't figure out why. I could use some extra pairs of eyes to look at it.Any ideas? Many thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions