浏览代码

Merge pull request #889 from FridaTveit/SimpleLinkedListUseGenerics

simple-linked-list: use generics
FridaTveit 9 年前
父节点
当前提交
a1234ac352
共有 1 个文件被更改,包括 25 次插入25 次删除
  1. 25
    25
      exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java

+ 25
- 25
exercises/simple-linked-list/src/test/java/SimpleLinkedListTest.java 查看文件

@@ -15,15 +15,15 @@ public class SimpleLinkedListTest {
15 15
 
16 16
     @Test
17 17
     public void aNewListIsEmpty() {
18
-        SimpleLinkedList list = new SimpleLinkedList();
18
+        SimpleLinkedList<Integer> list = new SimpleLinkedList<>();
19 19
         assertThat(list.size(), is(0));
20 20
     }
21 21
 
22 22
     @Ignore("Remove to run test")
23 23
     @Test
24 24
     public void canCreateFromArray() {
25
-        Integer[] values = new Integer[]{1, 2, 3};
26
-        SimpleLinkedList list = new SimpleLinkedList(values);
25
+        Character[] values = new Character[]{'1', '2', '3'};
26
+        SimpleLinkedList<Character> list = new SimpleLinkedList<Character>(values);
27 27
         assertThat(list.size(), is(3));
28 28
     }
29 29
 
@@ -31,14 +31,14 @@ public class SimpleLinkedListTest {
31 31
     @Test
32 32
     public void popOnEmptyListWillThrow() {
33 33
         expectedException.expect(NoSuchElementException.class);
34
-        SimpleLinkedList list = new SimpleLinkedList();
34
+        SimpleLinkedList<String> list = new SimpleLinkedList<String>();
35 35
         list.pop();
36 36
     }
37 37
 
38 38
     @Ignore("Remove to run test")
39 39
     @Test
40 40
     public void popReturnsLastAddedElement() {
41
-        SimpleLinkedList list = new SimpleLinkedList();
41
+        SimpleLinkedList<Integer> list = new SimpleLinkedList<Integer>();
42 42
         list.push(9);
43 43
         list.push(8);
44 44
         assertThat(list.size(), is(2));
@@ -50,37 +50,37 @@ public class SimpleLinkedListTest {
50 50
     @Ignore("Remove to run test")
51 51
     @Test
52 52
     public void reverseReversesList() {
53
-        SimpleLinkedList list = new SimpleLinkedList();
54
-        list.push(9);
55
-        list.push(8);
56
-        list.push(7);
57
-        list.push(6);
58
-        list.push(5);
53
+        SimpleLinkedList<String> list = new SimpleLinkedList<String>();
54
+        list.push("9");
55
+        list.push("8");
56
+        list.push("7");
57
+        list.push("6");
58
+        list.push("5");
59 59
         list.reverse();
60
-        assertThat(list.pop(), is(9));
61
-        assertThat(list.pop(), is(8));
62
-        assertThat(list.pop(), is(7));
63
-        assertThat(list.pop(), is(6));
64
-        assertThat(list.pop(), is(5));
60
+        assertThat(list.pop(), is("9"));
61
+        assertThat(list.pop(), is("8"));
62
+        assertThat(list.pop(), is("7"));
63
+        assertThat(list.pop(), is("6"));
64
+        assertThat(list.pop(), is("5"));
65 65
     }
66 66
 
67 67
     @Ignore("Remove to run test")
68 68
     @Test
69 69
     public void canReturnListAsArray() {
70
-        SimpleLinkedList list = new SimpleLinkedList();
71
-        list.push(9);
72
-        list.push(8);
73
-        list.push(7);
74
-        list.push(6);
75
-        list.push(5);
76
-        Integer[] expected = {5, 6, 7, 8, 9};
77
-        assertArrayEquals(expected, list.asArray(Integer.class));
70
+        SimpleLinkedList<Character> list = new SimpleLinkedList<Character>();
71
+        list.push('9');
72
+        list.push('8');
73
+        list.push('7');
74
+        list.push('6');
75
+        list.push('5');
76
+        Character[] expected = {'5', '6', '7', '8', '9'};
77
+        assertArrayEquals(expected, list.asArray(Character.class));
78 78
     }
79 79
 
80 80
     @Ignore("Remove to run test")
81 81
     @Test
82 82
     public void canReturnEmptyListAsEmptyArray() {
83
-        SimpleLinkedList list = new SimpleLinkedList();
83
+        SimpleLinkedList<Object> list = new SimpleLinkedList<Object>();
84 84
         Object[] expected = {};
85 85
         assertArrayEquals(expected, list.asArray(Object.class));
86 86
     }