diff --git a/common/lib/xmodule/xmodule/tests/test_word_cloud.py b/common/lib/xmodule/xmodule/tests/test_word_cloud.py index e0f59941cb..36656492a6 100644 --- a/common/lib/xmodule/xmodule/tests/test_word_cloud.py +++ b/common/lib/xmodule/xmodule/tests/test_word_cloud.py @@ -38,15 +38,14 @@ class WordCloudModuleTest(LogicTest): response['student_words'], {'sun': 1, 'dog': 6, 'cat': 12} ) + self.assertListEqual( response['top_words'], - [{'text': 'dad', 'size': 2, 'percent': 9.0}, - {'text': 'sun', 'size': 1, 'percent': 5.0}, + [{'text': 'cat', 'size': 12, 'percent': 55.0}, + {'text': 'dad', 'size': 2, 'percent': 9.0}, {'text': 'dog', 'size': 6, 'percent': 27.0}, {'text': 'mom', 'size': 1, 'percent': 5.0}, - {'text': 'cat', 'size': 12, 'percent': 54.0}] + {'text': 'sun', 'size': 1, 'percent': 4.0}] ) - self.assertEqual( - 100.0, - sum(i['percent'] for i in response['top_words'])) + self.assertEqual(100.0, sum(i['percent'] for i in response['top_words'])) diff --git a/common/lib/xmodule/xmodule/word_cloud_module.py b/common/lib/xmodule/xmodule/word_cloud_module.py index f3a8011062..e6ca4f53a4 100644 --- a/common/lib/xmodule/xmodule/word_cloud_module.py +++ b/common/lib/xmodule/xmodule/word_cloud_module.py @@ -148,11 +148,12 @@ class WordCloudModule(WordCloudFields, XModule): """ list_to_return = [] percents = 0 - for num, word_tuple in enumerate(six.iteritems(top_words)): + sorted_top_words = sorted(top_words.items(), key=lambda x: x[0].lower()) + for num, word_tuple in enumerate(sorted_top_words): if num == len(top_words) - 1: percent = 100 - percents else: - percent = round(100.0 * word_tuple[1] / total_count) + percent = round((100.0 * word_tuple[1]) / total_count) percents += percent list_to_return.append( {