[erlang-questions] On Joe's micro-lightweight-unit-testing

Joe Armstrong erlang@REDACTED
Wed Mar 25 15:39:10 CET 2009


On Wed, Mar 25, 2009 at 12:52 PM, Angel <clist@REDACTED> wrote:
> Hi list
>
> Im very new to erlang, just still astonished about erlang and all, you guys, say here
>
> Still im trying every day going deeper and deeper on erlang and functional programing.
>
> Got recently very please reading Joe's introcction to TTD and Unit test on erlang
>
> shttp://armstrongonsoftware.blogspot.com/2009/01/micro-lightweight-unit-testing.html
>
> some where in the article Joe says..
>
> step 4) Add unit tests for fastfib
>
> test/0 looks like this:
>
> test() ->
> 0 = fib(0),
> 1 = fib(1),
> 1 = fib(2),
> 6765 = fib(20),
> 0 = fastfib(0),
> 1 = fastfib(1),
> 1 = fastfib(2),
> 2 = fastfib(3),
> K = fib(25),
> K = fastfib(25),
> ok.
>
> Here I check that fastfib returns the same value as fib with the lines
>  K = fib(25),
> K = fastfib(25).
>
> But K=fib(25) binds K to the value fib(25) so, K= fastbib(25) must be wrong
> as K was previously bound to fib(25) ¿isnt it?

Take the argument in small steps:

            K = 10,
            K = 10,

succeeds (unsurprisingly), but

             K = 10,
             K = 11,

fails (K can't be both 10 and 11)

Now change the right hand side of '=' to a function call

             K = 10,
             K = f2(..)

This means evaluate f2(...), and test if it is 10 - just like the above

             K = f1(),
             K = f2()

means evalate f1() then evalute f2() and test if it has the same value as
f1() .

When you look at a code fragment containing a variable in a pattern
you should mentally think "is this the first time I've seen this
variable"  if the answer is yes, then the variable will become bound
if the pattern match succeeds. If
no then the pattern match acts as a test, which will succeed or fail depending
upon the value of the variable.

/Joe


/Joe








>
> so, What im missing here ?
>
> Thanks
>
> --
> No imprima este correo si no es necesario. El medio ambiente está en nuestras manos.
> __________________________________________
>
> Clist UAH a.k.a Angel
> __________________________________________
> ...being the second biggest search engine in the world is good enough for us. Peter @ Pirate Bay.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list