Skip to content

Commit

Permalink
统一代码格式
Browse files Browse the repository at this point in the history
  • Loading branch information
harryhook committed Apr 5, 2017
1 parent 49d2ca4 commit 6bc5b7d
Show file tree
Hide file tree
Showing 36 changed files with 2,329 additions and 2,698 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -9,156 +9,145 @@

import com.github.HarryHook.coding2017.array.ArrayUtil;

public class ArrayUtilTest
{
private ArrayUtil myArray;

@Before
public void setUp() throws Exception
{
myArray = new ArrayUtil();
}

@Test
public void testReverseArray()
{
int[] a = {1, 2, 1, 3, 5, 6};
int[] b = {6, 5, 3, 1, 2, 1};

myArray.reverseArray(a);
assertArrayEquals(a, b);

int[] c = new int[0];
myArray.reverseArray(c);
assertArrayEquals(c, new int[0]);

}

@Test
public void testRemoveZero()
{
int[] oldArr= {1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 1, 2, 0, 5};
int b[] = {1, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 1, 2, 5};
int[] c = myArray.removeZero(oldArr);
assertArrayEquals(b, c);

int[] d = null;
int[] e = myArray.removeZero(d);
assertNull(e);

}

@Test
public void testMerge()
{
int a1[] = {1, 2, 3, 4, 5};
int b1[] = {3, 4, 5, 6, 7, 8};
int c1[] = {1, 2, 3, 4, 5, 6, 7, 8};
int[] newArray1 = myArray.merge(a1, b1);
assertArrayEquals(c1, newArray1);

int a2[] = new int[0];
int b2[] = {0, 2, 3, 6, 7, 8};
int c2[] = {0, 2, 3, 6, 7, 8};
int[] newArray2 = myArray.merge(a2, b2);
assertArrayEquals(c2, newArray2);

int a3[] = {0, 2, 3, 6, 7, 8};
int b3[] = new int[0];
int c3[] = {0, 2, 3, 6, 7, 8};
int[] newArray3 = myArray.merge(a3, b3);
assertArrayEquals(c3, newArray3);

int[] a4 = null;
int[] b4 = null;
int[] newArray4 = myArray.merge(a4, b4);
assertNull(newArray4);
}

@Rule
public ExpectedException expectedEx = ExpectedException.none();

@Test
public void testGrow()
{
int[] a = {3, 5, 7, 8, 9};
int[] b = {3, 5, 7, 8, 9, 0, 0, 0};
int[] newArray = myArray.grow(a, 3);
assertArrayEquals(b, newArray);

int[] c = null;
int[] newArray1 = myArray.grow(c, 3);
assertNull(newArray1);

// size < 0 抛出异常
expectedEx.expect(Exception.class);
myArray.grow(a, -3);
}

@Test
public void testFibonacci()
{
//max == 1时返回空数组
int[] array1 = myArray.fibonacci(1);
int[] b = new int[0];
assertArrayEquals(array1, b);


int[] array2= myArray.fibonacci(35);
int[] c = {1, 1, 2, 3, 5, 8, 13, 21, 34 };
assertArrayEquals(c, array2);
}

@Test
public void testGetPrimes()
{
int[] a = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
int[] array1 = myArray.getPrimes(35);
assertArrayEquals(a, array1);

//max <= 2的时候没有素数,数组为空数组
int[] array2 = myArray.getPrimes(1);
int[] b = new int[0];
assertArrayEquals(array2, b);
}

@Test
public void testGetPerfectNumbers()
{
int[] array = myArray.getPerfectNumbers(-1);
assertNull(array);

array = myArray.getPerfectNumbers(0);
assertArrayEquals(array, new int[0]);

array = myArray.getPerfectNumbers(10000);
int[] a = {6, 28, 496, 8128 };
assertArrayEquals(a, array);
}

@Test
public void testJoin()
{
int[] array0 = {3, 5, 7, 8, 9};
String s0 = myArray.join(array0, "-");
String s1 = "3-5-7-8-9";
assertEquals(s1, s0);

int[] array1 = {3};
String s2 = myArray.join(array1, "-");
String s3 = "3";
assertEquals(s2, s3);

//传递空数组时,返回空字符串
int[] array2 = new int[0];
String s4 = myArray.join(array2, "-");
String s5 = "";
assertEquals(s4, s5);

//传递数组为null
int[] array3 = null;
String s6 = myArray.join(array3, "-");
assertNull(s6);
}
public class ArrayUtilTest {
private ArrayUtil myArray;

@Before
public void setUp() throws Exception {
myArray = new ArrayUtil();
}

@Test
public void testReverseArray() {
int[] a = { 1, 2, 1, 3, 5, 6 };
int[] b = { 6, 5, 3, 1, 2, 1 };

myArray.reverseArray(a);
assertArrayEquals(a, b);

int[] c = new int[0];
myArray.reverseArray(c);
assertArrayEquals(c, new int[0]);

}

@Test
public void testRemoveZero() {
int[] oldArr = { 1, 3, 4, 5, 0, 0, 6, 6, 0, 5, 4, 7, 6, 7, 1, 2, 0, 5 };
int b[] = { 1, 3, 4, 5, 6, 6, 5, 4, 7, 6, 7, 1, 2, 5 };
int[] c = myArray.removeZero(oldArr);
assertArrayEquals(b, c);

int[] d = null;
int[] e = myArray.removeZero(d);
assertNull(e);

}

@Test
public void testMerge() {
int a1[] = { 1, 2, 3, 4, 5 };
int b1[] = { 3, 4, 5, 6, 7, 8 };
int c1[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
int[] newArray1 = myArray.merge(a1, b1);
assertArrayEquals(c1, newArray1);

int a2[] = new int[0];
int b2[] = { 0, 2, 3, 6, 7, 8 };
int c2[] = { 0, 2, 3, 6, 7, 8 };
int[] newArray2 = myArray.merge(a2, b2);
assertArrayEquals(c2, newArray2);

int a3[] = { 0, 2, 3, 6, 7, 8 };
int b3[] = new int[0];
int c3[] = { 0, 2, 3, 6, 7, 8 };
int[] newArray3 = myArray.merge(a3, b3);
assertArrayEquals(c3, newArray3);

int[] a4 = null;
int[] b4 = null;
int[] newArray4 = myArray.merge(a4, b4);
assertNull(newArray4);
}

@Rule
public ExpectedException expectedEx = ExpectedException.none();

@Test
public void testGrow() {
int[] a = { 3, 5, 7, 8, 9 };
int[] b = { 3, 5, 7, 8, 9, 0, 0, 0 };
int[] newArray = myArray.grow(a, 3);
assertArrayEquals(b, newArray);

int[] c = null;
int[] newArray1 = myArray.grow(c, 3);
assertNull(newArray1);

// size < 0 抛出异常
expectedEx.expect(Exception.class);
myArray.grow(a, -3);
}

@Test
public void testFibonacci() {
// max == 1时返回空数组
int[] array1 = myArray.fibonacci(1);
int[] b = new int[0];
assertArrayEquals(array1, b);

int[] array2 = myArray.fibonacci(35);
int[] c = { 1, 1, 2, 3, 5, 8, 13, 21, 34 };
assertArrayEquals(c, array2);
}

@Test
public void testGetPrimes() {
int[] a = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 };
int[] array1 = myArray.getPrimes(35);
assertArrayEquals(a, array1);

// max <= 2的时候没有素数,数组为空数组
int[] array2 = myArray.getPrimes(1);
int[] b = new int[0];
assertArrayEquals(array2, b);
}

@Test
public void testGetPerfectNumbers() {
int[] array = myArray.getPerfectNumbers(-1);
assertNull(array);

array = myArray.getPerfectNumbers(0);
assertArrayEquals(array, new int[0]);

array = myArray.getPerfectNumbers(10000);
int[] a = { 6, 28, 496, 8128 };
assertArrayEquals(a, array);
}

@Test
public void testJoin() {
int[] array0 = { 3, 5, 7, 8, 9 };
String s0 = myArray.join(array0, "-");
String s1 = "3-5-7-8-9";
assertEquals(s1, s0);

int[] array1 = { 3 };
String s2 = myArray.join(array1, "-");
String s3 = "3";
assertEquals(s2, s3);

// 传递空数组时,返回空字符串
int[] array2 = new int[0];
String s4 = myArray.join(array2, "-");
String s5 = "";
assertEquals(s4, s5);

// 传递数组为null
int[] array3 = null;
String s6 = myArray.join(array3, "-");
assertNull(s6);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import org.junit.Before;
import com.github.HarryHook.coding2017.basic.MyArrayList;


public class ArrayListTest extends ListTest {

@Before
public void setUpArrayList()
{
aList = new MyArrayList();
}


@Before
public void setUpArrayList() {
aList = new MyArrayList();
}

}
Loading

0 comments on commit 6bc5b7d

Please sign in to comment.