Просмотр исходного кода

Merge pull request #889 from FridaTveit/SimpleLinkedListUseGenerics

simple-linked-list: use generics
FridaTveit 9 лет назад
Родитель
Сommit
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
 
16
     @Test
16
     @Test
17
     public void aNewListIsEmpty() {
17
     public void aNewListIsEmpty() {
18
-        SimpleLinkedList list = new SimpleLinkedList();
18
+        SimpleLinkedList<Integer> list = new SimpleLinkedList<>();
19
         assertThat(list.size(), is(0));
19
         assertThat(list.size(), is(0));
20
     }
20
     }
21
 
21
 
22
     @Ignore("Remove to run test")
22
     @Ignore("Remove to run test")
23
     @Test
23
     @Test
24
     public void canCreateFromArray() {
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
         assertThat(list.size(), is(3));
27
         assertThat(list.size(), is(3));
28
     }
28
     }
29
 
29
 
31
     @Test
31
     @Test
32
     public void popOnEmptyListWillThrow() {
32
     public void popOnEmptyListWillThrow() {
33
         expectedException.expect(NoSuchElementException.class);
33
         expectedException.expect(NoSuchElementException.class);
34
-        SimpleLinkedList list = new SimpleLinkedList();
34
+        SimpleLinkedList<String> list = new SimpleLinkedList<String>();
35
         list.pop();
35
         list.pop();
36
     }
36
     }
37
 
37
 
38
     @Ignore("Remove to run test")
38
     @Ignore("Remove to run test")
39
     @Test
39
     @Test
40
     public void popReturnsLastAddedElement() {
40
     public void popReturnsLastAddedElement() {
41
-        SimpleLinkedList list = new SimpleLinkedList();
41
+        SimpleLinkedList<Integer> list = new SimpleLinkedList<Integer>();
42
         list.push(9);
42
         list.push(9);
43
         list.push(8);
43
         list.push(8);
44
         assertThat(list.size(), is(2));
44
         assertThat(list.size(), is(2));
50
     @Ignore("Remove to run test")
50
     @Ignore("Remove to run test")
51
     @Test
51
     @Test
52
     public void reverseReversesList() {
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
         list.reverse();
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
     @Ignore("Remove to run test")
67
     @Ignore("Remove to run test")
68
     @Test
68
     @Test
69
     public void canReturnListAsArray() {
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
     @Ignore("Remove to run test")
80
     @Ignore("Remove to run test")
81
     @Test
81
     @Test
82
     public void canReturnEmptyListAsEmptyArray() {
82
     public void canReturnEmptyListAsEmptyArray() {
83
-        SimpleLinkedList list = new SimpleLinkedList();
83
+        SimpleLinkedList<Object> list = new SimpleLinkedList<Object>();
84
         Object[] expected = {};
84
         Object[] expected = {};
85
         assertArrayEquals(expected, list.asArray(Object.class));
85
         assertArrayEquals(expected, list.asArray(Object.class));
86
     }
86
     }