[squeak-dev] Units package

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] Units package

Cesar Rabak
I'm doing some test with the Units package and the results are puzzling me:

In a pristine 3.10.2-7179-basic image, I installed Units version 4 via
Universe.

I run the UnitsTest via SUnit Runner and all the 8 tests run green. So
far OK!

Now if I copy to a Workspace from the source of the UnitsTest>>testAdd
the following snippet:

u :=  (14 units: #feet) + (10 units: #meters).

If I print the whole expression I get '46.8083989501312 feet' as expected:

Now when I attempt to make any other thing with the "u" object, like
inspecting it, I get a stack, with the Title "Error: My subclass should
have overriden #hash.

Now, the tests run OK in the SUnit and fail in the Workspace! Even
attempting to use the object gets the same stack trace...

I probably doing something grossly wrong here as it seems to basic to
have eluded other users, but I cannot see what it is it!

Can you please advise?

--
Cesar Rabak
GNU/Linux User 52247.
Get counted: http://counter.li.org/

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Units package

cedreek
Hi

>
> u :=  (14 units: #feet) + (10 units: #meters).

same for me, if just evaluate this line twice... the parser use the
hash value...
a hash value has to be defined for Unit

I added in UnitValue (comparing):

hash

        ^value hash

and it seems to work... Units tests pass

hth

Cédrick


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Units package

Balázs Kósi
In reply to this post by Cesar Rabak
Hi!

> Now, the tests run OK in the SUnit and fail in the Workspace! Even
> attempting to use the object gets the same stack trace...
I met this problem recenty. It is something to do with, how the compiler
handles global variables. It involves a dictionary lookup, where your UnitValue
object is (part of) the key.

> Can you please advise?
Implement UnitValue >> #hash eg:

hash

        ^value hash bitXor: self class hash

Balázs

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Units package

cedreek
>
> hash
>
>        ^value hash bitXor: self class hash
>
There, (60 units: #seconds) hash = (60 units: #meters) returns true
I'm not sure this could lead to problem but what about:

hash
        ^value hash bitXor: unit hash

and

testEquality

        self deny: (60 units: #seconds) hash = (60 units: #meters) hash.
        self deny: (60 units: #seconds) = (60 units: #meters).
        self deny: (60 units: #seconds) hash = (1 units: #minutes) hash.
        self assert: (60 units: #seconds) = (1 units: #minutes).


Cédrick


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Units package

Balázs Kósi
> UnitValue >> hash
>        ^value hash bitXor: unit hash
>
> and
>
> testEquality
>
>        self deny: (60 units: #seconds) hash = (60 units: #meters) hash.
>        self deny: (60 units: #seconds) = (60 units: #meters).
>        self deny: (60 units: #seconds) hash = (1 units: #minutes) hash.
>        self assert: (60 units: #seconds) = (1 units: #minutes).

Much better :)

Cheers, Balázs

ps: cc-d to Marcus Denker, because he seems to be maintainer of the package.

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Units package

Cesar Rabak
In reply to this post by cedreek
cdrick escreveu:

> Hi
>
>> u :=  (14 units: #feet) + (10 units: #meters).
>
> same for me, if just evaluate this line twice... the parser use the
> hash value...
> a hash value has to be defined for Unit
>
> I added in UnitValue (comparing):
>
> hash
>
> ^value hash
>
> and it seems to work... Units tests pass
>
> hth
>
Thanks Cédrick!

I figure out that I could circumvent this using the 'create' button in
the debugger, but I thought I must be doing something wrong (perhaps
missing some dependency?).

If my reading of the code is correct, we have to define hash and =
methods. . .

I'll get back to this next week when I follow other tests.

Thanks again,

--
Cesar Rabak
GNU/Linux User 52247.
Get counted: http://counter.li.org/

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Units package

cedreek
In reply to this post by cedreek
2008/6/19 Gabriel Cotelli <[hidden email]>:
> Hi,
> I believe is not a good idea to test de denial of two hashes...
> I two objects are equal then the hash must be the same, but te inverse is
> not true

I agree, I wrote this test to show the behavior (and I should have
left the failing test :) ). The hash function is probably not good.

>
> If two objects aren't equal the hash could be the same... and that's ok...
> the number of possible hashes is lesser than the number of possible
> objects...
>
> Why not?
>
> testEquality
>        self deny: (60 units: #seconds) = (60 units: #meters).
>        self assert: (60 units: #seconds) = (1 units: #minutes);
>              assert: (60 units: #seconds) hash = (1 units: #minutes) hash.
the last one fails with the provided hash.

this hash seems ok:

UnitValue>>hash
|baseUnit|

        baseUnit := (self baseUnits).
  ^ baseUnit value hash bitXor: baseUnit unit hash


> Gabriel
>
Thanks ;)

Cédrick


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Units package

Marcus Denker
In reply to this post by Balázs Kósi
Hello,

the bug seems to be fixed in the last version. I harvested the test to make sure (this is
in Units-md.16 on SqueakSource)

The versions starting with -14 contain many enhancements (and the bugfix). This was contributed
by Pinesoft (http://www.pinesoft.co.uk/). 

Maybe the universe version could be updated?

      Marcus

On Thu, Jun 19, 2008 at 4:56 PM, Balázs Kósi <[hidden email]> wrote:
> UnitValue >> hash
>        ^value hash bitXor: unit hash
>
> and
>
> testEquality
>
>        self deny: (60 units: #seconds) hash = (60 units: #meters) hash.
>        self deny: (60 units: #seconds) = (60 units: #meters).
>        self deny: (60 units: #seconds) hash = (1 units: #minutes) hash.
>        self assert: (60 units: #seconds) = (1 units: #minutes).

Much better :)

Cheers, Balázs

ps: cc-d to Marcus Denker, because he seems to be maintainer of the package.