Porting continues. svn/trunk
authorilb@NIH.GOV <ilb@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Wed, 25 Apr 2018 22:16:51 +0000 (22:16 +0000)
committerilb@NIH.GOV <ilb@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Wed, 25 Apr 2018 22:16:51 +0000 (22:16 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15459 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/gov/nih/mipav/model/algorithms/StochasticForests.java

index a4103a1..4169f76 100644 (file)
@@ -964,7 +964,7 @@ public class StochasticForests extends AlgorithmBase {
          // Draw without replacement using Fisher Yates algorithm\r
          Random random = new Random();\r
          for (i = 0; i < num_samples; ++i) {\r
-           j = (int)Math.round(i + random.nextDouble() * (max - skip.size() - i));\r
+           j = (int)(i + random.nextDouble() * (max - skip.size() - i));\r
            temp = result.get(i);\r
            result.set(i,result.get(j));\r
            result.set(j,temp);\r
@@ -1047,6 +1047,40 @@ public class StochasticForests extends AlgorithmBase {
                }       \r
        }\r
        \r
+       /**\r
+        * Returns the most frequent class index of a vector with counts for the classes. Returns a random class if counts are equal.\r
+        * @param class_count Vector with class counts\r
+        * @param random_number_generator Random number generator\r
+        * @return Most frequent class index. Out of range index if all 0.\r
+        */\r
+       private int mostFrequentClass(Vector<Integer> class_count) {\r
+         Vector<Integer> major_classes = new Vector<Integer>();\r
+\r
+       // Find maximum count\r
+         int max_count = 0;\r
+         for (int i = 0; i < class_count.size(); ++i) {\r
+           int count = class_count.get(i);\r
+           if (count > max_count) {\r
+             max_count = count;\r
+             major_classes.clear();\r
+             major_classes.add(i);\r
+           } else if (count == max_count) {\r
+             major_classes.add(i);\r
+           }\r
+         }\r
+\r
+         if (max_count == 0) {\r
+           return class_count.size();\r
+         } else if (major_classes.size() == 1) {\r
+           return major_classes.get(0);\r
+         } else {\r
+           // Choose randomly\r
+               Random random = new Random();\r
+           return major_classes.get(random.nextInt(major_classes.size()));\r
+         }\r
+       }\r
+\r
+       \r
        private double mostFrequentValue(HashMap<Double, Integer> class_count) {\r
                int i;\r
                int value;\r
@@ -1766,7 +1800,60 @@ public class StochasticForests extends AlgorithmBase {
          }\r
        }\r
 \r
+       /**\r
+        * Write a 2d vector to filestream. First the size of the first dim is written as size_t, then for all inner vectors the size and elements.\r
+        * @param vector Vector of vectors of type T to write to file.\r
+        * @param file ofstream object to write to.\r
+        */\r
+       private void saveDVector2D(Vector<Vector<Double>> vector, BufferedWriter bw) {\r
+         int i;\r
+         // Save length of first dim\r
+         int length = vector.size();\r
+         try {\r
+             bw.write(String.valueOf(length)+"\n");\r
+         }\r
+         catch (IOException e) {\r
+                 MipavUtil.displayError("IO exception on bw.write(String.valueOf(length))");\r
+                 return;\r
+         }\r
+\r
+         // Save outer vector\r
+         Vector<Double> inner_vector = new Vector<Double>();\r
+         for (i = 0; i < vector.size(); i++) {\r
+           // Save inner vector\r
+               inner_vector = vector.get(i);\r
+           saveDVector1D(inner_vector, bw);\r
+         }\r
+       }\r
+       \r
+       /**\r
+        * Read a 2d vector written by saveVector2D() from filestream.\r
+        * @param result Result vector of vectors with elements of type T.\r
+        * @param file ifstream object to read from.\r
+        */\r
+       private void readDVector2D(Vector<Vector<Double>> result, BufferedReader br) {\r
+         int i;\r
+         // Read length of first dim\r
+         int length;\r
+         String line;\r
+         try {\r
+          line = br.readLine();\r
+         }\r
+         catch (IOException e) {\r
+                 MipavUtil.displayError("IO exception on br.readLine()");\r
+                 return;\r
+         }\r
+         length = Integer.valueOf(line).intValue();\r
+         for (i = 0; i < length; i++) {\r
+             result.add(new Vector<Double>());  \r
+         }\r
 \r
+         // Read outer vector\r
+         for (i = 0; i < length; ++i) {\r
+           // Read inner vector\r
+           readDVector1D(result.get(i), br);\r
+         }\r
+       }\r
        \r
        private boolean equalVectorInteger(Vector<Integer> v1, Vector<Integer> v2, String str) {\r
                // v1 is true answer, v2 is test answer\r
@@ -1806,7 +1893,7 @@ public class StochasticForests extends AlgorithmBase {
                p1 = v1.get(i);\r
                p2 = v2.get(i);\r
                for (j = 0; j < p1.size(); j++) {\r
-                       if (p1.get(i) != p2.get(i)) {\r
+                       if (p1.get(j) != p2.get(j)) {\r
                                System.out.println("In " + str + " correct element " + i + "," + j + " is " + p1.get(j));\r
                                System.out.println("Actual test element at " + i + "," + j + " is " + p2.get(j));\r
                                return false;\r
@@ -1836,6 +1923,45 @@ public class StochasticForests extends AlgorithmBase {
            return true;\r
        }\r
        \r
+       private boolean equalVectorVectorDouble(Vector<Vector<Double>> v1, Vector<Vector<Double>> v2, String str) {\r
+               // v1 is true answer, v2 is test answer\r
+               int i, j;\r
+               Vector<Double> p1 = new Vector<Double>();\r
+               Vector<Double> p2 = new Vector<Double>();\r
+           if (v1.size() != v2.size()) {\r
+               System.out.println("In " + str + " correct size is " + v1.size());\r
+               System.out.println("Test size is " + v2.size());\r
+               return false;\r
+           }\r
+           for (i = 0; i < v1.size(); i++) {\r
+               if (v1.get(i).size() != v2.get(i).size()) {\r
+                       System.out.println("In " + str + " v1.get("+i+").size() is " + v1.get(i).size());\r
+                       System.out.println("Actual test element v2.get("+i+").size() is " + v2.get(i).size());\r
+                       return false;\r
+               }\r
+               p1 = v1.get(i);\r
+               p2 = v2.get(i);\r
+               for (j = 0; j < p1.size(); j++) {\r
+                       if (!p1.get(j).equals(p2.get(j))) {\r
+                               System.out.println("In " + str + " correct element " + i + "," + j + " is " + p1.get(j));\r
+                               System.out.println("Actual test element at " + i + "," + j + " is " + p2.get(j));\r
+                               return false;\r
+                       }\r
+                   }\r
+           }\r
+           System.out.println(str + " passed");\r
+           return true;\r
+       }\r
+       \r
+       private boolean expectNear(double val1, double val2, double error, String str) {\r
+               if ((val2 < val1 - error) || (val2 > val1 + error)) {\r
+                       System.out.println("In " + str + " " + val2 + " is more than " +\r
+                                  error + " away from expected " + val1);\r
+                       return false;\r
+               }\r
+               return true;\r
+       }\r
+       \r
        public StochasticForests() {\r
                \r
        }\r
@@ -1843,6 +1969,7 @@ public class StochasticForests extends AlgorithmBase {
 \r
        public void runAlgorithm() {\r
           if (testCode) {\r
+                  int i, j;\r
                   Vector<Integer>test = new Vector<Integer>();\r
                   // Split 0..9 in 1 part\r
                   String str = "Test equalSplit, onePart";\r
@@ -2031,7 +2158,7 @@ public class StochasticForests extends AlgorithmBase {
            Vector<Integer> expect2 = new Vector<Integer>();\r
            expect2.addAll(Arrays.asList(new Integer[]{7,8,9,10}));\r
            Vector<Integer> expect3 = new Vector<Integer>();\r
-           expect3.addAll(Arrays.asList(new Integer[]{11,121,3,14,15}));\r
+           expect3.addAll(Arrays.asList(new Integer[]{11,12,13,14,15}));\r
            Vector<Vector<Integer>> expectAll = new Vector<Vector<Integer>>();\r
            expectAll.add(expect1);\r
            expectAll.add(expect2);\r
@@ -2064,7 +2191,459 @@ public class StochasticForests extends AlgorithmBase {
                           return;\r
                   }\r
                   equalVectorVectorInteger(expectAll, testAll, str);\r
-                  return;\r
+                  \r
+                str = "Test readWrite2D, double1";\r
+                outfile = new File("testfile2d");\r
+            try {\r
+                    fw = new FileWriter(outfile);\r
+                }\r
+                catch (IOException e) {\r
+                        MipavUtil.displayError("IO exception on fw = new FileWriter(outfile)");\r
+                        return;\r
+                }\r
+         bw = new BufferedWriter(fw);\r
+         Vector<Double> Dexpect1 = new Vector<Double>();\r
+         Dexpect1.addAll(Arrays.asList(new Double[]{1.1,2.4,3.0,4.3,5.9,6.7}));\r
+         Vector<Double> Dexpect2 = new Vector<Double>();\r
+         Dexpect2.addAll(Arrays.asList(new Double[]{7.2,8.1,9.0,10.1}));\r
+         Vector<Double> Dexpect3 = new Vector<Double>();\r
+         Dexpect3.addAll(Arrays.asList(new Double[]{11.3,12.4,13.2,14.7,15.8}));\r
+         Vector<Vector<Double>> DexpectAll = new Vector<Vector<Double>>();\r
+         DexpectAll.add(Dexpect1);\r
+         DexpectAll.add(Dexpect2);\r
+         DexpectAll.add(Dexpect3);\r
+         saveDVector2D(DexpectAll, bw);\r
+         try {\r
+          bw.close();\r
+         }\r
+         catch (IOException e) {\r
+          MipavUtil.displayError("IO exception on bw.close()");\r
+          return;\r
+         }\r
+         \r
+\r
+            file = new File("testfile2d");\r
+            try {\r
+                infile = new BufferedReader(new FileReader(file));\r
+            }\r
+            catch (FileNotFoundException e) {\r
+                    MipavUtil.displayError("Could not find file testfile2d");\r
+                    return;\r
+            }\r
+            Vector<Vector<Double>> DtestAll = new Vector<Vector<Double>>();\r
+            readDVector2D(DtestAll, infile);\r
+            try {\r
+                    infile.close();\r
+            }\r
+            catch(IOException e) {\r
+                    MipavUtil.displayError("IO exception on infile.close()");\r
+                    return;\r
+            }\r
+            equalVectorVectorDouble(DexpectAll, DtestAll, str);\r
+            \r
+            str = "Test drawWithoutReplacementSkip, small_small1";\r
+            Vector<Integer>result = new Vector<Integer>();\r
+            Map<Integer, Integer> counts = new HashMap<Integer, Integer>();\r
+            int max = 9;\r
+            Vector<Integer> skip = new Vector<Integer>();\r
+            skip.add(7);\r
+            int num_samples = 4;\r
+            int num_replicates = 10000;\r
+            int expected_count = num_samples * num_replicates / max;\r
+            \r
+            for (i = 0; i < num_replicates; i++) {\r
+                result.clear();\r
+                drawWithoutReplacementSkip(result, max + 1, skip, num_samples);\r
+                for (j = 0; j < result.size(); j++) {\r
+                    int idx = result.get(j);\r
+                    if (counts.get(idx) == null) {\r
+                        counts.put(idx, 1);\r
+                    }\r
+                    else {\r
+                        counts.put(idx, counts.get(idx)+1);\r
+                    }\r
+                }\r
+            } \r
+            \r
+            // Check if counts are expected +-5%\r
+               Object values[] = counts.values().toArray();\r
+               boolean success = true;\r
+               boolean near;\r
+            for (i = 0; i < counts.size(); i++) {\r
+                int value = (int)values[i];\r
+                near = expectNear(expected_count, value, expected_count * 0.05, str);\r
+                if (!near) {\r
+                        success = false;\r
+                }\r
+            }\r
+            if (counts.get(skip.get(0)) != null) {\r
+                System.out.println("In " + str + " counts.get(skip.get(0)) = " + \r
+                            counts.get(skip.get(0)) + " instead of null for zero count");\r
+                success = false;\r
+            }\r
+            if (success) {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test drawWithoutReplacementSkip, small_small2";\r
+            result.clear();\r
+            counts.clear();\r
+            max = 9;\r
+            skip.clear();\r
+            skip.add(0);\r
+            num_samples = 4;\r
+            num_replicates = 10000;\r
+            expected_count = num_samples * num_replicates / max;\r
+            \r
+            for (i = 0; i < num_replicates; i++) {\r
+                result.clear();\r
+                drawWithoutReplacementSkip(result, max + 1, skip, num_samples);\r
+                for (j = 0; j < result.size(); j++) {\r
+                    int idx = result.get(j);\r
+                    if (counts.get(idx) == null) {\r
+                        counts.put(idx, 1);\r
+                    }\r
+                    else {\r
+                        counts.put(idx, counts.get(idx)+1);\r
+                    }\r
+                }\r
+            } \r
+            \r
+            // Check if counts are expected +-5%\r
+               values = counts.values().toArray();\r
+               success = true;\r
+            for (i = 0; i < counts.size(); i++) {\r
+                int value = (int)values[i];\r
+                near = expectNear(expected_count, value, expected_count * 0.05, str);\r
+                if (!near) {\r
+                        success = false;\r
+                }\r
+            }\r
+            if (counts.get(skip.get(0)) != null) {\r
+                System.out.println("In " + str + " counts.get(skip.get(0)) = " + \r
+                            counts.get(skip.get(0)) + " instead of null for zero count");\r
+                success = false;\r
+            }\r
+            if (success) {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test drawWithoutReplacementSkip, small_small3";\r
+            result.clear();\r
+            counts.clear();\r
+            max = 9;\r
+            skip.clear();\r
+            skip.add(9);\r
+            num_samples = 4;\r
+            num_replicates = 10000;\r
+            expected_count = num_samples * num_replicates / max;\r
+            \r
+            for (i = 0; i < num_replicates; i++) {\r
+                result.clear();\r
+                drawWithoutReplacementSkip(result, max + 1, skip, num_samples);\r
+                for (j = 0; j < result.size(); j++) {\r
+                    int idx = result.get(j);\r
+                    if (counts.get(idx) == null) {\r
+                        counts.put(idx, 1);\r
+                    }\r
+                    else {\r
+                        counts.put(idx, counts.get(idx)+1);\r
+                    }\r
+                }\r
+            } \r
+            \r
+            // Check if counts are expected +-5%\r
+               values = counts.values().toArray();\r
+               success = true;\r
+            for (i = 0; i < counts.size(); i++) {\r
+                int value = (int)values[i];\r
+                near = expectNear(expected_count, value, expected_count * 0.05, str);\r
+                if (!near) {\r
+                        success = false;\r
+                }\r
+            }\r
+            if (counts.get(skip.get(0)) != null) {\r
+                System.out.println("In " + str + " counts.get(skip.get(0)) = " + \r
+                            counts.get(skip.get(0)) + " instead of null for zero count");\r
+                success = false;\r
+            }\r
+            if (success) {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test drawWithoutReplacementSkip, small_large1";\r
+            result.clear();\r
+            counts.clear();\r
+            max = 1000;\r
+            skip.clear();\r
+            skip.add(7);\r
+            num_samples = 50;\r
+            num_replicates = 100000;\r
+            expected_count = num_samples * num_replicates / max;\r
+            \r
+            for (i = 0; i < num_replicates; i++) {\r
+                result.clear();\r
+                drawWithoutReplacementSkip(result, max + 1, skip, num_samples);\r
+                for (j = 0; j < result.size(); j++) {\r
+                    int idx = result.get(j);\r
+                    if (counts.get(idx) == null) {\r
+                        counts.put(idx, 1);\r
+                    }\r
+                    else {\r
+                        counts.put(idx, counts.get(idx)+1);\r
+                    }\r
+                }\r
+            } \r
+            \r
+            // Check if counts are expected +-10%\r
+               values = counts.values().toArray();\r
+               success = true;\r
+            for (i = 0; i < counts.size(); i++) {\r
+                int value = (int)values[i];\r
+                near = expectNear(expected_count, value, expected_count * 0.1, str);\r
+                if (!near) {\r
+                        success = false;\r
+                }\r
+            }\r
+            if (counts.get(skip.get(0)) != null) {\r
+                System.out.println("In " + str + " counts.get(skip.get(0)) = " + \r
+                            counts.get(skip.get(0)) + " instead of null for zero count");\r
+                success = false;\r
+            }\r
+            if (success) {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test drawWithoutReplacementSkip, large_large1";\r
+            result.clear();\r
+            counts.clear();\r
+            max = 1000;\r
+            skip.clear();\r
+            skip.add(7);\r
+            num_samples = 500;\r
+            num_replicates = 10000;\r
+            expected_count = num_samples * num_replicates / max;\r
+            \r
+            for (i = 0; i < num_replicates; i++) {\r
+                result.clear();\r
+                drawWithoutReplacementSkip(result, max + 1, skip, num_samples);\r
+                for (j = 0; j < result.size(); j++) {\r
+                    int idx = result.get(j);\r
+                    if (counts.get(idx) == null) {\r
+                        counts.put(idx, 1);\r
+                    }\r
+                    else {\r
+                        counts.put(idx, counts.get(idx)+1);\r
+                    }\r
+                }\r
+            } \r
+            \r
+            // Check if counts are expected +- 5%\r
+               values = counts.values().toArray();\r
+               success = true;\r
+            for (i = 0; i < counts.size(); i++) {\r
+                int value = (int)values[i];\r
+                near = expectNear(expected_count, value, expected_count * 0.05, str);\r
+                if (!near) {\r
+                        success = false;\r
+                }\r
+            }\r
+            if (counts.get(skip.get(0)) != null) {\r
+                System.out.println("In " + str + " counts.get(skip.get(0)) = " + \r
+                            counts.get(skip.get(0)) + " instead of null for zero count");\r
+                success = false;\r
+            }\r
+            if (success) {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test mostFrequentClassCount, notEqual1";\r
+            Vector<Integer>class_count = new Vector<Integer>();\r
+            class_count.addAll(Arrays.asList(new Integer[]{0,4,7,3,2,1,8}));\r
+            int ans = mostFrequentClass(class_count);\r
+            if (ans != 6) {\r
+                System.out.println("In " + str + " answer = " + ans + " instead of the correct 6");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test mostFrequentClassCount, notEqual2";\r
+            class_count.clear();\r
+            class_count.addAll(Arrays.asList(new Integer[]{5,4,3,2,1}));\r
+            ans = mostFrequentClass(class_count);\r
+            if (ans != 0) {\r
+                System.out.println("In " + str + " answer = " + ans + " instead of the correct 0");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test mostFrequentClassCount, equal1";\r
+            class_count.clear();\r
+            class_count.addAll(Arrays.asList(new Integer[]{5,5,5,5}));\r
+            ans = mostFrequentClass(class_count);\r
+            if ((ans < 0) || (ans > 3)) {\r
+                System.out.println("In " + str + " answer = " + ans + " instead of the correct 0 to 3");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test mostFrequentClassCount, equal2";\r
+            class_count.clear();\r
+            class_count.addAll(Arrays.asList(new Integer[]{4,5,5,4}));\r
+            ans = mostFrequentClass(class_count);\r
+            if ((ans < 1) || (ans > 2)) {\r
+                System.out.println("In " + str + " answer = " + ans + " instead of the correct 1 to 2");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test mostFrequentValue, notEqual1";\r
+            HashMap <Double, Integer> class_count2 = new HashMap<Double, Integer>();\r
+            class_count2.put(1.0,5);\r
+            class_count2.put(2.0,7);\r
+            class_count2.put(3.0,10);\r
+            double dans = mostFrequentValue(class_count2);\r
+            if (dans != 3.0) {\r
+                System.out.println("In " + str + " answer = " + dans + " instead of the correct 3.0");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test mostFrequentValue, notEqual2";\r
+            class_count2.clear();\r
+            class_count2.put(10.1,15);\r
+            class_count2.put(2.5,12);\r
+            class_count2.put(30.0,10);\r
+            dans = mostFrequentValue(class_count2);\r
+            if (dans != 10.1) {\r
+                System.out.println("In " + str + " answer = " + dans + " instead of the correct 10.1");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test mostFrequentValue, equal1";\r
+            class_count2.clear();\r
+            class_count2.put(1.0,10);\r
+            class_count2.put(2.0,15);\r
+            class_count2.put(3.0,15);\r
+            dans = mostFrequentValue(class_count2);\r
+            if ((dans != 2.0) && (dans != 3.0)) {\r
+                System.out.println("In " + str + " answer = " + dans + " instead of the correct 2.0 or 3.0");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test mostFrequentValue, equal2";\r
+            class_count2.clear();\r
+            class_count2.put(10.0,30);\r
+            class_count2.put(11.0,30);\r
+            class_count2.put(15.0,29);\r
+            dans = mostFrequentValue(class_count2);\r
+            if ((dans != 10.0) && (dans != 11.0)) {\r
+                System.out.println("In " + str + " answer = " + dans + " instead of the correct 10.0 or 11.0");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "Test mostFrequentValue, equal3";\r
+            class_count2.clear();\r
+            class_count2.put(3.0,10);\r
+            class_count2.put(5.0,500);\r
+            class_count2.put(6.0,500);\r
+            dans = mostFrequentValue(class_count2);\r
+            if ((dans != 5.0) && (dans != 6.0)) {\r
+                System.out.println("In " + str + " answer = " + dans + " instead of the correct 5.0 or 6.0");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "test beautifyTime, seconds1";\r
+            String res = beautifyTime(0);\r
+            if (!res.equals("0 seconds")) {\r
+                System.out.println("In " + str + " answer = " + res + " instead of the correct 0 seconds");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "test beautifyTime, seconds2";\r
+            res = beautifyTime(30);\r
+            if (!res.equals("30 seconds")) {\r
+                System.out.println("In " + str + " answer = " + res + " instead of the correct 30 seconds");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "test beautifyTime, minutes1";\r
+            res = beautifyTime(60);\r
+            if (!res.equals("1 minute, 0 seconds")) {\r
+                System.out.println("In " + str + " answer = " + res + \r
+                                " instead of the correct 1 minute, 0 seconds");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "test beautifyTime, minutes2";\r
+            res = beautifyTime(2317);\r
+            if (!res.equals("38 minutes, 37 seconds")) {\r
+                System.out.println("In " + str + " answer = " + res + \r
+                                " instead of the correct 38 minutes, 37 seconds");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "test beautifyTime, hours1";\r
+            res = beautifyTime(3600);\r
+            if (!res.equals("1 hour, 0 minutes, 0 seconds")) {\r
+                System.out.println("In " + str + " answer = " + res + \r
+                                " instead of the correct 1 hour, 0 minutes, 0 seconds");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "test beautifyTime, hours2";\r
+            res = beautifyTime(13498);\r
+            if (!res.equals("3 hours, 44 minutes, 58 seconds")) {\r
+                System.out.println("In " + str + " answer = " + res + \r
+                                " instead of the correct 3 hours, 44 minutes, 58 seconds");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "test beautifyTime, days1";\r
+            res = beautifyTime(86400);\r
+            if (!res.equals("1 day, 0 hours, 0 minutes, 0 seconds")) {\r
+                System.out.println("In " + str + " answer = " + res + \r
+                                " instead of the correct 1 day, 0 hours, 0 minutes, 0 seconds");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+            \r
+            str = "test beautifyTime, days2";\r
+            res = beautifyTime(287345);\r
+            if (!res.equals("3 days, 7 hours, 49 minutes, 5 seconds")) {\r
+                System.out.println("In " + str + " answer = " + res + \r
+                                " instead of the correct 3 days, 7 hours, 49 minutes, 5 seconds");\r
+            }\r
+            else {\r
+                System.out.println(str + " passed");\r
+            }\r
+                return;\r
           }\r
        }\r
 }
\ No newline at end of file