[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to implement this in unit testing

Muath A. Khalaf

5/21/2008 7:35:00 AM

[Note: parts of this message were removed to make it a legal post.]

Hi,
If I want to implement something like this in Ruby Unit Testing:
test_z_lessthan_20
x = choose(1..5)
y = choose(0..3)
z = x * y
assert(z < 20)
end_choice
end_choice
end

The idea here is to run the previous test for all x and y values. My
initial idea is to parse previous code and generate something like
this:
test_z_lessthan_20
[1..5].each do |x|
[0..3].each do |y|
z = x * y
assert(z < 20)
end
end
end
My question is what is the best way to parse previous code i.e. is
there a parser where I will just change small parts of it to pasre the
choose part.
Also is there a way to implement the previous code dynamically during
runtime or at least do the parsing and change on the fly instead of
creating some code statically.

Thanks



2 Answers

ethica1

5/21/2008 8:24:00 AM

0

On May 21, 12:34 am, "Muath A. Khalaf" <moa...@yahoo.com> wrote:
> [Note:  parts of this message were removed to make it a legal post.]
>
> Hi,
> If I want to implement something like this in Ruby Unit Testing:
> test_z_lessthan_20
>     x = choose(1..5)
>     y = choose(0..3)
>     z = x * y
>     assert(z < 20)
>     end_choice
>     end_choice
> end
>
> The idea here is to run the previous test for all x and y values. My
> initial idea is to parse previous code and generate something like
> this:
> test_z_lessthan_20
>     [1..5].each do |x|
>         [0..3].each do |y|
>              z = x * y
>              assert(z < 20)
>         end
>      end
> end
> My question is what is the best way to parse previous code i.e. is
> there a parser where I will just change small parts of it to pasre the
> choose part.
> Also is there a way to implement the previous code dynamically during
> runtime or at least do the parsing and change on the fly instead of
> creating some code statically.
>
> Thanks

just small change as [1..5].each does not work correctly so I may
change it to [1,2,3,4,5].each

Craig Demyanovich

5/21/2008 1:20:00 PM

0

On Wed, May 21, 2008 at 4:25 AM, ethica1 <Muath.Alkhalaf@gmail.com> wrote:
> just small change as [1..5].each does not work correctly so I may
> change it to [1,2,3,4,5].each

You can use a range instead of an array, e.g., (1..5).each { |n| puts n } .

Craig