1. How to test function that uses public variable?
- Posted by SnakeCharmer Sep 20, 2012
- 1745 views
My program rot13.ex:
include addlucky.e public integer LUCKY = 1 sequence Message = "Hello, World!" -- must be converted to "Ifmmp, Xpsme!" integer CurrentSymbol for i = 1 to length(Message) do CurrentSymbol = Message[i] if (CurrentSymbol >= 'a' and CurrentSymbol <= 'z') then CurrentSymbol -= 'a' CurrentSymbol = addLucky(CurrentSybmol) CurrentSymbol += 'a' elsif (CurrentSymbol >= 'A' and CurrentSymbol <= 'Z') then CurrentSymbol -= 'A' CurrentSymbol = addLucky(CurrentSybmol) CurrentSymbol += 'A' else CurrentSymbol = 0 end if if CurrentSymbol != 0 then Message[i] = CurrentSymbol end if end for puts(1, Message)
addlucky.e:
export function addLucky(integer Letter) Letter += LUCKY if Letter > 25 then Letter -= 25 end if return Letter end function
t_addlucky.e
include std/unittest.e include addlucky.e public integer LUCKY = 1 test_equal("", 1, addLucky(0)) test_equal("", 2, addLucky(1)) test_equal("", 0, addLucky(25))
C:\WORK>eutest t_uniquens.e
interpreting t_addlucky.e: C:\WORK\addlucky.e:1 <0074>:: Errors resolving the following references: 'LUCKY' (addlucky.e:1) has not been declared.
export function addLucky(integer Letter) ^
FAILURE: t_addlucky.e EUPHORIA error with status 1
Test results summary: FAIL: t_addlucky.e Files (run: 1) (failed: 1) (0% success)
What's wrong?
2. Re: How to test function that uses public variable?
- Posted by petelomax Sep 23, 2012
- 1652 views
include addlucky.e public integer LUCKY = 1
'LUCKY' (addlucky.e:1) has not been declared.
What's wrong?
declare LUCKY before including addlucky.e
3. Re: How to test function that uses public variable?
- Posted by Insolor Sep 25, 2012
- 1576 views
include addlucky.e public integer LUCKY = 1
'LUCKY' (addlucky.e:1) has not been declared.
What's wrong?
declare LUCKY before including addlucky.e
Doesn't eutest support forward references?
4. Re: How to test function that uses public variable?
- Posted by SnakeCharmer Sep 25, 2012
- 1549 views
declare LUCKY before including addlucky.e
It didn't conceive any effect.
UPD: I found the decision independently! It is enough to take out all public variables in the separate file. It even increased convenience.
5. Re: How to test function that uses public variable?
- Posted by mattlewis (admin) Sep 25, 2012
- 1520 views
include addlucky.e public integer LUCKY = 1
'LUCKY' (addlucky.e:1) has not been declared.
What's wrong?
declare LUCKY before including addlucky.e
Doesn't eutest support forward references?
Euphoria does. Eutest just executes your code with euphoria (or translates, etc). However, you need to include the file that declares the variable in the file that uses the variable (or a file that does a public include on the file that declares the public variable).
Matt