Ejemplo n.º 1
0
 def test_04(self):
     # Arrange
     test = NewClass("test_class")
     # Act
     result = test.__str__()
     # Assert
     self.assertEqual(result, "test_class")
Ejemplo n.º 2
0
 def test_07(self):
     # Arrange
     test = NewClass("test_class")
     # Act
     test.add_attribute("attribute1 : String")
     result = test.attribute[-1]
     # Assert
     self.assertEqual(result, "attribute1 : String")
Ejemplo n.º 3
0
 def test_05(self):
     # Arrange
     test = NewClass("test_class")
     # Act
     test.add_method("do_stuff()")
     result = test.method[-1]
     # Assert
     self.assertEqual(result, "do_stuff()")
Ejemplo n.º 4
0
 def test_09(self):
     # Arrange
     test = NewClass("test_class")
     # Act
     test.add_relationship("class1 *-- class2")
     result = test.relationship[-1]
     # Assert
     self.assertEqual(result, "class1 *-- class2")
Ejemplo n.º 5
0
 def test_08(self):
     # Arrange
     test = NewClass("test_class")
     count = 0
     # Act
     while count <= 100:
         test.add_attribute("attribute" + str(count))
         count += 1
     # Assert
     self.assertEqual(test.attribute[0], "attribute0")
     self.assertEqual(test.attribute[-1], "attribute100")
Ejemplo n.º 6
0
 def test_06(self):
     # Arrange
     test = NewClass("test_class")
     count = 0
     # Act
     while count <= 100:
         test.add_method("do_stuff_" + str(count) + "()")
         count += 1
     # Assert
     self.assertEqual(test.method[0], "do_stuff_0()")
     self.assertEqual(test.method[-1], "do_stuff_100()")
Ejemplo n.º 7
0
    def find_class(self, file_data: str) -> None:
        assert type(
            file_data
        ) is str, "find_class method must take string as input parameter"
        list_of_letters = file_data.split()
        # Find total amount of words in the list
        total_letters = len(list_of_letters)

        # for each word in the list
        for i in range(total_letters):

            # Check if the before word is class
            if list_of_letters[i - 1] == "class":
                a_new_class = list_of_letters[i]
                a_new_class = NewClass(a_new_class)
                self.my_classes.append(a_new_class)

            # Add attributes
            elif ":" == list_of_letters[i]:
                if ("(" not in list_of_letters[i - 1]) and (
                        list_of_letters[i - 1][0].islower()):
                    attribute = list_of_letters[i - 1] + " " + list_of_letters[
                        i] + " " + list_of_letters[i + 1]
                    self.my_classes[-1].add_attribute(attribute)

            # Add methods
            elif "(" in list_of_letters[i]:
                part_of_method = ""
                for j in range(i, total_letters):
                    if ")" in list_of_letters[i]:
                        part_of_method += list_of_letters[i]
                        break
                    elif ")" in list_of_letters[j]:
                        part_of_method += (" " + list_of_letters[j])
                        if list_of_letters[j + 1] == ":":
                            part_of_method += list_of_letters[
                                j + 1] + " " + list_of_letters[j + 2]
                            break
                    elif "}" in list_of_letters[j]:
                        break
                    else:
                        part_of_method += " " + (list_of_letters[j])

                if list_of_letters[i + 1] == ":":
                    method = part_of_method + list_of_letters[
                        i + 1] + " " + list_of_letters[i + 2]
                else:
                    method = part_of_method
                self.my_classes[-1].add_method(method)
Ejemplo n.º 8
0
 def test_10(self):
     # Arrange
     test = NewClass("test_class")
     # Act
     test.add_relationship("class1 *-- class2")
     test.add_relationship("class1 o-- class3")
     test.add_relationship("class1 *-- class4")
     # Assert
     self.assertEqual(test.relationship[0], "class1 *-- class2")
     self.assertEqual(test.relationship[1], "class1 o-- class3")
     self.assertEqual(test.relationship[2], "class1 *-- class4")