From 79bc4dbfe2992db9602547d9212cbc769a08d6a6 Mon Sep 17 00:00:00 2001
From: koen <koenwermer@gmail.com>
Date: Sat, 28 Jan 2017 01:09:58 +0100
Subject: [PATCH] small fixes in helperfunctions and test programs

---
 .../Mutants/Stack_bool_is_result.java         |  4 ++--
 .../Stack_constructor_duplication.java        |  4 ++--
 .../Mutants/Stack_useless_property.java       |  4 ++--
 Equivalent mutations/Stack.java               | 22 +++++++++----------
 HelperFunctions.hs                            |  2 ++
 Main.hs                                       |  2 +-
 6 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/Equivalent mutations/Mutants/Stack_bool_is_result.java b/Equivalent mutations/Mutants/Stack_bool_is_result.java
index d40fff2..89a8d19 100644
--- a/Equivalent mutations/Mutants/Stack_bool_is_result.java	
+++ b/Equivalent mutations/Mutants/Stack_bool_is_result.java	
@@ -90,7 +90,7 @@ class Program
     }
     public Object Pop()
     {
-        if (isEmpty())
+        if (this.isEmpty())
         {
             System.out.println("Stack is empty!");
             return "No elements";
@@ -103,7 +103,7 @@ class Program
         }
         public Object Peek()
         {
-            if (isEmpty())
+            if (this.isEmpty())
             {
                 System.out.println("Stack is empty!");
             return "No elements";
diff --git a/Equivalent mutations/Mutants/Stack_constructor_duplication.java b/Equivalent mutations/Mutants/Stack_constructor_duplication.java
index 151eb58..04c4580 100644
--- a/Equivalent mutations/Mutants/Stack_constructor_duplication.java	
+++ b/Equivalent mutations/Mutants/Stack_constructor_duplication.java	
@@ -90,7 +90,7 @@ class Program
     }
     public Object Pop()
     {
-        if (isEmpty())
+        if (this.isEmpty())
         {
             System.out.println("Stack is empty!");
             return "No elements";
@@ -103,7 +103,7 @@ class Program
         }
         public Object Peek()
         {
-            if (isEmpty())
+            if (this.isEmpty())
             {
                 System.out.println("Stack is empty!");
             return "No elements";
diff --git a/Equivalent mutations/Mutants/Stack_useless_property.java b/Equivalent mutations/Mutants/Stack_useless_property.java
index 9a37ee6..5c87186 100644
--- a/Equivalent mutations/Mutants/Stack_useless_property.java	
+++ b/Equivalent mutations/Mutants/Stack_useless_property.java	
@@ -90,7 +90,7 @@ class Program
     }
     public Object Pop()
     {
-        if (isEmpty())
+        if (this.isEmpty())
         {
             System.out.println("Stack is empty!");
             return "No elements";
@@ -103,7 +103,7 @@ class Program
         }
         public Object Peek()
         {
-            if (isEmpty())
+            if (this.isEmpty())
             {
                 System.out.println("Stack is empty!");
             return "No elements";
diff --git a/Equivalent mutations/Stack.java b/Equivalent mutations/Stack.java
index d67d9f1..cfbd486 100644
--- a/Equivalent mutations/Stack.java	
+++ b/Equivalent mutations/Stack.java	
@@ -88,27 +88,27 @@ class Program
  
             	this.item[++this.top] = element;
                 System.out.println("Item pushed successfully!");
+            }
         }
-    }
-    public Object Pop()
-    {
-        if (isEmpty())
+        
+        public Object Pop()
         {
-            System.out.println("Stack is empty!");
-            return "No elements";
+            if (this.isEmpty())
+            {
+                System.out.println("Stack is empty!");
+                return "No elements";
             }
             else
             {
- 
                 return this.item[this.top--];
             }
         }
         public Object Peek()
         {
-            if (isEmpty())
+            if (this.isEmpty())
             {
                 System.out.println("Stack is empty!");
-            return "No elements";
+                return "No elements";
             }
             else
             {
@@ -123,6 +123,6 @@ class Program
             {
  
                 System.out.printf("Item {0}: {1}", (i + 1), this.item[i]);
-        }
-    }
+            }
+        }   
 }
diff --git a/HelperFunctions.hs b/HelperFunctions.hs
index dbdacb7..b380bfe 100644
--- a/HelperFunctions.hs
+++ b/HelperFunctions.hs
@@ -110,6 +110,7 @@ getMethod' classTypeDecls methodId = case (concatMap searchClass classTypeDecls)
                                         []      -> Nothing -- Library function call
   where
     searchClass (ClassTypeDecl (ClassDecl _ _ _ _ _ (ClassBody decls))) = searchDecls decls
+    searchClass _ = []
     searchDecls (MemberDecl (MethodDecl _ _ t id params _ (MethodBody (Just b))):_) | methodId == id = [(StmtBlock b, t, params)]
     searchDecls (MemberDecl (ConstructorDecl _ _ id params _ (ConstructorBody _ b)):_) | methodId == toConstrId id = [(StmtBlock (Block b), Just (RefType (ClassRefType (ClassType [(id, [])]))), params)]
     searchDecls (_:decls) = searchDecls decls
@@ -125,6 +126,7 @@ getMainMethod classTypeDecls = fromJust' "getMainMethod" $ getMethod classTypeDe
 getMethodIds :: [TypeDecl] -> [Ident]
 getMethodIds classTypeDecls = concatMap searchClass classTypeDecls where
     searchClass (ClassTypeDecl (ClassDecl _ _ _ _ _ (ClassBody decls))) = searchDecls decls
+    searchClass _ = []
     searchDecls (MemberDecl (MethodDecl _ _ _ id _ _ _):decls) = id : searchDecls decls
     searchDecls (_:decls) = searchDecls decls
     searchDecls [] = []
diff --git a/Main.hs b/Main.hs
index 76d20b4..6ee3314 100644
--- a/Main.hs
+++ b/Main.hs
@@ -102,7 +102,7 @@ getPostCond t = case parser Language.Java.Parser.exp postCond' of
 -- Calculate the wlp (for testing purposes)
 calcWlp :: IO ()
 calcWlp = do
-    source <- readFile (joinPath ["Equivalent mutations", "BST.java"]) -- sourcePath
+    source <- readFile (joinPath ["Equivalent mutations", "stack.java"]) -- sourcePath
     
     let result = parser compilationUnit source
     
-- 
GitLab