1. How to test function that uses public variable?

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?

new topic     » topic index » view message » categorize

2. Re: How to test function that uses public variable?

SnakeCharmer said...
include addlucky.e 
public integer LUCKY = 1 

'LUCKY' (addlucky.e:1) has not been declared.

What's wrong?

declare LUCKY before including addlucky.e

new topic     » goto parent     » topic index » view message » categorize

3. Re: How to test function that uses public variable?

petelomax said...
SnakeCharmer said...
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?

new topic     » goto parent     » topic index » view message » categorize

4. Re: How to test function that uses public variable?

petelomax said...

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.

new topic     » goto parent     » topic index » view message » categorize

5. Re: How to test function that uses public variable?

Insolor said...
petelomax said...
SnakeCharmer said...
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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu