NCAS-CMS / cfunits

A Python interface to UNIDATA’s UDUNITS-2 library with CF extensions:
http://ncas-cms.github.io/cfunits
MIT License
11 stars 8 forks source link

Update to equivalence and equality for non-valid units #19

Closed davidhassell closed 3 years ago

davidhassell commented 3 years ago

Non valid units (such as the integer 1) should not be equivalent to anything. I.e. the following tests should all pass:

        self.assertFalse(Units().equivalent(Units(1)))
        self.assertFalse(Units(1).equivalent(Units(1)))
        self.assertFalse(Units(2).equivalent(Units(1)))
        self.assertFalse(Units('').equivalent(Units(1)))
        self.assertFalse(Units(' ').equivalent(Units(1)))
        self.assertFalse(Units('1').equivalent(Units(1)))
        self.assertNotEqual(Units(1), Units(1))
        self.assertNotEqual(Units(1), Units(2))
        self.assertNotEqual(Units(1), Units())
        self.assertNotEqual(Units(1), Units(''))
        self.assertNotEqual(Units(1), Units(' '))
        self.assertNotEqual(Units(1), Units('metre'))

Currently all of these tests fail.

I think it is right to say that Units(1) is not equivalent nor equal to Units(1) because, even though both units are the same, they are both meaningless, so the promise that downstream applications might assume by virtue of equivalence/equality would be compromised.

davidhassell commented 3 years ago

Will be applied in v3.3.1