Re: Unit-testing in same file
- Posted by SnakeCharmer Jul 29, 2012
- 1009 views
My first attempt to use unit-testing. What's wrong?
happy.e
include misc.e function IsHappy(integer x) integer Happy = 0 if x > 10 then sequence Cyphers = sprint(x) integer Capacity = length(Cyphers) if remainder(Capacity, 2) = 0 then Capacity /= 2 for i = 1 to Capacity do Happy += Cyphers[i] Happy -= Cyphers[Capacity + i] end for if Happy = 0 then Happy = 1 else Happy = 0 end if end if end if return Happy end function
t_happy.e
include happy.e include std/unittest.e constant Tickets = {-11, 0, 11, 23, 4444, 0101, 50505, 505050, 173056} constant Answers = {0, 0, 1, 0, 1, 0, 0, 0, 1} sequence Message integer Expected, Outcome for i = 1 to length(Tickets) do Message = "Testing Happy Ticket " & i Expected = Answers[i] Outcome = IsHappy(Tickets[i]) test_equal(Message, Expected, Outcome) end for test_report()
eutest:
interpreting t_happy.e: C:\WORK\t_happy.e:12 <0074>:: Errors resolving the following references: 'IsHappy' (t_happy.e:12) has not been declared. Outcome = IsHappy(Tickets[i]) ^ FAILURE: t_happy.e EUPHORIA error with status 1 Test results summary: FAIL: t_happy.e Files (run: 1) (failed: 1) (0% success)