> Can I use method names other then
"test_sometest" in my script. For example, I have a method that performs a
calculation and returns a value and passes that value to test method. Unless I
rename my calculation method as "test_calculation" the method is not executed. I
know that my class is inheriting from test::unit, but do I need to precede every
method name with "test"?
I'm not sure I understand this question. Can you
give us a f'rinstance?
I would have thought that you can include a method
"some_method" in your class and call it explicitly from within something
called "test_method". I think
I've done that, and it would startle me if that weren't so. However, if I
am to be startled, you should be able to put that calculation and that method in
another class, at least, and call that class. If necessary, you could do
it as a class method, and call the method without having to create an object to
get the benefit of the method.
[quoting]
Secondly, I am trying to generate test
users for my test by generating a random number and the concatenating that
number to a string "test" so that the result is "test12345", for
example.
I'm using
rand(max-0) to generate the number, but it returns a big number. So I tried
stripping the number and then concatenating but it didn't work. Ultimately, I
would like to have generate names with 5 digits randomly like the example above.
Any ideas?
def
Random_name
$rand_num = rand(max=0)
$rand_num =~ /^0???/
$rand_num = rand(max=0)
$rand_num =~ /^0???/
$rand_user =
$rand_num.to_s
puts ("tester"+ ($rand_user))
return $rand_user
end
puts ("tester"+ ($rand_user))
return $rand_user
end
[/quoting]
Is the problem that the name has to
be a certain length, and thus numeric part of the name must be five digits
always?
def
random_name
# give us a random
number where the integer part is up to five digits
long
$random_five_digits =
rand(100_000)
# make it a
string
$random_five_digits =
$random_five_digits.to_s
# if it's shorter than
five characters, pad it with leading zeroes
$random_five_digits =
$random_five_digits.rjust(5, "0")
#prepend the "tester"
part (as your code reads, or "test", as your description
reads)
$random_user = "tester"
+ $random_five_digits
end
or, more concisely,
def
random_name
#object.method.method
is sooooo cool, albeit a little harder to
read...
$random_five_digits =
rand(100_000).to_s.rjust(5, "0")
$random_user = "tester"
+ $random_five_digits
end
_______________________________________________ Wtr-general mailing list [email protected] http://rubyforge.org/mailman/listinfo/wtr-general
