Mercurial > dive4elements > river
comparison backend/src/main/java/org/dive4elements/river/backend/utils/StringUtil.java @ 8855:d7c005e12af0 3.2.x
Remove unused test code.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 18 Jan 2018 20:10:59 +0100 |
parents | 3bb1c62ad732 |
children | 5e38e2924c07 |
comparison
equal
deleted
inserted
replaced
8846:6a4bdcccfa4d | 8855:d7c005e12af0 |
---|---|
685 pw.flush(); | 685 pw.flush(); |
686 return sw.toString(); | 686 return sw.toString(); |
687 } | 687 } |
688 | 688 |
689 | 689 |
690 public static void testQuote() { | |
691 System.err.println("testing quote:"); | |
692 | |
693 String cases [] = { | |
694 "", "''", | |
695 "test", "test", | |
696 "test test", "'test test'", | |
697 " test", "' test'", | |
698 "test ", "'test '", | |
699 " test ", "' test '", | |
700 "'test", "'\\'test'", | |
701 "'", "'\\''", | |
702 " ' ' ", "' \\' \\' '", | |
703 "te'st", "'te\\'st'" | |
704 }; | |
705 | |
706 int failed = 0; | |
707 | |
708 for (int i = 0; i < cases.length; i += 2) { | |
709 String in = cases[i]; | |
710 String out = cases[i+1]; | |
711 | |
712 String res = quote(in, '\''); | |
713 if (!res.equals(out)) { | |
714 ++failed; | |
715 System.err.println( | |
716 "quote failed on: >" + in + | |
717 "< result: >" + res + | |
718 "< expected: >" + out + "<"); | |
719 } | |
720 } | |
721 | |
722 int T = cases.length/2; | |
723 | |
724 System.err.println("tests total: " + T); | |
725 System.err.println("tests failed: " + failed); | |
726 System.err.println("tests passed: " + (T - failed)); | |
727 } | |
728 | |
729 public static void testQuoteReplacement() { | |
730 System.err.println("testing quoteReplacement:"); | |
731 | |
732 String cases [] = { | |
733 "", "", | |
734 "test", "test", | |
735 "$", "\\$", | |
736 "\\", "\\\\", | |
737 "\\$", "\\\\\\$", | |
738 "test\\$", "test\\\\\\$", | |
739 "\\test", "\\\\test", | |
740 "test$", "test\\$", | |
741 "test$test", "test\\$test", | |
742 "$test$", "\\$test\\$" | |
743 }; | |
744 | |
745 int failed = 0; | |
746 | |
747 for (int i = 0; i < cases.length; i += 2) { | |
748 String in = cases[i]; | |
749 String out = cases[i+1]; | |
750 | |
751 String res = quoteReplacement(in); | |
752 if (!res.equals(out)) { | |
753 ++failed; | |
754 System.err.println( | |
755 "quoteReplacement failed on: '" + in + | |
756 "' result: '" + res + | |
757 "' expected: '" + out + "'"); | |
758 } | |
759 } | |
760 | |
761 int T = cases.length/2; | |
762 | |
763 System.err.println("tests total: " + T); | |
764 System.err.println("tests failed: " + failed); | |
765 System.err.println("tests passed: " + (T - failed)); | |
766 } | |
767 | |
768 public static void testStringArray2D() { | |
769 int total = 0; | |
770 int fail = 0; | |
771 int passed = 0; | |
772 | |
773 System.err.println("testing StringArray2D:"); | |
774 | |
775 double[][] testarray = {{1.0, 2.0, 3.0}, | |
776 {1.1, 2.1, 3.1}, | |
777 {100.2, 200.2} | |
778 }; | |
779 String str = double2DArrayToString(testarray); | |
780 | |
781 total += 1; | |
782 if (str.equals("1.0;2.0;3.0:1.1;2.1;3.1:100.2;200.2")) { | |
783 passed +=1; | |
784 } | |
785 else { | |
786 fail +=1; | |
787 System.err.println("Der Ergebnis-String ist nicht richtig:"); | |
788 System.err.println(str); | |
789 } | |
790 | |
791 | |
792 | |
793 double[][] testarray2 = stringToDouble2DArray(str); | |
794 boolean failed = false; | |
795 | |
796 total +=1; | |
797 for (int i=0; i < testarray.length; i++) | |
798 for (int j=0; j < testarray[i].length; j++) | |
799 if (testarray[i][j] != testarray2[i][j]) { | |
800 System.err.println("Test scheitert bei i=" +i +" j=" +j); | |
801 System.err.println("alter Wert=" + testarray[i][j] +" neuer Wert=" +testarray2[i][j]); | |
802 failed = true; | |
803 } | |
804 if (failed) { | |
805 fail +=1; | |
806 } | |
807 else { | |
808 passed +=1; | |
809 } | |
810 System.err.println("tests total: "+ total); | |
811 System.err.println("tests failed: "+ fail); | |
812 System.err.println("tests passed: "+ passed); | |
813 } | |
814 | |
815 public static void main(String [] args) { | |
816 | |
817 testQuoteReplacement(); | |
818 testQuote(); | |
819 testStringArray2D(); | |
820 } | |
821 | |
822 /** Check for occurence of needle in hay, converting both to lowercase | 690 /** Check for occurence of needle in hay, converting both to lowercase |
823 * to be ignorant of cases. */ | 691 * to be ignorant of cases. */ |
824 public static boolean containsIgnoreCase(String hay, String needle) { | 692 public static boolean containsIgnoreCase(String hay, String needle) { |
825 return hay.toLowerCase().contains(needle.toLowerCase()); | 693 return hay.toLowerCase().contains(needle.toLowerCase()); |
826 } | 694 } |