From a52efdce63df0e56cf13d108c7e0c90b702b4fa4 Mon Sep 17 00:00:00 2001 From: MAC Date: Tue, 14 Mar 2017 22:06:15 +0800 Subject: [PATCH 01/28] week02 array util commit --- group26/89460886/src/week02/.DS_Store | Bin 0 -> 6148 bytes .../89460886/src/week02/source/ArrayUtil.java | 190 ++++++++++++++++++ .../src/week02/test/TestArrayUtil.java | 95 +++++++++ 3 files changed, 285 insertions(+) create mode 100644 group26/89460886/src/week02/.DS_Store create mode 100644 group26/89460886/src/week02/source/ArrayUtil.java create mode 100644 group26/89460886/src/week02/test/TestArrayUtil.java diff --git a/group26/89460886/src/week02/.DS_Store b/group26/89460886/src/week02/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 array2[arr2Index]) { + array3[arr3Index++] = array2[arr2Index++]; + } else { + array3[arr3Index++] = array1[arr1Index++] = array2[arr2Index++]; + zeroCount++; + } + } + while (arr1Index < len1) { + array3[arr3Index++] = array1[arr1Index++]; + } + while (arr2Index < len2) { + array3[arr3Index++] = array2[arr2Index++]; + } + return Arrays.copyOf(array3, len1 + len2 - zeroCount); + } + /** + * 把一个已经存满数据的数组 oldArray的容量进行扩展, 扩展后的新数据大小为oldArray.length + size + * 注意,老数组的元素在新数组中需要保持 + * 例如 oldArray = [2,3,6] , size = 3,则返回的新数组为 + * [2,3,6,0,0,0] + * @param oldArray + * @param size + * @return + */ + public int[] grow(int [] oldArray, int size){ + return Arrays.copyOf(oldArray, oldArray.length + size); + } + + /** + * 斐波那契数列为:1,1,2,3,5,8,13,21...... ,给定一个最大值, 返回小于该值的数列 + * 例如, max = 15 , 则返回的数组应该为 [1,1,2,3,5,8,13] + * max = 1, 则返回空数组 [] + * @param max + * @return + */ + public int[] fibonacci(int max){ + if (max == 1) return null; + int first = 1, second = 1; + int next = 2; + int[] result = new int[max]; + result[0] = first; result[1] = second; + int count = 2; + while (next < max) { + result[count++] = next; + first = second; + second = next; + next = first + second; + } + return Arrays.copyOf(result, count); + } + + /** + * 返回小于给定最大值max的所有素数数组 + * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19] + * @param max + * @return + */ + public int[] getPrimes(int max){ + if (max <= 2) return null; + int [] result = new int[max]; + int count = 0; + for (int i = 2; i < max; i++) { + if (!primes(i)) { + result[count++] = i; + } + } + return Arrays.copyOf(result, count); + } + + private boolean primes(int data) { + int sqrt = (int) Math.sqrt(data) + 1; + for (int i = 2; i < sqrt; i++) { + if (data % i == 0){ + return true; + } + } + return false; + } + + /** + * 所谓“完数”, 是指这个数恰好等于它的因子之和,例如6=1+2+3 + * 给定一个最大值max, 返回一个数组, 数组中是小于max 的所有完数 + * @param max + * @return + */ + public int[] getPerfectNumbers(int max){ + int[] result = new int[max - 2]; + int count = 0; + for (int i = 2; i < max; i++) { + if (perfectNumber(i)) + result[count++] = i; + } + return Arrays.copyOf(result, count); + } + + private boolean perfectNumber(int number) { + int left = 2, right = number; + int sum = 1; + while (left < right) { + if (number % left == 0) { + sum += left; + right = number / left; + if (left != right) sum += right; + } + left++; + } + return sum == number; + } + + /** + * 用separator 把数组 array给连接起来 + * 例如array= [3,8,9], seperator = "-" + * 则返回值为"3-8-9" + * @param array + * @param separator + * @return + */ + public String join(int[] array, String separator){ + if (array == null) return null; + StringBuilder result = new StringBuilder(); + result.append(array[0]); + for (int i = 1, len = array.length; i < len; i++) { + result.append(separator).append(array[i]); + } + return result.toString(); + } + +} diff --git a/group26/89460886/src/week02/test/TestArrayUtil.java b/group26/89460886/src/week02/test/TestArrayUtil.java new file mode 100644 index 0000000000..836d4366b8 --- /dev/null +++ b/group26/89460886/src/week02/test/TestArrayUtil.java @@ -0,0 +1,95 @@ +import coding.ArrayUtil; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author jiaxun + */ +public class TestArrayUtil { + + private ArrayUtil arrayUtil; + + @Before + public void setUp() { + arrayUtil = new ArrayUtil(); + } + + @After + public void tearDown() { + + } + + @Test + public void testReverseArrayOdd() { + int[] actualArray = {6, 2, 5, 8, 7}; + arrayUtil.reverseArray(actualArray); + int[] expectedArray = {7, 8, 5, 2, 6}; + Assert.assertArrayEquals(expectedArray, actualArray); + } + + @Test + public void testReverseArrayEven() { + int[] actualArray = {5, 3, 6, 7}; + arrayUtil.reverseArray(actualArray); + int[] expectedArray = {7, 6, 3, 5}; + Assert.assertArrayEquals(expectedArray, actualArray); + } + + @Test + public void testRemoveZero() { + int[] oldArray = {4, 5, 0, 7, 0, 3}; + int[] newArray = arrayUtil.removeZero(oldArray); + Assert.assertEquals(newArray.length, 4); + Assert.assertEquals(newArray[2], 7); + } + + @Test + public void testMerge() { + int[] array1 = {3, 5, 7,8}; + int[] array2 = {4, 5, 6,7}; + int[] array3 = arrayUtil.merge(array1, array2); + Assert.assertEquals(array3.length, 6); + int[] expectArray = {3, 4, 5, 6, 7, 8}; + Assert.assertArrayEquals(expectArray, array3); + } + + @Test + public void testGrow() { + int[] array = {2, 3, 6}; + int[] result = arrayUtil.grow(array, 3); + Assert.assertEquals(result.length, 6); + int[] expectedArray = {2, 3, 6, 0, 0, 0}; + Assert.assertArrayEquals(expectedArray, result); + } + + @Test + public void testFibonacci() { + int[] result = arrayUtil.fibonacci(15); + int[] expect = {1, 1, 2, 3, 5, 8, 13}; + Assert.assertArrayEquals(expect, result); + } + + @Test + public void testGetPerfectNumbers() { + int[] result = arrayUtil.getPerfectNumbers(500); + int[] expected = {6, 28, 496}; + Assert.assertArrayEquals(expected, result); + } + + @Test + public void testGetPrimes() { + int[] result = arrayUtil.getPrimes(23); + int[] expectedArray = {2, 3, 5, 7, 11, 13, 17, 19}; + Assert.assertArrayEquals(expectedArray, result); + } + + @Test + public void testJoin() { + int[] source = {3,8,9}; + String result = arrayUtil.join(source, "-"); + Assert.assertEquals("3-8-9", result); + } + +} From ff34f1fa57eaa9a4d981d821b74370f349824553 Mon Sep 17 00:00:00 2001 From: ajie9608 <1778842360@qq.com> Date: Wed, 15 Mar 2017 19:53:16 +0800 Subject: [PATCH 02/28] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- group26/1778842360/.gitignore | 2 - group26/1778842360/first heomework/.gitignore | 0 .../.settings/org.eclipse.jdt.core.prefs | 11 - .../1778842360/second homework/ArrayUtil.java | 239 ++++++++++++++++++ .../second homework/ArrayUtilTest.java | 71 ++++++ ...05\345\206\265\347\273\237\350\256\241.md" | 6 +- 6 files changed, 313 insertions(+), 16 deletions(-) delete mode 100644 group26/1778842360/.gitignore create mode 100644 group26/1778842360/first heomework/.gitignore delete mode 100644 group26/1778842360/first heomework/.settings/org.eclipse.jdt.core.prefs create mode 100644 group26/1778842360/second homework/ArrayUtil.java create mode 100644 group26/1778842360/second homework/ArrayUtilTest.java diff --git a/group26/1778842360/.gitignore b/group26/1778842360/.gitignore deleted file mode 100644 index 4f4c622218..0000000000 --- a/group26/1778842360/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/bin -/.project/.classpath \ No newline at end of file diff --git a/group26/1778842360/first heomework/.gitignore b/group26/1778842360/first heomework/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/group26/1778842360/first heomework/.settings/org.eclipse.jdt.core.prefs b/group26/1778842360/first heomework/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 7341ab1683..0000000000 --- a/group26/1778842360/first heomework/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7 diff --git a/group26/1778842360/second homework/ArrayUtil.java b/group26/1778842360/second homework/ArrayUtil.java new file mode 100644 index 0000000000..c9efeb2d0b --- /dev/null +++ b/group26/1778842360/second homework/ArrayUtil.java @@ -0,0 +1,239 @@ +package array; + +import java.util.Arrays; + +public class ArrayUtil { + /** + * 给定一个整形数组a , 对该数组的值进行置换 + 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] + 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7] + * @param origin + * @return + */ + public static void reverseArray(int[] origin){ + for(int i=0;iarray2[j]){ + array3[k++]=array2[j]; + j++; + } + else{ + array3[k++]=array1[i]; + i++; + j++; + } + } + while(i Date: Fri, 17 Mar 2017 13:12:15 +0800 Subject: [PATCH 03/28] =?UTF-8?q?=E5=AE=8C=E6=88=90ArrayUtils=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/week2/com/coding/basic/ArrayUtil.java | 280 ++++++++++++++++++ .../week2/com/coding/test/ArrayUtilTest.java | 89 ++++++ 2 files changed, 369 insertions(+) create mode 100644 group26/191191717/src/week2/com/coding/basic/ArrayUtil.java create mode 100644 group26/191191717/src/week2/com/coding/test/ArrayUtilTest.java diff --git a/group26/191191717/src/week2/com/coding/basic/ArrayUtil.java b/group26/191191717/src/week2/com/coding/basic/ArrayUtil.java new file mode 100644 index 0000000000..9bb9c18897 --- /dev/null +++ b/group26/191191717/src/week2/com/coding/basic/ArrayUtil.java @@ -0,0 +1,280 @@ +package week2.com.coding.basic; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +public class ArrayUtil +{ + + /** + * һa , Ըֵû 磺 a = [7, 9 , 30, 3] , ûΪ [3, 30, 9,7] a = [7, 9, 30, 3, 4] , ûΪ [4,3, 30 , 9,7] + * + * @param origin + * @return + */ + public void reverseArray(int[] origin) + { + int[] tempArrays = new int[origin.length]; + int j = 0; + for (int i = origin.length - 1; i > -1; i--) + { + tempArrays[j] = origin[i]; + j++; + } + } + + /** + * µһ飺 int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5} ҪֵΪ0ȥΪ0ֵһµ飬ɵΪ + * {1,3,4,5,6,6,5,4,7,6,7,5} + * + * @param oldArray + * @return + */ + + public int[] removeZero(int[] oldArray) + { + // ArrayListҪ֪ȣڴ˴ + List list = new ArrayList(); + for (int i = 0; i < oldArray.length; i++) + { + if (oldArray[i] != 0) + { + list.add(oldArray[i]); + } + } + int[] newArray = new int[list.size()]; + for (int i = 0; i < list.size(); i++) + { + newArray[i] = list.get(i); + } + return newArray; + + } + + /** + * Ѿõ飬 a1a2 , һµa3, ʹa3 a1a2 Ԫأ Ȼ a1 = [3, 5, 7,8] a2 = [4, 5, 6,7] a3 + * Ϊ[3,4,5,6,7,8] , ע⣺ Ѿظ + * + * @param array1 + * @param array2 + * @return + */ + + public int[] merge(int[] array1, int[] array2) + { + //Setϲظֵ + Set set = new HashSet(); + for (int i : array1) + { + set.add(i); + } + for (int i : array2) + { + set.add(i); + } + int[] newArr = new int[set.size()]; + Iterator it = set.iterator(); + int i = 0; + while (it.hasNext()) + { + newArr[i] = it.next(); + i++; + } + // newArrð + for (int j = 0; j < newArr.length - 1; j++) + { + for (int k = 0; k < newArr.length - 1 - j; k++) + { + int temp = 0; + if (newArr[k] > newArr[k + 1]) + { + temp = newArr[k]; + newArr[k + 1] = temp; + } + } + } + return newArr; + } + + /** + * һѾݵ oldArrayչ չݴСΪoldArray.length + size ע⣬ԪҪ oldArray = [2,3,6] , size = + * 3,򷵻صΪ [2,3,6,0,0,0] + * + * @param oldArray + * @param size + * @return + */ + public int[] grow(int[] oldArray, int size) + { + int[] newArray = Arrays.copyOf(oldArray, oldArray.length + size); + return newArray; + } + + /** + * 쳲Ϊ1123581321...... һֵ Сڸֵ 磬 max = 15 , 򷵻صӦΪ [11235813] max = 1, 򷵻ؿ [] + * + * @param max + * @return + */ + public int[] fibonacci(int max) + { + // f(n)=f(n-1)+f(n-2) + // f(0)=1 f(1)=1 f(2)=f(0)+f(1)=2 + List list = new ArrayList(); + int[] newArr = null; + if (max == 1) + return newArr; + int num = 0; + int x = 1, y = 1; + list.add(1);// f(0)=1; + list.add(1);// f(1)=1; + while (true) + { + num = x + y; + x = y; + y = num; + if (num >= max) + break; + list.add(num); + } + newArr = new int[list.size()]; + for (int k = 0; k < list.size(); k++) + { + newArr[k] = list.get(k); + } + return newArr; + } + + /** + * 쳲еĵݹ㷨 + * + * @param i + * @return + */ + public static int getFiboo(int i) + { + if (i == 1 || i == 2) + return 1; + else + return getFiboo(i - 1) + getFiboo(i - 2); + } + + /** + * Сڸֵmax max = 23, صΪ[2,3,5,7,11,13,17,19] + * + * @param max + * @return + */ + public int[] getPrimes(int max) + { + int[] newArr = null; + List list = new ArrayList(); + for (int i = 1; i < max; i++) + { + boolean flag = isPrime(i); + if (flag) + list.add(i); + } + newArr = new int[list.size()]; + for (int k = 0; k < list.size(); k++) + { + newArr[k] = list.get(k); + } + return newArr; + } + + public static boolean isPrime(int n) + { + if (n == 1) + return false; + if (n == 2) + return true; + if (n % 2 == 0) + return false;// ż϶ + for (int i = 3; i < n; i += 2)// ȥżж + { + if (n % i == 0) + return false; + } + return true; + } + + /** + * ν ָǡõ֮ͣ6=1+2+3 һֵmax һ飬 Сmax + * + * @param max + * @return + */ + public int[] getPerfectNumbers(int max) + { + List list = new ArrayList(); + List factorList = null; + for (int i = 1; i < max; i++) + { + // е + if (isPrime(i)) + { + continue; + } + factorList = getFactor(i); + int count = 0; + for (int j = 0; j < factorList.size(); j++) + { + count += factorList.get(j); + } + if (count != i) + continue; + list.add(i); + } + int[] newArr = new int[list.size()]; + for (int k = 0; k < list.size(); k++) + { + newArr[k] = list.get(k); + } + return newArr; + } + + /** + * һ + **/ + public static List getFactor(int number) + { + List list = new ArrayList(); + for (int i = 1; i < number; i++) + { + if (number % i != 0) + continue; + list.add(i); + } + return list; + } + + /** + * seperator array array= [3,8,9], seperator = "-" 򷵻ֵΪ"3-8-9" + * + * @param array + * @param s + * @return + */ + public String join(int[] array, String seperator) + { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < array.length; i++) + { + if (i == array.length - 1) + { + sb.append(array[i]); + break; + } + sb.append(array[i] + seperator); + } + return sb.toString(); + } + +} \ No newline at end of file diff --git a/group26/191191717/src/week2/com/coding/test/ArrayUtilTest.java b/group26/191191717/src/week2/com/coding/test/ArrayUtilTest.java new file mode 100644 index 0000000000..7ec1c88245 --- /dev/null +++ b/group26/191191717/src/week2/com/coding/test/ArrayUtilTest.java @@ -0,0 +1,89 @@ +package week2.com.coding.test; + +import static org.junit.Assert.*; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import week2.com.coding.basic.ArrayUtil; + +public class ArrayUtilTest +{ + private static ArrayUtil arrayUtil = null; + + @Before + public void init() + { + arrayUtil = new ArrayUtil(); + } + + @Test + public void testReverseArray() + { + int[] arrays = {7, 9, 30, 3}; + arrayUtil.reverseArray(arrays); + } + + @Test + public void testRemoveZero() + { + int oldArr[] = {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 0, 5}; + int newArr[] = {1, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 5}; + Assert.assertArrayEquals(newArr, arrayUtil.removeZero(oldArr)); + } + + @Test + public void testMerge() + { + int[] array1 = {3, 5, 7, 8}; + int[] array2 = {4, 5, 6, 7}; + int[] vaildateArr = {3, 4, 5, 6, 7, 8}; + int[] arrs = arrayUtil.merge(array1, array2); + Assert.assertArrayEquals(vaildateArr, arrs); + } + + @Test + public void testGrow() + { + int[] vaildateArr = {2, 3, 6, 0, 0, 0}; + int[] oldArr = {2, 3, 6}; + int[] arrs = arrayUtil.grow(oldArr, 3); + Assert.assertArrayEquals(vaildateArr, arrs); + + } + + @Test + public void testFibonacci() + { + int [] validateArr={1,1,2,3,5,8,13}; + int [] newArr=arrayUtil.fibonacci(15); + Assert.assertArrayEquals(validateArr, newArr); + } + + @Test + public void testGetPrimes() + { + int[] arrs = arrayUtil.getPrimes(23); + for (int i : arrs) + System.out.printf("%d ", i); + } + + @Test + public void testGetPerfectNumbers() + { + int [] validateArr={6,28};; + int [] newArr=arrayUtil.getPerfectNumbers(100); + Assert.assertArrayEquals(validateArr, newArr); + } + + @Test + public void testJoin() + { + String validateStr = "3-8-9"; + int[] oldArr = {3, 8, 9}; + String str = arrayUtil.join(oldArr, "-"); + Assert.assertEquals(validateStr, str); + } + +} From a619dc48aa862cfad49196568851e8e2ac2469fc Mon Sep 17 00:00:00 2001 From: luojunyi Date: Sat, 18 Mar 2017 23:22:42 +0800 Subject: [PATCH 04/28] Signed-off-by: luojunyi --- .../com/coding/litestruts/LoginAction.java | 52 ++++++ .../week2/com/coding/litestruts/Struts.java | 156 ++++++++++++++++++ .../com/coding/litestruts/StrutsTest.java | 41 +++++ .../src/week2/com/coding/litestruts/View.java | 23 +++ .../week2/com/coding/litestruts/struts.xml | 11 ++ 5 files changed, 283 insertions(+) create mode 100644 group26/191191717/src/week2/com/coding/litestruts/LoginAction.java create mode 100644 group26/191191717/src/week2/com/coding/litestruts/Struts.java create mode 100644 group26/191191717/src/week2/com/coding/litestruts/StrutsTest.java create mode 100644 group26/191191717/src/week2/com/coding/litestruts/View.java create mode 100644 group26/191191717/src/week2/com/coding/litestruts/struts.xml diff --git a/group26/191191717/src/week2/com/coding/litestruts/LoginAction.java b/group26/191191717/src/week2/com/coding/litestruts/LoginAction.java new file mode 100644 index 0000000000..a8bad2d7df --- /dev/null +++ b/group26/191191717/src/week2/com/coding/litestruts/LoginAction.java @@ -0,0 +1,52 @@ +package week2.com.coding.litestruts; + +/** + * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。 + * + * @author liuxin + * + */ +public class LoginAction +{ + private String name; + + private String password; + + private String message; + + public String getName() + { + return name; + } + + public String getPassword() + { + return password; + } + + public String execute() + { + if ("test".equals(name) && "1234".equals(password)) + { + this.message = "login successful"; + return "success"; + } + this.message = "login failed,please check your user/pwd"; + return "fail"; + } + + public void setName(String name) + { + this.name = name; + } + + public void setPassword(String password) + { + this.password = password; + } + + public String getMessage() + { + return this.message; + } +} diff --git a/group26/191191717/src/week2/com/coding/litestruts/Struts.java b/group26/191191717/src/week2/com/coding/litestruts/Struts.java new file mode 100644 index 0000000000..e9b902c518 --- /dev/null +++ b/group26/191191717/src/week2/com/coding/litestruts/Struts.java @@ -0,0 +1,156 @@ +package week2.com.coding.litestruts; + +import java.io.File; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +public class Struts +{ + + public static View runAction(String actionName, Map parameters) + { + + /* + * + * 0. 读取配置文件struts.xml + * + * 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象) 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 + * ("name"="test" , "password"="1234") , 那就应该调用 setName和setPassword方法 + * + * 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success" + * + * 3. 通过反射找到对象的所有getter方法(例如 getMessage), 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} , + * 放到View对象的parameters + * + * 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp, 放到View对象的jsp字段中。 + * + */ + File file = new File("src/week2/com/coding/litestruts/struts.xml"); + resolveXml(file); + Object object = actions.get(actionName); + Set set = parameters.keySet();// 获取键值 + Iterator it = set.iterator(); + View view = new View(); + try + { + while (it.hasNext()) + { + String keyName = it.next(); + String setMethodName = "set" + keyName.substring(0, 1).toUpperCase() + keyName.substring(1);// 组合方法名 + + Method method = object.getClass().getMethod(setMethodName, String.class); + if (method == null) + { + continue; + } + method.invoke(object, parameters.get(keyName));// 执行set方法 + } + + Method exeMethod = object.getClass().getMethod("execute"); + String result = (String)exeMethod.invoke(object);// 获取execute方法返回值 + // 获取对象所有的属性值 + Field[] fs = object.getClass().getDeclaredFields(); + HashMap resultMap = new HashMap(); + for (Field f : fs) + { + String fieldName = f.getName(); + Method m2 = object.getClass() + .getMethod("get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1)); + String rs2 = (String)m2.invoke(object); + // 将所有get方法的返回值存入map + resultMap.put(fieldName, rs2); + } + view.setParameters(resultMap); + // 根据result的值找到xml配置的值 + if (null != result) + { + String viewURL = (String)actions.get(actionName + "_" + result); + view.setJsp(viewURL); + } + } + catch (Exception e) + { + e.printStackTrace(); + } + return view; + } + + static Map actions = new HashMap(); + + /** + * 解析XML,将xml映射对象,以及返回值的属性存入actions + * + * @param file + */ + @SuppressWarnings("unchecked") + public static void resolveXml(File file) + { + SAXReader read = new SAXReader(); + Element rootElement = null; + try + { + rootElement = read.read(file).getRootElement(); + List actionList = rootElement.elements("action"); + for (Element ele : actionList) + { + String name = ele.attributeValue("name"); + String clz = ele.attributeValue("class");// 找到类名 + Object obj = Class.forName(clz).newInstance(); + actions.put(name, obj); + if (ele.hasContent())// 如果还有节点 + { + List list = ele.elements("result"); + for (Element e : list) + { + String cName = e.attributeValue("name"); + String cValue = e.getTextTrim(); + actions.put(name + "_" + cName, cValue);// 示例key:login_success + } + } + } + } + catch (DocumentException e) + { + e.printStackTrace(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public static void main(String[] args) + throws Exception + { + File file = new File("src/week2/com/coding/litestruts/struts.xml"); + resolveXml(file); + System.out.println(actions.toString()); + // Map parameters = new HashMap(); + // parameters.put("name", "luojunyi"); + // runAction("login", parameters); + // Class clazz = Class.forName("week2.com.coding.litestruts.LoginAction"); + // Object obj = clz.newInstance(); + // System.out.println(obj.toString()); + // Method m1 = clz.getMethod("setName", java.lang.String.class); + // System.out.println(m1.getName()); + // m1.invoke(obj, "hello"); + // Method m2 = clz.getMethod("getName"); + // System.out.println(m2.getName()); + // String s = (String)m2.invoke(obj); + // System.out.println(s); + // Field[] f = clazz.getDeclaredFields(); + // for (int i = 0; i < f.length; i++) + // { + // System.out.println(f[i].getName()); + // } + } +} diff --git a/group26/191191717/src/week2/com/coding/litestruts/StrutsTest.java b/group26/191191717/src/week2/com/coding/litestruts/StrutsTest.java new file mode 100644 index 0000000000..7f5125c107 --- /dev/null +++ b/group26/191191717/src/week2/com/coding/litestruts/StrutsTest.java @@ -0,0 +1,41 @@ +package week2.com.coding.litestruts; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +public class StrutsTest +{ + + @Test + public void testLoginActionSuccess() + { + + String actionName = "login"; + + Map params = new HashMap(); + params.put("name", "test"); + params.put("password", "1234"); + + View view = Struts.runAction(actionName, params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() + { + String actionName = "login"; + Map params = new HashMap(); + params.put("name", "test"); + params.put("password", "123456"); // //密码和预设的不一致 + + View view = Struts.runAction(actionName, params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} diff --git a/group26/191191717/src/week2/com/coding/litestruts/View.java b/group26/191191717/src/week2/com/coding/litestruts/View.java new file mode 100644 index 0000000000..3d0708b0c0 --- /dev/null +++ b/group26/191191717/src/week2/com/coding/litestruts/View.java @@ -0,0 +1,23 @@ +package week2.com.coding.litestruts; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} diff --git a/group26/191191717/src/week2/com/coding/litestruts/struts.xml b/group26/191191717/src/week2/com/coding/litestruts/struts.xml new file mode 100644 index 0000000000..d63e7651d8 --- /dev/null +++ b/group26/191191717/src/week2/com/coding/litestruts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + \ No newline at end of file From 8b380a075974a8e360284289e850f3c6a19d0dc7 Mon Sep 17 00:00:00 2001 From: MAC Date: Sun, 19 Mar 2017 08:45:05 +0800 Subject: [PATCH 05/28] week02 struts commit --- .../src/week02/source/struts/.DS_Store | Bin 0 -> 6148 bytes .../src/week02/source/struts/Action.java | 10 ++ .../src/week02/source/struts/Constants.java | 12 +++ .../src/week02/source/struts/DOMParser.java | 27 +++++ .../src/week02/source/struts/LoginAction.java | 48 +++++++++ .../week02/source/struts/LogoutAction.java | 7 ++ .../src/week02/source/struts/StringUtils.java | 12 +++ .../src/week02/source/struts/Struts.java | 92 ++++++++++++++++++ .../src/week02/source/struts/struts.xml | 11 +++ .../89460886/src/week02/test/TestStruct.java | 44 +++++++++ 10 files changed, 263 insertions(+) create mode 100644 group26/89460886/src/week02/source/struts/.DS_Store create mode 100644 group26/89460886/src/week02/source/struts/Action.java create mode 100644 group26/89460886/src/week02/source/struts/Constants.java create mode 100644 group26/89460886/src/week02/source/struts/DOMParser.java create mode 100644 group26/89460886/src/week02/source/struts/LoginAction.java create mode 100644 group26/89460886/src/week02/source/struts/LogoutAction.java create mode 100644 group26/89460886/src/week02/source/struts/StringUtils.java create mode 100644 group26/89460886/src/week02/source/struts/Struts.java create mode 100644 group26/89460886/src/week02/source/struts/struts.xml create mode 100644 group26/89460886/src/week02/test/TestStruct.java diff --git a/group26/89460886/src/week02/source/struts/.DS_Store b/group26/89460886/src/week02/source/struts/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 parameters) { + if (StringUtils.isEmpty(actionName)) return null; + DOMParser parser = new DOMParser(); + Document document = parser.parse("src/coding/coderising/litestruts/struts.xml"); + Element rootElement = document.getDocumentElement(); + + NodeList actionList = rootElement.getElementsByTagName("action"); + if (actionList == null || actionList.getLength() == 0) return null; + + for (int i = 0, len = actionList.getLength(); i < len; i++) { + Element element = (Element) actionList.item(i); + String name = element.getAttribute("name"); + if (actionName.equals(name)) { + return handleAction((Element) actionList.item(i), parameters); + } + } + return null; + } + + private static View handleAction(Element element, Map parameters) { + String className = element.getAttribute("class"); + try { + Class clazz = Class.forName(className); + Object object = clazz.newInstance(); + + for (Map.Entry entry : parameters.entrySet()) { + String methodStr = "set" + entry.getKey().toUpperCase().substring(0, 1) + + entry.getKey().substring(1); + Method method = clazz.getMethod(methodStr, String.class); + method.invoke(object, entry.getValue()); + } + + Method execute = clazz.getMethod("execute"); + String result = (String) execute.invoke(object); + + Map getParams = new HashMap<>(); + Field[] fields = clazz.getDeclaredFields(); + if (fields != null && fields.length > 0) { + for (int i = 0, len = fields.length; i < len; i++) { + PropertyDescriptor pd = new PropertyDescriptor(fields[i].getName(), clazz); + Method getMethod = pd.getReadMethod(); + if (getMethod != null) { + getParams.put(fields[i].getName(), (String) getMethod.invoke(object)); + } + } + } + + NodeList nodeList = element.getElementsByTagName("result"); + for (int i = 0; i < nodeList.getLength(); i++) { + Element resultElement = (Element) nodeList.item(i); + String name = resultElement.getAttribute("name"); + if ("success".equals(name) && Constants.ACTION_SUCCESS.equals(result)) { + return createView(resultElement, getParams); + } + if ("failure".equals(name) && Constants.ACTION_FAILURE.equals(result)) { + return createView(resultElement, getParams); + } + if ("error".equals(name) && Constants.ACTION_ERROR.equals(result)) { + return createView(resultElement, getParams); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private static View createView(Element element, Map parameters) { + View view = new View(); + view.setJsp(element.getTextContent()); + view.setParameters(parameters); + return view; + } + +} diff --git a/group26/89460886/src/week02/source/struts/struts.xml b/group26/89460886/src/week02/source/struts/struts.xml new file mode 100644 index 0000000000..811f2c9134 --- /dev/null +++ b/group26/89460886/src/week02/source/struts/struts.xml @@ -0,0 +1,11 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file diff --git a/group26/89460886/src/week02/test/TestStruct.java b/group26/89460886/src/week02/test/TestStruct.java new file mode 100644 index 0000000000..69d80d3642 --- /dev/null +++ b/group26/89460886/src/week02/test/TestStruct.java @@ -0,0 +1,44 @@ +package coding.coderising.litestruts; + +import list.Iterator; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author jiaxun + */ +public class TestStruct { + + @Test + public void testLoginActionSuccess() { + + String actionName = "login"; + + Map params = new HashMap<>(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //密码和预设的不一致 + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } + +} From 757181507aad739667674040bbce7546a4ef42c7 Mon Sep 17 00:00:00 2001 From: Memory-Cunese Date: Sun, 19 Mar 2017 18:16:13 +0800 Subject: [PATCH 06/28] Delete .classpath --- group26/1778842360/first heomework/.classpath | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 group26/1778842360/first heomework/.classpath diff --git a/group26/1778842360/first heomework/.classpath b/group26/1778842360/first heomework/.classpath deleted file mode 100644 index fb565a588d..0000000000 --- a/group26/1778842360/first heomework/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - From 5bae8d8e6cbd110bce8a8765ab7402eed7662503 Mon Sep 17 00:00:00 2001 From: Memory-Cunese Date: Sun, 19 Mar 2017 18:20:24 +0800 Subject: [PATCH 07/28] Delete .gitignore --- group26/1778842360/first heomework/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 group26/1778842360/first heomework/.gitignore diff --git a/group26/1778842360/first heomework/.gitignore b/group26/1778842360/first heomework/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 From 53897b1cbfe3d76ebee35949ae86cd70903a2901 Mon Sep 17 00:00:00 2001 From: Memory-Cunese Date: Sun, 19 Mar 2017 18:20:47 +0800 Subject: [PATCH 08/28] Delete .project --- group26/1778842360/first heomework/.project | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 group26/1778842360/first heomework/.project diff --git a/group26/1778842360/first heomework/.project b/group26/1778842360/first heomework/.project deleted file mode 100644 index 88536f7819..0000000000 --- a/group26/1778842360/first heomework/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - first heomework - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - From 36e35f91fba997cc2291f480be989acc3f228db0 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:11:15 +0800 Subject: [PATCH 09/28] Create week1 --- group26/1515345281/src/week1 | 1 + 1 file changed, 1 insertion(+) create mode 100644 group26/1515345281/src/week1 diff --git a/group26/1515345281/src/week1 b/group26/1515345281/src/week1 new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/group26/1515345281/src/week1 @@ -0,0 +1 @@ + From 597e0e024fa5aaa671b1bc4e487eaec688e1d8a8 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:11:40 +0800 Subject: [PATCH 10/28] Delete week1 --- group26/1515345281/src/week1 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 group26/1515345281/src/week1 diff --git a/group26/1515345281/src/week1 b/group26/1515345281/src/week1 deleted file mode 100644 index 8b13789179..0000000000 --- a/group26/1515345281/src/week1 +++ /dev/null @@ -1 +0,0 @@ - From 9555d309af905888d23cf28e264b30a1eea5427e Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:14:14 +0800 Subject: [PATCH 11/28] Create ww --- group26/1515345281/src/week1/ww | 1 + 1 file changed, 1 insertion(+) create mode 100644 group26/1515345281/src/week1/ww diff --git a/group26/1515345281/src/week1/ww b/group26/1515345281/src/week1/ww new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/group26/1515345281/src/week1/ww @@ -0,0 +1 @@ + From f353cfa1372e58da5b1245ef14d4aa233c8522bb Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:14:32 +0800 Subject: [PATCH 12/28] Create week2 --- group26/1515345281/src/week2 | 1 + 1 file changed, 1 insertion(+) create mode 100644 group26/1515345281/src/week2 diff --git a/group26/1515345281/src/week2 b/group26/1515345281/src/week2 new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/group26/1515345281/src/week2 @@ -0,0 +1 @@ + From 4b40386be291b13473d13cdd8be31b9e52b093a1 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:14:49 +0800 Subject: [PATCH 13/28] Delete week2 --- group26/1515345281/src/week2 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 group26/1515345281/src/week2 diff --git a/group26/1515345281/src/week2 b/group26/1515345281/src/week2 deleted file mode 100644 index 8b13789179..0000000000 --- a/group26/1515345281/src/week2 +++ /dev/null @@ -1 +0,0 @@ - From bd8f374ab06c401a7f7b1cffbd77f265b7087ca0 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:15:06 +0800 Subject: [PATCH 14/28] Create 11 --- group26/1515345281/src/week2/11 | 1 + 1 file changed, 1 insertion(+) create mode 100644 group26/1515345281/src/week2/11 diff --git a/group26/1515345281/src/week2/11 b/group26/1515345281/src/week2/11 new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/group26/1515345281/src/week2/11 @@ -0,0 +1 @@ + From fcba1ed913a27991fe8a69592908b9d10a03c602 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:15:16 +0800 Subject: [PATCH 15/28] Delete 11 --- group26/1515345281/src/week2/11 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 group26/1515345281/src/week2/11 diff --git a/group26/1515345281/src/week2/11 b/group26/1515345281/src/week2/11 deleted file mode 100644 index 8b13789179..0000000000 --- a/group26/1515345281/src/week2/11 +++ /dev/null @@ -1 +0,0 @@ - From b195d8581045e43b0a8ec2b015ba2e726d81b909 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:15:37 +0800 Subject: [PATCH 16/28] Create qqq --- group26/1515345281/src/week2/qqq | 1 + 1 file changed, 1 insertion(+) create mode 100644 group26/1515345281/src/week2/qqq diff --git a/group26/1515345281/src/week2/qqq b/group26/1515345281/src/week2/qqq new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/group26/1515345281/src/week2/qqq @@ -0,0 +1 @@ + From e2194be906b69ad8e7a5052b24f5a3ede2bbe88b Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:17:08 +0800 Subject: [PATCH 17/28] Create a --- group26/1515345281/src/week1/collection/test/a | 1 + 1 file changed, 1 insertion(+) create mode 100644 group26/1515345281/src/week1/collection/test/a diff --git a/group26/1515345281/src/week1/collection/test/a b/group26/1515345281/src/week1/collection/test/a new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/group26/1515345281/src/week1/collection/test/a @@ -0,0 +1 @@ + From 3c26d9c2caf738a800ce862338b6c1db699bf6e1 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:17:29 +0800 Subject: [PATCH 18/28] Delete ww --- group26/1515345281/src/week1/ww | 1 - 1 file changed, 1 deletion(-) delete mode 100644 group26/1515345281/src/week1/ww diff --git a/group26/1515345281/src/week1/ww b/group26/1515345281/src/week1/ww deleted file mode 100644 index 8b13789179..0000000000 --- a/group26/1515345281/src/week1/ww +++ /dev/null @@ -1 +0,0 @@ - From 843a85107e5752762588da832b212cf73b892f72 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:18:40 +0800 Subject: [PATCH 19/28] Add files via upload --- .../week1/collection/test/ArrayListTest.java | 69 ++++++++++++++ .../collection/test/BinarySearchTreeTest.java | 23 +++++ .../week1/collection/test/LinkedListTest.java | 90 +++++++++++++++++++ .../src/week1/collection/test/QueueTest.java | 27 ++++++ .../src/week1/collection/test/StackTest.java | 56 ++++++++++++ 5 files changed, 265 insertions(+) create mode 100644 group26/1515345281/src/week1/collection/test/ArrayListTest.java create mode 100644 group26/1515345281/src/week1/collection/test/BinarySearchTreeTest.java create mode 100644 group26/1515345281/src/week1/collection/test/LinkedListTest.java create mode 100644 group26/1515345281/src/week1/collection/test/QueueTest.java create mode 100644 group26/1515345281/src/week1/collection/test/StackTest.java diff --git a/group26/1515345281/src/week1/collection/test/ArrayListTest.java b/group26/1515345281/src/week1/collection/test/ArrayListTest.java new file mode 100644 index 0000000000..0fa7701041 --- /dev/null +++ b/group26/1515345281/src/week1/collection/test/ArrayListTest.java @@ -0,0 +1,69 @@ +package week1.test; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import week1.collection.ArrayList; +import week1.collection.Iterator; + +public class ArrayListTest { + + private ArrayList list=new ArrayList(); + + @Test + public void testAddObject(){ + list.add(1); + assertEquals(1 , list.get(0)); + } + + @Test + public void testAddIndexObject(){ + list.add("aa"); + list.add("bb"); + list.add(0,"cc"); + assertEquals("cc",list.get(0)); + try{ + list.add(-1,"pp"); + fail("- can't be index"); + + list.add(list.size()+100,"bb"); + fail("index should <= size"); + + }catch(Exception ex){ + + } + } + + @Test + public void testGetObject(){ + list.add(1); + assertEquals(1,list.get(0)); + } + + @Test + public void testRemoveObject(){ + list.add(1); + list.add(2); + list.add(3); + list.remove(0); + list.remove(2); + assertEquals(2,list.get(0)); + } + + @Test + public void testSize(){ + assertEquals(0,list.size()); + } + + @Test + public void testIterator(){ + list.add(1); + list.add(2); + list.add(3); + Iterator it=list.iterator(); + while(it.hasNext()){ + System.out.println(it.next()); + } + } +} diff --git a/group26/1515345281/src/week1/collection/test/BinarySearchTreeTest.java b/group26/1515345281/src/week1/collection/test/BinarySearchTreeTest.java new file mode 100644 index 0000000000..a6ea1cac3f --- /dev/null +++ b/group26/1515345281/src/week1/collection/test/BinarySearchTreeTest.java @@ -0,0 +1,23 @@ +package week1.test; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import week1.collection.BinaryTreeNode; + +public class BinarySearchTreeTest { + + private BinaryTreeNode root=new BinaryTreeNode(5); + + @Test + public void testInsert(){ + root.insert(2); + root.insert(2); + root.insert(7); + root.insert(1); + root.insert(4); + root.insert(3); + assertEquals(3,root.getLeft().getRight().getLeft().getData()); + } +} diff --git a/group26/1515345281/src/week1/collection/test/LinkedListTest.java b/group26/1515345281/src/week1/collection/test/LinkedListTest.java new file mode 100644 index 0000000000..cba45c719d --- /dev/null +++ b/group26/1515345281/src/week1/collection/test/LinkedListTest.java @@ -0,0 +1,90 @@ +package week1.test; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import week1.collection.Iterator; +import week1.collection.LinkedList; + +public class LinkedListTest { + + private LinkedList list=new LinkedList(); + + @Test + public void testAdd(){ + list.add("1"); + list.add("2"); + list.add("3"); + assertEquals("1",list.get(0)); + assertEquals("2",list.get(1)); + assertEquals(3,list.size()); + } + + @Test + public void testAddByIndex(){ + list.add(2); + list.add(4); + list.add(6); + list.add(0,0); + list.add(3,3); + list.add(5,7); + assertEquals(0, list.get(0)); + assertEquals(3, list.get(3)); + assertEquals(7, list.get(5)); + try{ + list.add(-1,0); + fail("-1 not a correctly index"); + }catch(Exception ex){ + + } + } + + @Test + public void testGet(){ + list.add(0); + list.add(1); + list.add(2); + assertEquals(0,list.get(0)); + } + + @Test + public void testRemove(){ + list.add(0); + list.add(1); + list.add(2); + list.add(3); + list.add(4); + assertEquals(0,list.remove(0)); + assertEquals(4,list.remove(3)); + assertEquals(2,list.remove(1)); + } + + @Test + public void testSize(){ + list.add(0); + list.addLast(0); + list.addFirst(0); + list.remove(0); + list.removeLast(); + list.removeFirst(); + assertEquals(0,list.size()); + } + + @Test + public void testOther(){ + list.add(1); + list.add(1); + list.add(1); + list.add(1); + list.addFirst(0); + list.addLast(2); + list.removeFirst(); + list.removeLast(); + Iterator it=list.iterator(); + while(it.hasNext()){ + System.out.print(it.next()+" "); + } + } + +} diff --git a/group26/1515345281/src/week1/collection/test/QueueTest.java b/group26/1515345281/src/week1/collection/test/QueueTest.java new file mode 100644 index 0000000000..81979682a6 --- /dev/null +++ b/group26/1515345281/src/week1/collection/test/QueueTest.java @@ -0,0 +1,27 @@ +package week1.test; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import week1.collection.Queue; + +public class QueueTest { + + private Queue queue=new Queue(); + + @Test + public void testEnQueue(){ + queue.enQueue("123"); + queue.enQueue("456"); + assertEquals("123",queue.deQueue()); + } + + @Test + public void testDeQueue(){ + queue.enQueue("123"); + queue.enQueue("456"); + queue.deQueue(); + assertEquals("456",queue.deQueue()); + } +} diff --git a/group26/1515345281/src/week1/collection/test/StackTest.java b/group26/1515345281/src/week1/collection/test/StackTest.java new file mode 100644 index 0000000000..717bf9b6a8 --- /dev/null +++ b/group26/1515345281/src/week1/collection/test/StackTest.java @@ -0,0 +1,56 @@ +package week1.test; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import week1.collection.Stack; + +public class StackTest { + + private Stack stack=new Stack(); + + @Test + public void testPush(){ + stack.push("hello"); + stack.push("world"); + assertEquals("world",stack.peek()); + } + + @Test + public void testPop(){ + stack.push("hello"); + stack.push("world"); + assertEquals("world",stack.pop()); + assertEquals(1,stack.size()); + } + + @Test + public void testPeek(){ + stack.push("world"); + assertEquals("world",stack.peek()); + stack.pop(); + try{ + stack.peek(); + fail("stack is empty,can't do peek"); + + }catch(Exception ex){ + + } + } + + @Test + public void testEmpty(){ + assertEquals(true,stack.isEmpty()); + stack.push("hello"); + stack.push("world"); + assertEquals(false,stack.isEmpty()); + } + + @Test + public void testSize(){ + stack.push("hello"); + stack.pop(); + assertEquals(0,stack.size()); + } +} From 338118ec396146c9f2e262328158e83a68d3cb77 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:19:14 +0800 Subject: [PATCH 20/28] Delete a --- group26/1515345281/src/week1/collection/test/a | 1 - 1 file changed, 1 deletion(-) delete mode 100644 group26/1515345281/src/week1/collection/test/a diff --git a/group26/1515345281/src/week1/collection/test/a b/group26/1515345281/src/week1/collection/test/a deleted file mode 100644 index 8b13789179..0000000000 --- a/group26/1515345281/src/week1/collection/test/a +++ /dev/null @@ -1 +0,0 @@ - From d4d8debdbbcc48dba2e8e6aee44f26f038c9bac5 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:20:15 +0800 Subject: [PATCH 21/28] Add files via upload --- .../src/week1/collection/ArrayList.java | 79 +++++++ .../src/week1/collection/BinaryTreeNode.java | 94 ++++++++ .../src/week1/collection/Iterator.java | 5 + .../src/week1/collection/LinkedList.java | 214 ++++++++++++++++++ .../1515345281/src/week1/collection/List.java | 9 + .../src/week1/collection/ListUtils.java | 9 + .../src/week1/collection/Queue.java | 24 ++ .../src/week1/collection/Stack.java | 37 +++ 8 files changed, 471 insertions(+) create mode 100644 group26/1515345281/src/week1/collection/ArrayList.java create mode 100644 group26/1515345281/src/week1/collection/BinaryTreeNode.java create mode 100644 group26/1515345281/src/week1/collection/Iterator.java create mode 100644 group26/1515345281/src/week1/collection/LinkedList.java create mode 100644 group26/1515345281/src/week1/collection/List.java create mode 100644 group26/1515345281/src/week1/collection/ListUtils.java create mode 100644 group26/1515345281/src/week1/collection/Queue.java create mode 100644 group26/1515345281/src/week1/collection/Stack.java diff --git a/group26/1515345281/src/week1/collection/ArrayList.java b/group26/1515345281/src/week1/collection/ArrayList.java new file mode 100644 index 0000000000..2ba58db6f0 --- /dev/null +++ b/group26/1515345281/src/week1/collection/ArrayList.java @@ -0,0 +1,79 @@ +package week1.collection; + +import java.util.Arrays; + +public class ArrayList implements List { + + private int size=0; + + private Object[] elementData=new Object[100]; + + public void add(Object o){ + + add(size,o); + + } + + public void add(int index, Object o){ + + ListUtils.checkIndexRange(index,size); + + if(size == elementData.length){ + elementData = Arrays.copyOf(elementData, elementData.length+50); + } + + if(index < size){ + for(int i=size-1;i>=index;i--){ + elementData[i+1]=elementData[i]; + } + } + elementData[index] = o; + size++; + } + + public Object get(int index){ + + ListUtils.checkIndexRange(index+1,size); + + return elementData[index]; + } + + public Object remove(int index){ + + ListUtils.checkIndexRange(index+1,size); + + Object object=elementData[index]; + for(int i=index;i 0){ + if(null == currentNode.getLeft()){ + BinaryTreeNode insertNode=new BinaryTreeNode(o); + currentNode.setLeft(insertNode); + return insertNode; + } + currentNode=currentNode.left; + }else{ + if(null ==currentNode.right){ + BinaryTreeNode insertNode=new BinaryTreeNode(o); + currentNode.setRight(insertNode); + return insertNode; + } + currentNode=currentNode.right; + } + } + return new BinaryTreeNode(o); + }*/ + + /* + * 递归实现 + */ + public BinaryTreeNode insert(Comparable o){ + + Comparable data=(Comparable) this.getData(); + int result=data.compareTo(o); + + if(result == 0){ + return this; + }else if(result > 0){ + if(this.getLeft()==null){ + BinaryTreeNode node=new BinaryTreeNode(o); + this.setLeft(node); + return node; + } + return this.getLeft().insert(o); + }else{ + if(this.getRight()==null){ + BinaryTreeNode node=new BinaryTreeNode(o); + this.setRight(node); + return node; + } + return this.getRight().insert(o); + } + } + + public Object getData() { + return data; + } + + public void setData(Comparable data) { + this.data = data; + } + + public BinaryTreeNode getLeft() { + return left; + } + + public void setLeft(BinaryTreeNode left) { + this.left = left; + } + + public BinaryTreeNode getRight() { + return right; + } + + public void setRight(BinaryTreeNode right) { + this.right = right; + } + +} diff --git a/group26/1515345281/src/week1/collection/Iterator.java b/group26/1515345281/src/week1/collection/Iterator.java new file mode 100644 index 0000000000..03e50730f7 --- /dev/null +++ b/group26/1515345281/src/week1/collection/Iterator.java @@ -0,0 +1,5 @@ +package week1.collection; +public interface Iterator{ + public boolean hasNext(); + public Object next(); +} \ No newline at end of file diff --git a/group26/1515345281/src/week1/collection/LinkedList.java b/group26/1515345281/src/week1/collection/LinkedList.java new file mode 100644 index 0000000000..fd0b9c76dd --- /dev/null +++ b/group26/1515345281/src/week1/collection/LinkedList.java @@ -0,0 +1,214 @@ +package week1.collection; + +/* + * 要求:单向链表实现 + */ +public class LinkedList implements List { + + private int size=0;//表示该链表的长度 + private Node head;//链表的头元素 + + public void add(Object o){ + if(null == head){ + head = new Node(o); + size++; + return ; + } + + Node node=head; + while(null != node.next){ + node=node.next; + } + Node addNode=new Node(o); + node.next=addNode; + size++; + } + + public void add(int index , Object o){ + if(size == 0 || index ==size){ + add(o); + return ; + } + + ListUtils.checkIndexRange(index, size); + + if(index==0){ + Node node=new Node(head.next.data); + node.next=head.next; + head.next=node; + head.data=o; + size++; + return ; + } + + Node node=head; + for(int i=0;i7->10 , 逆置后变为 10->7->3 + */ + public void reverse(){ + + } + + /** + * 删除一个单链表的前半部分 + * 例如:list = 2->5->7->8 , 删除以后的值为 7->8 + * 如果list = 2->5->7->8->10 ,删除以后的值为7,8,10 + + */ + public void removeFirstHalf(){ + + } + + /** + * 从第i个元素开始, 删除length 个元素 , 注意i从0开始 + * @param i + * @param length + */ + public void remove(int i, int length){ + + } + /** + * 假定当前链表和listB均包含已升序排列的整数 + * 从当前链表中取出那些listB所指定的元素 + * 例如当前链表 = 11->101->201->301->401->501->601->701 + * listB = 1->3->4->6 + * 返回的结果应该是[101,301,401,601] + * @param list + */ + public int[] getElements(LinkedList list){ + return null; + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 从当前链表中中删除在listB中出现的元素 + + * @param list + */ + + public void subtract(LinkedList list){ + + } + + /** + * 已知当前链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 删除表中所有值相同的多余元素(使得操作后的线性表中所有元素的值均不相同) + */ + public void removeDuplicateValues(){ + + } + + /** + * 已知链表中的元素以值递增有序排列,并以单链表作存储结构。 + * 试写一高效的算法,删除表中所有值大于min且小于max的元素(若表中存在这样的元素) + * @param min + * @param max + */ + public void removeRange(int min, int max){ + + } + + /** + * 假设当前链表和参数list指定的链表均以元素依值递增有序排列(同一表中的元素值各不相同) + * 现要求生成新链表C,其元素为当前链表和list中元素的交集,且表C中的元素有依值递增有序排列 + * @param list + */ + public LinkedList intersection( LinkedList list){ + return null; + } +} \ No newline at end of file diff --git a/group26/1515345281/src/week1/collection/List.java b/group26/1515345281/src/week1/collection/List.java new file mode 100644 index 0000000000..013956e25b --- /dev/null +++ b/group26/1515345281/src/week1/collection/List.java @@ -0,0 +1,9 @@ +package week1.collection; + +public interface List{ + public void add(Object o); + public void add(int index,Object o); + public Object get(int index); + public Object remove(int index); + public int size(); +} \ No newline at end of file diff --git a/group26/1515345281/src/week1/collection/ListUtils.java b/group26/1515345281/src/week1/collection/ListUtils.java new file mode 100644 index 0000000000..3ebb559aea --- /dev/null +++ b/group26/1515345281/src/week1/collection/ListUtils.java @@ -0,0 +1,9 @@ +package week1.collection; + +public class ListUtils { + + public static void checkIndexRange(int index, int size) { + if (index < 0 || index > size) + throw new IndexOutOfBoundsException(); + } +} diff --git a/group26/1515345281/src/week1/collection/Queue.java b/group26/1515345281/src/week1/collection/Queue.java new file mode 100644 index 0000000000..06f5ea52c8 --- /dev/null +++ b/group26/1515345281/src/week1/collection/Queue.java @@ -0,0 +1,24 @@ +package week1.collection; + +public class Queue { + + private LinkedList list=new LinkedList(); + + public void enQueue(Object o){ + list.add(o); + } + + public Object deQueue(){ + + return list.removeFirst(); + } + + public boolean isEmpty(){ + + return list.size()==0; + } + + public int size(){ + return list.size(); + } +} diff --git a/group26/1515345281/src/week1/collection/Stack.java b/group26/1515345281/src/week1/collection/Stack.java new file mode 100644 index 0000000000..63b226dca8 --- /dev/null +++ b/group26/1515345281/src/week1/collection/Stack.java @@ -0,0 +1,37 @@ +package week1.collection; + +import java.util.EmptyStackException; + +public class Stack { + private ArrayList elementData = new ArrayList(); + + + public void push(Object o){ + elementData.add(o); + } + + public Object pop(){ + if(isEmpty()){ + throw new EmptyStackException(); + } + + Object data=elementData.get(size()-1); + elementData.remove(size()-1); + return data; + } + + public Object peek(){ + return (Object)elementData.get(size()-1); + } + + public boolean isEmpty(){ + if(elementData.size()==0) + return true; + else + return false; + } + + public int size(){ + return elementData.size(); + } +} From 1939a6347f8911f56ead6b2b50119699634f99b6 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:22:36 +0800 Subject: [PATCH 22/28] Create ArrayUtil.java --- .../src/week2/arrayutil/ArrayUtil.java | 225 ++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 group26/1515345281/src/week2/arrayutil/ArrayUtil.java diff --git a/group26/1515345281/src/week2/arrayutil/ArrayUtil.java b/group26/1515345281/src/week2/arrayutil/ArrayUtil.java new file mode 100644 index 0000000000..dcc530949d --- /dev/null +++ b/group26/1515345281/src/week2/arrayutil/ArrayUtil.java @@ -0,0 +1,225 @@ +package week2.arrayutil; + +import java.util.ArrayList; + +public class ArrayUtil { + + /** + * 给定一个整形数组a , 对该数组的值进行置换 + 例如: a = [7, 9 , 30, 3] , 置换后为 [3, 30, 9,7] + 如果 a = [7, 9, 30, 3, 4] , 置换后为 [4,3, 30 , 9,7] + * @param origin + * @return + */ + public void reverseArray(int[] origin){ + for(int i=0;i list=new ArrayList(); + int i=0; + int j=0; + while(i array2[j]){ + list.add(array2[j]); + j++; + }else{ + list.add(array1[i]); + i++; + j++; + } + } + while(i=result.length ){ + result=this.grow(result, 5); + } + result[cursor]=result[cursor-2]+result[cursor-1]; + cursor++; + } + return result; + } + + + /** + * 返回小于给定最大值max的所有素数数组 + * 例如max = 23, 返回的数组为[2,3,5,7,11,13,17,19] + * @param max + * @return + */ + public int[] getPrimes(int max){ + if(max<=1){ + return new int[0]; + } + if(max == 2){ + return new int[]{2}; + } + + int[] temp=new int[max]; + temp[2]=2; + int primeNum=0; + for(int i=3;i list=new ArrayList(); + for(int i=6;i Date: Sun, 19 Mar 2017 23:22:58 +0800 Subject: [PATCH 23/28] Delete qqq --- group26/1515345281/src/week2/qqq | 1 - 1 file changed, 1 deletion(-) delete mode 100644 group26/1515345281/src/week2/qqq diff --git a/group26/1515345281/src/week2/qqq b/group26/1515345281/src/week2/qqq deleted file mode 100644 index 8b13789179..0000000000 --- a/group26/1515345281/src/week2/qqq +++ /dev/null @@ -1 +0,0 @@ - From 43416367d6769b7486e15ee50ba113642214f93e Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:23:44 +0800 Subject: [PATCH 24/28] Create View.java --- .../1515345281/src/week2/struts2/View.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 group26/1515345281/src/week2/struts2/View.java diff --git a/group26/1515345281/src/week2/struts2/View.java b/group26/1515345281/src/week2/struts2/View.java new file mode 100644 index 0000000000..5a907a455f --- /dev/null +++ b/group26/1515345281/src/week2/struts2/View.java @@ -0,0 +1,23 @@ +package week2.struts2; + +import java.util.Map; + +public class View { + private String jsp; + private Map parameters; + + public String getJsp() { + return jsp; + } + public View setJsp(String jsp) { + this.jsp = jsp; + return this; + } + public Map getParameters() { + return parameters; + } + public View setParameters(Map parameters) { + this.parameters = parameters; + return this; + } +} From b0fe53ffc6878af624b023cc320dd51e4dd833ce Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:24:33 +0800 Subject: [PATCH 25/28] Add files via upload --- .../src/week2/struts2/LoginAction.java | 39 ++++++++++++++++++ .../src/week2/struts2/LoginOutAction.java | 5 +++ .../1515345281/src/week2/struts2/Struts.java | 34 ++++++++++++++++ .../src/week2/struts2/StrutsTest.java | 40 +++++++++++++++++++ .../1515345281/src/week2/struts2/struts.xml | 12 ++++++ 5 files changed, 130 insertions(+) create mode 100644 group26/1515345281/src/week2/struts2/LoginAction.java create mode 100644 group26/1515345281/src/week2/struts2/LoginOutAction.java create mode 100644 group26/1515345281/src/week2/struts2/Struts.java create mode 100644 group26/1515345281/src/week2/struts2/StrutsTest.java create mode 100644 group26/1515345281/src/week2/struts2/struts.xml diff --git a/group26/1515345281/src/week2/struts2/LoginAction.java b/group26/1515345281/src/week2/struts2/LoginAction.java new file mode 100644 index 0000000000..0a34e92f18 --- /dev/null +++ b/group26/1515345281/src/week2/struts2/LoginAction.java @@ -0,0 +1,39 @@ +package week2.struts2; + +/** + * 这是一个用来展示登录的业务类, 其中的用户名和密码都是硬编码的。 + * @author liuxin + * + */ +public class LoginAction{ + private String name ; + private String password; + private String message; + + public String getName() { + return name; + } + + public String getPassword() { + return password; + } + + public String execute(){ + if("test".equals(name) && "1234".equals(password)){ + this.message = "login successful"; + return "success"; + } + this.message = "login failed,please check your user/pwd"; + return "fail"; + } + + public void setName(String name){ + this.name = name; + } + public void setPassword(String password){ + this.password = password; + } + public String getMessage(){ + return this.message; + } +} diff --git a/group26/1515345281/src/week2/struts2/LoginOutAction.java b/group26/1515345281/src/week2/struts2/LoginOutAction.java new file mode 100644 index 0000000000..54bfb503fd --- /dev/null +++ b/group26/1515345281/src/week2/struts2/LoginOutAction.java @@ -0,0 +1,5 @@ +package week2.struts2; + +public class LoginOutAction { + +} diff --git a/group26/1515345281/src/week2/struts2/Struts.java b/group26/1515345281/src/week2/struts2/Struts.java new file mode 100644 index 0000000000..06edfe7e20 --- /dev/null +++ b/group26/1515345281/src/week2/struts2/Struts.java @@ -0,0 +1,34 @@ +package week2.struts2; + +import java.util.Map; + +public class Struts { + + + public static View runAction(String actionName, Map parameters) { + + /* + + 0. 读取配置文件struts.xml + + 1. 根据actionName找到相对应的class , 例如LoginAction, 通过反射实例化(创建对象) + 据parameters中的数据,调用对象的setter方法, 例如parameters中的数据是 + ("name"="test" , "password"="1234") , + 那就应该调用 setName和setPassword方法 + + 2. 通过反射调用对象的exectue 方法, 并获得返回值,例如"success" + - + 3. 通过反射找到对象的所有getter方法(例如 getMessage), + 通过反射来调用, 把值和属性形成一个HashMap , 例如 {"message": "登录成功"} , + 放到View对象的parameters + + 4. 根据struts.xml中的 配置,以及execute的返回值, 确定哪一个jsp, + 放到View对象的jsp字段中。 + + */ + + + return null; + } + +} diff --git a/group26/1515345281/src/week2/struts2/StrutsTest.java b/group26/1515345281/src/week2/struts2/StrutsTest.java new file mode 100644 index 0000000000..68ec3ee4b4 --- /dev/null +++ b/group26/1515345281/src/week2/struts2/StrutsTest.java @@ -0,0 +1,40 @@ +package week2.struts2; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + + +public class StrutsTest { + + @Test + public void testLoginActionSuccess() { + + String actionName = "login"; + + Map params = new HashMap(); + params.put("name","test"); + params.put("password","1234"); + + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/homepage.jsp", view.getJsp()); + Assert.assertEquals("login successful", view.getParameters().get("message")); + } + + @Test + public void testLoginActionFailed() { + String actionName = "login"; + Map params = new HashMap(); + params.put("name","test"); + params.put("password","123456"); //密码和预设的不一致 + + View view = Struts.runAction(actionName,params); + + Assert.assertEquals("/jsp/showLogin.jsp", view.getJsp()); + Assert.assertEquals("login failed,please check your user/pwd", view.getParameters().get("message")); + } +} diff --git a/group26/1515345281/src/week2/struts2/struts.xml b/group26/1515345281/src/week2/struts2/struts.xml new file mode 100644 index 0000000000..9e69fa4e47 --- /dev/null +++ b/group26/1515345281/src/week2/struts2/struts.xml @@ -0,0 +1,12 @@ + + + + /jsp/homepage.jsp + /jsp/showLogin.jsp + + + + /jsp/welcome.jsp + /jsp/error.jsp + + \ No newline at end of file From 96e57174278bccd9a9ef56077f6c05fe5349969d Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:26:01 +0800 Subject: [PATCH 26/28] Create ArrayUtilTest.java --- group26/1515345281/src/week2/arrayutil/ArrayUtilTest.java | 1 + 1 file changed, 1 insertion(+) create mode 100644 group26/1515345281/src/week2/arrayutil/ArrayUtilTest.java diff --git a/group26/1515345281/src/week2/arrayutil/ArrayUtilTest.java b/group26/1515345281/src/week2/arrayutil/ArrayUtilTest.java new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/group26/1515345281/src/week2/arrayutil/ArrayUtilTest.java @@ -0,0 +1 @@ + From acd6537cdf67c7abbc3a61106e6d40ea35578532 Mon Sep 17 00:00:00 2001 From: SJsunshine Date: Sun, 19 Mar 2017 23:26:27 +0800 Subject: [PATCH 27/28] Update ArrayUtilTest.java --- .../src/week2/arrayutil/ArrayUtilTest.java | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/group26/1515345281/src/week2/arrayutil/ArrayUtilTest.java b/group26/1515345281/src/week2/arrayutil/ArrayUtilTest.java index 8b13789179..7b0d3c94e0 100644 --- a/group26/1515345281/src/week2/arrayutil/ArrayUtilTest.java +++ b/group26/1515345281/src/week2/arrayutil/ArrayUtilTest.java @@ -1 +1,97 @@ +package week2.test; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import week2.arrayutil.ArrayUtil; + +public class ArrayUtilTest { + + private ArrayUtil arrayUtil=new ArrayUtil(); + + @Test + public void testReverseArray(){ + + int[] origin={1,2,3,4}; + arrayUtil.reverseArray(origin); + assertArrayEquals(new int[]{4,3,2,1}, origin); + + int[] origin1={5,6,7}; + arrayUtil.reverseArray(origin1); + assertArrayEquals(new int[]{7,6,5},origin1); + } + + @Test + public void testRemoveArray(){ + + int[] oldArray={0,0,1,2,0,0,3,4,0,0}; + int[] result=arrayUtil.removeZero(oldArray); + assertArrayEquals(new int[]{1,2,3,4},result); + } + + @Test + public void testMerge(){ + int[] array1={3,5,7,8}; + int[] array2={4,5,6,7}; + int[] array=arrayUtil.merge(array1, array2); + assertArrayEquals(new int[]{3,4,5,6,7,8}, array); + } + + @Test + public void testGrow(){ + int[] oldArray={2,3,6}; + int size=3; + int[] newArray=new int[oldArray.length+size]; + newArray=arrayUtil.grow(oldArray, size); + assertArrayEquals(new int[]{2,3,6,0,0,0},newArray); + } + + @Test + public void testFibonacci(){ + int max=1; + int[] result=arrayUtil.fibonacci(max); + assertArrayEquals(new int[0],result); + + max=2; + int[] result1=arrayUtil.fibonacci(max); + assertEquals(1,result1[0]); + + max=15; + int[] result2=arrayUtil.fibonacci(max); + assertArrayEquals(new int[]{1,1,2,3,5,8,13},result2); + } + + @Test + public void testGetPrime(){ + int max=-1; + int[] result=arrayUtil.getPrimes(max); + assertEquals(new int[0],result); + + max=23; + result=arrayUtil.getPrimes(max); + assertEquals(new int[]{2,3,5,7,11,13,17,19},result); + + } + + @Test + public void testGetPerfectNumbers(){ + int max=7; + int[] result=arrayUtil.getPerfectNumbers(max); + assertArrayEquals(new int[]{6},result); + + max=100; + result=arrayUtil.getPerfectNumbers(max); + assertArrayEquals(new int[]{6,28},result); + } + + @Test + public void testJoin(){ + String seperator="-"; + int[] array={3,5,8}; + String result=arrayUtil.join(array, seperator); + assertEquals("3-5-8",result); + + } +} From 68c05424ecea2a3d2ad1e2e5631e596b5afa2efc Mon Sep 17 00:00:00 2001 From: BlindingDark Date: Sun, 19 Mar 2017 11:10:30 -0500 Subject: [PATCH 28/28] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 第二次作业提交 --- ...04\346\203\205\345\206\265\347\273\237\350\256\241.md" | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git "a/group26/26\347\273\204\346\203\205\345\206\265\347\273\237\350\256\241.md" "b/group26/26\347\273\204\346\203\205\345\206\265\347\273\237\350\256\241.md" index 74fab9de80..165922cc87 100644 --- "a/group26/26\347\273\204\346\203\205\345\206\265\347\273\237\350\256\241.md" +++ "b/group26/26\347\273\204\346\203\205\345\206\265\347\273\237\350\256\241.md" @@ -5,17 +5,17 @@ | | 文章1 | | | | | | 723161901 | 已完成 | | | | | | | | | | | | -| jiaxun1990(89460886) | 已完成 | | | | | +| jiaxun1990(89460886) | 已完成 | 已完成 | | | | | | https://goo.gl/Wvz3Od | | | | | -| 1515345281 | 已完成 | | | | | +| 1515345281 | 已完成 | 已完成 | | | | | | | | | | | | 2070509107 | 已完成 | | | | | | | | | | | | -| lizhy2017 | 部分完成 | | | | | +| lizhy2017 | 部分完成 | 已完成 | | | | | | | | | | | | JEE-逆水百川 | 部分完成 | | | | | | | http://blog.csdn.net/u012759397/article/details/61618612 | | | | | -|191191717 |已完成|       |           |     |     |     |     |     |     |     | +|191191717 |已完成|   已完成    |           |     |     |     |     |     |     |     | | | | | | | | | | | | | | 1778842360 | 已完成 |完成80% | | | | | | | | | | | 文章1 http://note.youdao.com/noteshare?id=7e8faf2bd2a7a3e5259d83bb1e6d9d8f | | | | | | | | | |