def test_is_counting(self):
        """
        test_init - makes sure letter counter initializes right
        """

        lc = LetterCounter('a')

        self.assertTrue(lc.is_counting('a'))
        self.assertFalse(lc.is_counting('b'))
コード例 #2
0
    def test_append_twice(self):

        lc = LetterCounter('a')

        lc.append('b')
        lc.append('b')

        self.assertEqual(2, len(lc.letters))
        self.assertEqual(1, lc.letters[1].count)
コード例 #3
0
    def test_append(self):
        """
        test_append - make sure new non controlled letters append right onto LetterCounter.letters list
        """

        lc = LetterCounter('a')

        lc.append('b')

        self.assertEqual(2, len(lc.letters))
        self.assertEqual(1, lc.letters[1].count)
コード例 #4
0
    def test_init(self):
        """
        test_init - makes sure letter counter initializes right
        """

        lc = LetterCounter('a')
        self.assertEqual('a', lc.letters[0].letter)
        self.assertEqual(1, lc.letters[0].count)
コード例 #5
0
def letter_counts(in_str):
    if len(in_str) == 1:
        lc = LetterCounter(in_str[0])
        return lc.letters
    elif len(in_str) >= 1:
        lc = LetterCounter(in_str[0])
        for l in in_str[1:]:
            if lc.is_counting(l):
                lc.increment(l)
            else:
                lc.append(l)
        return lc.letters
    # null input
    return None
コード例 #6
0
    def test_increment_letter_not_under_control(self):
        """
        test_increment_letter_not_under_control - make sure incrementing letter not under control doesn't affect letters
        list
        :return:
        """

        lc = LetterCounter('a')

        lc.append('b')

        self.assertEqual(2, len(lc.letters))
        self.assertEqual(1, lc.letters[1].count)
        lc.increment('b')
        self.assertEqual(2, lc.letters[1].count)
        lc.increment('z')
        self.assertEqual(2, len(lc.letters))
コード例 #7
0
    def test_increment(self):
        """
        test_increment - make sure letter undercontrol count increments
        """

        lc = LetterCounter('a')

        lc.append('b')

        self.assertEqual(2, len(lc.letters))
        self.assertEqual(1, lc.letters[1].count)
        lc.increment('b')
        self.assertEqual(2, lc.letters[1].count)