def test_one_line_string(self): def error_msg(str_odd=True, width_odd=True): string = "Odd" if str_odd else "Even" width = "odd" if width_odd else "even" return "%s string on %s width centered incorrectly." % (string, width) self.assertEquals(center_text("AAAA", 11), " AAAA ".rstrip(), msg=error_msg(True, False)) self.assertEquals(center_text("AAA", 11), " AAA ".rstrip(), msg=error_msg(False, False)) self.assertEquals(center_text("AA", 11), " AA ".rstrip(), msg=error_msg(True, False)) self.assertEquals(center_text("AAAA", 10), " AAAA ".rstrip(), msg=error_msg(True, True)) self.assertEquals(center_text("AAA", 10), " AAA ".rstrip(), msg=error_msg(False, True)) self.assertEquals(center_text("AA", 10), " AA ".rstrip(), msg=error_msg(True, True))
def test_multiple_lines_string(self): self.assertEquals(center_text("AAA\nBBBBB", 7), " AAA\n BBBBB")
def test_string_longer_than_width(self): self.assertEquals(center_text("#" * 10, 5), "#" * 10)
def test_empty_string(self): self.assertEquals(center_text("", 10), " " * 5)