Last active
August 13, 2023 08:38
-
-
Save arialdomartini/d057124daac8cdb206e52c8d1e744b46 to your computer and use it in GitHub Desktop.
Randomly repeat characters in a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test | |
"repeated characters are replaced with one" | |
{ | |
let randomlyRepeat char = | |
gen { | |
let! randomLength = Arb.generate<int> |> Gen.map (fun i -> abs i + 1) | |
return String(char, randomLength) | |
} | |
let arbitrarilyRepeatCharactersInString s = | |
gen { | |
let! result = | |
Seq.map randomlyRepeat s | |
|> Gen.sequence | |
let single = String.concat "" result | |
return single | |
} | |
let cases = gen { | |
let! r = randomString | |
let! repeated = arbitrarilyRepeatCharactersInString r | |
return (r, repeated) | |
} | |
let c = Gen.sample 10 100 cases | |
Tests.failtest "OMG I failed!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment