Exemplo n.º 1
0
    def test_add_multi_01(self):
        sj = StringJoiner(prefix="[", suffix="]")
        sj.add_multi(1, 2, 3, "e4")

        self.assertEqual("[1,2,3,e4]", str(sj))

        expected__repr__ = '{"separator": ",", "prefix": "[", "suffix": "]", ' \
                           '"nelem": 4, "str_length": 10, "elements": ["1", "2", "3", "e4"]}'
        self.assertEqual(expected__repr__, repr(sj))
Exemplo n.º 2
0
    def test_adding_two_sj_01(self):
        sj1 = StringJoiner()
        sj2 = StringJoiner(prefix="(", suffix=")")

        sj1.add_multi("sj1_e1", "sj1_e2")
        sj2.add_multi("sj2_e1", "sj2_e2")

        sj1_2 = sj1 + sj2  # the sum is not cumulative. You get a different results if you change the order.
        self.assertEqual('sj1_e1,sj1_e2,sj2_e1,sj2_e2', str(sj1_2))

        sj2_1 = sj2 + sj1
        self.assertEqual('(sj2_e1,sj2_e2,sj1_e1,sj1_e2)', str(sj2_1))

        self.assertEqual('sj1_e1,sj1_e2', str(sj1))
        self.assertEqual('(sj2_e1,sj2_e2)', str(sj2))
Exemplo n.º 3
0
    def test_subtract_two_sj_01(self):
        sj1 = StringJoiner()
        sj1.add_multi("e1", "e2", "e3")

        sj2 = StringJoiner()
        sj2.add_multi("e2", "e3", "e4")

        sj1_2 = sj1 - sj2
        self.assertEqual("e1", str(sj1_2))
        expected__repr__ = '{"separator": ",", "prefix": "", "suffix": "", ' \
                           '"nelem": 1, "str_length": 2, "elements": ["e1"]}'
        self.assertEqual(expected__repr__, repr(sj1_2))

        sj2_1 = sj2 - sj1
        self.assertEqual("e4", str(sj2_1))
        expected__repr__ = '{"separator": ",", "prefix": "", "suffix": "", ' \
                           '"nelem": 1, "str_length": 2, "elements": ["e4"]}'
        self.assertEqual(expected__repr__, repr(sj2_1))