Unit-testing in same file

new topic     » topic index » view thread      » older message » newer message

Is it possible to test function in same myfunc.e, not in separate t_myfunc.e? For example, I need Luhn algorithm for verifying credit cards.

http://rosettacode.org/wiki/Luhn_test#Euphoria

When this file will be started, it will check an algorithm correctness. It that is necessary for me. But if I import this file to the program, the constant cc_numbers is imported and the for-cycle will be executed, which are absolutely not necessary to me. Besides it would be desirable not to lose possibility of the automated testing. By the way, Python is able to do such trick by means of checking how the file is started - as the separate program or as the imported function:

if __name__ == "__main__" 
Hope you understand what I mean. Sorry for my ugly machine-translated english.

P.S. It would be absolutely amazing, if Euphoria would have something like Python's doctests. Here is how it could look for Luhn algorithm:

function luhn(sequence cc) 
>>> "49927398716"  --  Output effect of this input value should be... 
1                  --  ...such! 
>>> "49927398717" 
0 
>>> "1234567812345678" 
0 
>>> "1234567812345670" 
1 
-- Other part of function. 

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu