def test_hash(self): self.assertEquals(1511848646, IdName.hash("ab")) self.assertEquals(669497117, IdName.hash("abc")) self.assertEquals(-1994190713, IdName.hash("abcd")) self.assertEquals(-802680418, IdName.hash("abcde")) self.assertEquals(1266308680, IdName.hash("abcdef")) self.assertEquals(-379372513, IdName.hash("abcdefg")) self.assertEquals(-1416967159, IdName.hash("abcdefgh")) self.assertEquals(53556896, IdName.hash("abcdefghi")) self.assertEquals(-4427318, IdName.hash("abcdefghij"))
def test_computehash(self): test_keys = ( ('_mt__Etch_RuntimeException', 1071849665), ('foo', 711657441), ('bar', 677693038), ('ZZZZZZZZZZZZZZZZZZZZ', -1181680379), ) for t in test_keys: print " IdName.hash('%s') -> %d" % (t[0], t[1]) self.assertEquals(t[1], IdName.hash(t[0]))
def _testMt(self, *args): if len(args) == 1: n = args[0] i = IdName.hash(n) elif len(args) == 2: i = args[0] n = args[1] else: raise Exception, "Bad number of arguments" mt = Type(i, n) self.assertEquals(i, mt.getId()) self.assertEquals(n, mt.getName())
def _testMf(self, *args): if len(args) == 1: name = args[0] mf = Field(name) self.assertEquals(IdName.hash(name), mf.getId()) self.assertEquals(name, mf.getName()) elif len(args) == 2: i = args[0] n = args[1] mf = Field(i, n) self.assertEquals(i, mf.getId()) self.assertEquals(n, mf.getName()) else: pass
def test_hashCodeObject(self): self.assertEquals(id(IdName(1, "foo")), id(IdName(1, "foo"))) self.assertEquals(id(IdName(1, "bar")), id(IdName(1, "bar"))) self.assertEquals(id(IdName(2, "foo")), id(IdName(2, "foo"))) self.assertEquals(id(IdName(2, "bar")), id(IdName(2, "bar")))
def test_equals(self): self.assertEquals(IdName(1, "foo"), IdName(1, "foo")) self.assertEquals(IdName(1, "bar"), IdName(1, "bar")) self.assertEquals(IdName(2, "foo"), IdName(2, "foo")) self.assertEquals(IdName(2, "bar"), IdName(2, "bar")) self.assertNotEquals(IdName(1, "foo"), IdName(2, "foo")) # id changed self.assertNotEquals(IdName(1, "foo"), IdName(1, "bar")) # name changed self.assertNotEquals(IdName(1, "foo"), IdName(2, "bar")) # id and name changed self.assertNotEquals(IdName(1, "foo"), None) self.assertNotEquals(IdName(1, "foo"), 1) self.assertNotEquals(IdName(1, "foo"), True)
def test_repr(self): self.assertEquals("foo(1)", repr(IdName(1, "foo"))) self.assertEquals("bar(1)", repr(IdName(1, "bar"))) self.assertEquals("foo(2)", repr(IdName(2, "foo"))) self.assertEquals("bar(2)", repr(IdName(2, "bar")))
def test_getName(self): self.assertEquals("foo", IdName(1, "foo").getName()) self.assertEquals("bar", IdName(1, "bar").getName()) self.assertEquals("foo", IdName(2, "foo").getName()) self.assertEquals("bar", IdName(2, "bar").getName())
def test_getId(self): self.assertEquals(1, IdName(1, "foo").getId()) self.assertEquals(1, IdName(1, "bar").getId()) self.assertEquals(2, IdName(2, "foo").getId()) self.assertEquals(2, IdName(2, "bar").getId())