From b07a3c24304d79fd9b5873c2efcc468e548cfa5f Mon Sep 17 00:00:00 2001 From: Karl Voit Date: Sat, 25 Feb 2017 11:18:10 +0100 Subject: [PATCH] fixed unit test bug --- filetags.py | 3 ++- tests/unit_tests.py | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/filetags.py b/filetags.py index 9f059af..f5a6fac 100755 --- a/filetags.py +++ b/filetags.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- -PROG_VERSION = u"Time-stamp: <2017-02-12 17:33:32 vk>" +PROG_VERSION = u"Time-stamp: <2017-02-25 11:17:56 vk>" ## TODO: ## - fix parts marked with «FIXXME» @@ -961,6 +961,7 @@ def get_upto_nine_keys_of_dict_with_highest_value(mydict, list_of_tags_to_omit=[ values with the highest values. Example1: { "key2":45, "key1": 33} -> [ "key1", "key2" ] + Example2: { "key2":45, "key1": 33, "key3": 99} list_of_tags_to_omit=["key3"] -> [ "key1", "key2" ] @param mydict: dictionary holding keys and values @param list_of_tags_to_omit: list of strings that should not be part of the returned list diff --git a/tests/unit_tests.py b/tests/unit_tests.py index 71570bd..304c4d3 100755 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# Time-stamp: <2016-10-16 12:48:52 vk> +# Time-stamp: <2017-02-25 11:17:22 vk> ## invoke tests using following command line: ## ~/src/vktag % PYTHONPATH="~/src/filetags:" tests/unit_tests.py --verbose @@ -85,11 +85,20 @@ class TestMethods(unittest.TestCase): def test_get_upto_nine_keys_of_dict_with_highest_value(self): self.assertEqual(filetags.get_upto_nine_keys_of_dict_with_highest_value({ "key2":45, "key1": 33}), [ "key1", "key2" ]) - self.assertEqual(filetags.get_upto_nine_keys_of_dict_with_highest_value({ "key1":45, "key2": 33, "key3": 3, "key4": 1, "key5": 5, "key6": 159, "key7": 0, "key8": 999, "key9": 42, "key10": 4242}), \ - [ "key1", "key10", "key2", "key3", "key4", "key5", "key6", "key8", "key9"]) - self.assertEqual(filetags.get_upto_nine_keys_of_dict_with_highest_value({ "key1":45, "key2": 33, "key3": 3, "key4": 1, "key5": 5, "key6": 159, "key7": 0, "key8": 999, "key9": 42, "key10": 4242, "key11": 1234, "key12": 1234, "key13": 1234, "key14": 1234}, list_of_tags_to_omit=['key2', 'key3', 'key7', 'key4']), \ - [ "key1", "key10", "key11", "key12", "key13", "key14", "key5", "key6", "key8"]) + mydict = { "key1":45, "key2": 33, "key3": 3, "key4": 1, "key5": 5, "key6": 159, + "key7": 0, "key8": 999, "key9": 42, "key10": 4242} + myresult = [ "key1", "key10", "key2", "key3", "key4", "key5", "key6", "key8", "key9"] + self.assertEqual(filetags.get_upto_nine_keys_of_dict_with_highest_value(mydict), myresult) + + mydict = { "key1":45, "key2": 33, "key3": 3, "key4": 1, "key5": 5, "key6": 159, + "key7": 0, "key8": 999, "key9": 42, "key10": 4242, "key11": 1234, + "key12": 1234, "key13": 1234, "key14": 1234} + list_of_tags_to_omit = ['key11', 'key3', 'key7', 'key14'] + myresult = [ "key1", "key10", "key12", "key13", "key2", "key5", "key6", "key8", "key9"] + self.assertEqual(filetags.get_upto_nine_keys_of_dict_with_highest_value(mydict, + list_of_tags_to_omit=list_of_tags_to_omit), + myresult) def test_get_common_tags_from_files(self):