Exemple #1
0
    def test_convert_for(self):
        """Test case for Java.convert_for"""

        # Create test set
        test_set = [("int i", "0", "10", "1", None),
                    ("String var", "0", "10", "2", None),
                    ("int var", "3", "30", "1", None),
                    ("int j", "2", "20", "2", None),
                    ("float arr_item", "0", "Array.length", "1", "my_array")]

        # Create expected results test set
        res_set = [
            "for (int i = 0; i < 10; i++) {",
            "for (String var = 0; var < 10; var += 2) {",
            "for (int var = 3; var < 30; var++) {",
            "for (int j = 2; j < 20; j += 2) {",
            "for (float arr_item: my_array) {"
        ]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().convert_for(*test_set[i]),
                             ([res_set[i]], ["}"]))
Exemple #2
0
    def test_is_while(self):
        """Test case for Java.is_while"""

        # Create test set
        test_set = [(self.file, 33), (self.file, 17), (self.file, 14)]

        # Create expected results test set
        res_set = [True, False, False]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().is_while(*test_set[i]), res_set[i])
Exemple #3
0
    def test_get_while_condition(self):
        """Test case for Java.get_while_condition"""

        # Create test set
        test_set = [(self.file, 33)]

        # Create expected results test set
        res_set = [("valid", [], [])]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().get_while_condition(*test_set[i]),
                             res_set[i])
Exemple #4
0
    def test_get_if_condition(self):
        """Test case for Java.get_if_condition"""

        # Create test set
        test_set = [(self.file, 10), (self.file, 14)]

        # Create expected results test set
        res_set = [("times < 0 && !accept_null", "if", [], []),
                   ("times == 10", "if", [], [])]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().get_if_condition(*test_set[i]), res_set[i])
Exemple #5
0
    def test_get_interface_definition(self):
        """Test case for Java.get_interface_definition"""

        # Create test set
        test_set = [(self.file, 3), (self.file, 5)]

        # Create expected results test set
        res_set = [("public static", "ParentIntr", [], [], []),
                   ("private", "MyIntr", ["ParentIntr"], [], [])]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().get_interface_definition(*test_set[i]),
                             res_set[i])
Exemple #6
0
    def test_parse_function_definition(self):
        """Test case for Java.parse_function_definition"""

        # Create test set
        test_set = [("public static void main", "String[] args) {"),
                    ("int count_occurrences", "File fp) {"),
                    ("private String[] my_func", ") {")]

        # Create expected results test set
        res_set = [("public static", "void", "main", [["args", "String[]"]]),
                   ("", "int", "count_occurrences", [["fp", "File"]]),
                   ("private", "String[]", "my_func", [])]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().parse_function_definition(*test_set[i]),
                             res_set[i])
Exemple #7
0
    def test_get_method_definition(self):
        """Test case for Java.get_method_definition"""

        # Create test set
        test_set = [(self.file, 9), (self.file, 21), (self.file, 27)]

        # Create expected results test set
        res_set = [
            ("public static", "int", "run_ext_func", [["times",
                                                       "int"]], [], []),
            ("", "void", "print_default_times", [], [], []),
            ("public static", "void", "main", [["args", "String[]"]], [], []),
        ]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().get_method_definition(*test_set[i]),
                             res_set[i])
Exemple #8
0
    def test_get_for_iterations(self):
        """Test case for Java.get_for_iterations"""

        # Create test set
        test_set = [(self.file, 17), (self.file, 22), (self.file, 28),
                    (self.file, 30), (self.file, 38)]

        # Create expected results test set
        res_set = [("int i", "0", "times", "1", None, [], []),
                   ("int i", "0", "10", "2", None, [], []),
                   ("int i", "2", "10", "1", None, [], []),
                   ("int j", "0", "-11", "-2", None, [], []),
                   ("int num", "0", "Array.length", "1", "my_arr", [], [])]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().get_for_iterations(*test_set[i]),
                             res_set[i])
Exemple #9
0
    def test_convert_if(self):
        """Test case for Java.convert_if"""

        # Create test set
        test_set = [
            "name && uid || reg_no && !invalid && !(time > expired)",
            "&&_text && ||_text || u!_text && &&&&&&&&&||&& || |||!||"
        ]

        # Create expected results test set
        res_set = [
            "if (name && uid || reg_no && !invalid && !(time > expired)) {",
            "if (&&_text && ||_text || u!_text && &&&&&&&&&||&& || |||!||) {"
        ]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().convert_if(test_set[i], "if"),
                             ([res_set[i]], ["}"]))
Exemple #10
0
    def test_convert_interface(self):
        """Test case for Java.convert_interface"""

        # Create test set
        test_set = [("public", "MyIntr", ["ParentIntr"]),
                    ("private static", "ParentIntr", []),
                    ("", "ChildIntr", ["MyIntr", "ParentIntr"])]

        # Create expected results test set
        res_set = [
            "public interface MyIntr extends ParentIntr {",
            "private static interface ParentIntr {",
            "interface ChildIntr extends MyIntr, ParentIntr {"
        ]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().convert_interface(*test_set[i]),
                             ([res_set[i]], ["}"]))
Exemple #11
0
    def test_convert_function(self):
        """Test case for Java.convert_function"""

        # Create test set
        test_set = [("public static", "void", "main", [["args", "String[]"]]),
                    ("", "int", "count", [["file_name", "String"],
                                          ["kw", "String"]]),
                    ("private", "void", "print_data", [])]

        # Create expected results test set
        res_set = [[
            "class Outfile {", "    public static void main(String[] args) {"
        ], ["int count(String file_name, String kw) {"],
                   ["private void print_data() {"]]

        # Run test for all tests in test_set
        for i in range(len(test_set)):
            # Get number of closing brackets based on input
            end = ["}"] * (len(res_set[i]) if type(res_set[i]) == list else 1)

            # Test function with inputs and expected outputs
            self.assertEqual(Java().convert_function(*test_set[i]),
                             (res_set[i], end))
Exemple #12
0
    def test_convert_class(self):
        """Test case for Java.convert_class"""

        # Create test set
        test_set = [
            ("public final", "MasterClass", [], []),
            ("private static", "ChildClass", ["MasterClass"], ["ParentIntr"]),
            ("", "SubClass", ["MasterClass"], ["ParentIntr", "ChildIntr"]),
        ]

        # Create expected results test set
        res_set = [
            "public final class MasterClass {",
            "private static class ChildClass extends MasterClass" +
            " implements ParentIntr {", "class SubClass extends MasterClass" +
            " implements ParentIntr, ChildIntr {"
        ]

        # Run test for all tests in test_set
        for i in range(len(test_set)):

            # Test function with inputs and expected outputs
            self.assertEqual(Java().convert_class(*test_set[i]),
                             ([res_set[i]], ["}"]))