|
|
|
|
|
by thomasz
5011 days ago
|
|
This looks promising. Nothing that has never been done before, but I really like the support for baked in doctests and contracts. This kind of sugar can make a real difference in terms of quality and readability #from the website, because it seems to be down for many right now.
class SmallSample
var _random = Random()
def randomString(length as int, alphabet as String) as String
require
length > 0
alphabet <> ''
ensure
result.length == length
test
utils = SmallSample()
assert utils.randomString(5, 'ab').length == 5
s = utils.randomString(1000, 'a')
for c in s, assert c == 'a'
body
sb = StringBuilder()
for i in length
c = alphabet[_random.next(alphabet.length)]
sb.append(c)
return sb.toString
|
|
Seems that doesn't use explicit variable declaration. Supporting that would be a great improvement over Python.