Title: makes incorrect assumption about dict ordering
Type: behaviour Severity: normal
Components: Versions: Jython 2.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: fwierzbicki Nosy List: amak, csebasha, fwierzbicki, geraint
Priority: normal Keywords:

Created on 2012-12-21.07:49:35 by geraint, last changed 2013-02-25.19:11:13 by fwierzbicki.

msg7549 (view) Author: Geraint Jones (geraint) Date: 2012-12-21.07:49:34
Test passed when using Java 7 - I tried Oracle's and IBM's.

However, when I use Java 8, it fails.

I believe is not a good test because it assumes that 2 adjacent dicts (hashes) will, if populated with the same key/value pairs in the same order, return those values in the same order.

For example, populating both dict_a and dict_b with values 3, 1, 2, 7, 6, 5, 4, and 0, using the value as the key (i.e. key=value in each tuple), it assumes that both dict_a and dict_b will both be the same.

I observed that this is the case when using Java 7 - both dicts are the same.

I also observed that using Python instead of Jython, not only are both dicts the same, but they are both ordered in ascending key sequence.

However, they are not the same with Java 8, as illustrated by one set of results I saw:

  dict_a  {3: 3, 6: 6, 0: 0, 4: 4, 1: 1, 5: 5, 2: 2, 7: 7}
  dict_b  {5: 5, 6: 6, 3: 3, 2: 2, 1: 1, 7: 7, 4: 4, 0: 0}

It is my understanding that a dict is a hash, and that the order of hashes is not specified and should not be assumed.

The fact that makes an assumption about the ordering means that it is not a reliable test and should be removed.
msg7649 (view) Author: Alan Kennedy (amak) Date: 2013-02-09.13:56:43
It is indeed the case that ordering of keys should not be relied on. This is the behaviour of the original cpython test, and we target getting all cpython tests to pass on jython. This ordering assumption makes the test non-portable to jython, especially when it is run on different JVMs, as you have found.

Frank Wierzbicki is in the process of fixing these in cpython, so that we don't have to have specialised versions of the tests.

Doctests in test_dictcomp depend on dict order
msg7652 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-09.17:54:36
Usually this happens when there are doctests involved - as in the test that Alan pointed out. test_dict though doesn't include any doctests, and my scanning of the test doesn't have any of these popping out at me. Would you mind posting the specific tests that fail for you so I can have a better look? Also have you seen the same behavior on 2.7 (the default branch) dict_test looks like it mainly has cosmetic changes so presumably the problem would persist.
Date User Action Args
2013-02-25 19:11:13fwierzbickisetversions: + Jython 2.5, - 2.5.2
2013-02-09 17:54:54fwierzbickisetpriority: normal
assignee: fwierzbicki
2013-02-09 17:54:36fwierzbickisetmessages: + msg7652
2013-02-09 13:56:44amaksetnosy: + amak, fwierzbicki
messages: + msg7649
2012-12-21 15:43:18csebashasetnosy: + csebasha
2012-12-21 07:49:35geraintcreate