Commit 8662c8e4a6fa4783a2ecb57bf2cd5cd8f160860a

Authored by Adrian Chirita
1 parent d5759da3

mappe innhold forandret, tester imports og innhold forandret, lagt til

nye tester
.classpath
... ... @@ -2,5 +2,6 @@
2 2 <classpath>
3 3 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
4 4 <classpathentry kind="src" path="src"/>
  5 + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
5 6 <classpathentry kind="output" path="bin"/>
6 7 </classpath>
... ...
src/Main.java renamed to src/oblig_2/Main.java
  1 +package oblig_2;
  2 +
1 3 public class Main {
2 4  
3 5 public static void main(String[] args) {
... ...
src/MyLinkedList.java renamed to src/oblig_2/MyLinkedList.java
  1 +package oblig_2;
  2 +
1 3 // 11th edition version
2 4 public class MyLinkedList<E> implements MyList<E> {
3 5 private Node<E> head, tail;
... ...
src/MyList.java renamed to src/oblig_2/MyList.java
  1 +package oblig_2;
1 2 // MyList from 11th edition
2 3  
3 4 import java.util.Collection;
... ...
src/TwoWayLinkedList.java renamed to src/oblig_2/TwoWayLinkedList.java
  1 +package oblig_2;
1 2 import java.util.Iterator;
2 3 import java.util.ListIterator;
3 4  
... ...
src/TwoWayLinkedListTest.java renamed to src/test/TwoWayLinkedListTest.java
1   -import org.junit.jupiter.api.AfterEach;
2   -import org.junit.jupiter.api.BeforeAll;
3   -import org.junit.jupiter.api.BeforeEach;
4   -import org.junit.jupiter.api.Test;
  1 +package test;
  2 +
  3 +import java.util.Iterator;
  4 +import static org.junit.Assert.*;
  5 +import static org.hamcrest.CoreMatchers.*;
  6 +import org.junit.Before;
  7 +import org.junit.Test;
  8 +
  9 +import oblig_2.TwoWayLinkedList;
5 10  
6   -import static org.junit.jupiter.api.Assertions.assertEquals;
7   -import static org.junit.jupiter.api.Assertions.assertNotEquals;
8 11  
9 12 public class TwoWayLinkedListTest {
10 13  
11 14 private TwoWayLinkedList<String> data;
12   -
13   - @BeforeEach
  15 + private Iterator<String> itr;
  16 +
  17 + @Before
14 18 public void setUp(){
15 19 data = new TwoWayLinkedList<>();
16 20 }
17   -
18 21 @Test
19 22 public void getFirst() {
20 23 String result = "Oreo";
... ... @@ -23,7 +26,6 @@ public class TwoWayLinkedListTest {
23 26 data.addFirst(result);
24 27 assertEquals(result, data.getFirst());
25 28 }
26   -
27 29 @Test
28 30 public void getLast() {
29 31 String result = "Oreo";
... ... @@ -32,21 +34,18 @@ public class TwoWayLinkedListTest {
32 34 data.addLast(result);
33 35 assertEquals(result, data.getLast());
34 36 }
35   -
36 37 @Test
37 38 public void addFirst() {
38 39 String result = "Oreo";
39 40 data.addFirst(result);
40 41 assertEquals(result, data.getFirst());
41 42 }
42   -
43 43 @Test
44 44 public void addLast() {
45 45 String result = "Oreo";
46 46 data.addLast(result);
47 47 assertEquals(result, data.getLast());
48 48 }
49   -
50 49 @Test
51 50 public void add() {
52 51 int n = 5;
... ... @@ -54,7 +53,6 @@ public class TwoWayLinkedListTest {
54 53 assertEquals(n+1, data.size());
55 54 assertEquals("test "+n, data.getLast());
56 55 }
57   -
58 56 @Test
59 57 public void removeFirst() {
60 58 data.add("Kitkat");
... ... @@ -63,7 +61,6 @@ public class TwoWayLinkedListTest {
63 61 assertEquals("Kitkat",data.removeFirst());
64 62 assertNotEquals("Kitkat",data.getFirst());
65 63 }
66   -
67 64 @Test
68 65 public void removeLast() {
69 66 data.add("Kitkat");
... ... @@ -72,7 +69,6 @@ public class TwoWayLinkedListTest {
72 69 assertEquals("Oreo",data.removeLast());
73 70 assertNotEquals("Oreo",data.getLast());
74 71 }
75   -
76 72 @Test
77 73 public void remove() {
78 74 data.add("Kitkat");
... ... @@ -82,4 +78,83 @@ public class TwoWayLinkedListTest {
82 78 assertEquals("Pie", data.remove(1));
83 79 assertEquals("Kitkat",data.remove(0));
84 80 }
  81 + @Test
  82 + public void addIndex() {
  83 + data.add(0,"Vitkat");
  84 + data.add(1,"Kitkat");
  85 + data.add(2,"Pie");
  86 + data.add(3,"Oreo");
  87 + assertEquals("Pie",data.get(2));
  88 + }
  89 + @Test
  90 + public void clear() {
  91 + data.add(0,"Vitkat");
  92 + data.add(1,"Kitkat");
  93 + data.add(2,"Pie");
  94 + data.add(3,"Oreo");
  95 + assertEquals("Pie",data.get(2));
  96 + data.clear();
  97 + assertEquals(null,data.get(0));
  98 + assertNotEquals("Kitkat",data.get(1));
  99 + assertEquals(null,data.get(2));
  100 + assertEquals(null,data.get(3));
  101 + }
  102 + @Test
  103 + public void clearList() {
  104 + data.add(0,"Vitkat");
  105 + data.add(1,"Kitkat");
  106 + data.add(2,"Pie");
  107 + data.add(3,"Oreo");
  108 + assertEquals("Pie",data.get(2));
  109 + data.clear();
  110 + assertEquals(null,data.get(0));
  111 + assertNotEquals("Kitkat",data.get(1));
  112 + assertEquals(null,data.get(2));
  113 + assertEquals(null,data.get(3));
  114 + }
  115 + @Test
  116 + public void contains() {
  117 + data.add(0,"Vitkat");
  118 + data.add(1,"Kitkat");
  119 + data.add(2,"Pie");
  120 + data.add(3,"Oreo");
  121 +
  122 + assertEquals(true,data.contains("Oreo"));
  123 + assertNotEquals(true,data.contains("Snikers"));
  124 + }
  125 + @Test
  126 + public void indexOf() {
  127 + data.add(0,"Vitkat");
  128 + data.add(1,"Kitkat");
  129 + data.add(2,"Pie");
  130 + data.add(3,"Oreo");
  131 + data.add(4,"Vitkat");
  132 + data.add(2,"Pie");
  133 + assertEquals(0,data.indexOf("Vitkat"));
  134 + assertEquals(2,data.indexOf("Pie"));
  135 + }
  136 + @Test
  137 + public void LastindexOf() {
  138 + data.add(0,"Vitkat");
  139 + data.add(1,"Kitkat");
  140 + data.add(2,"Pie");
  141 + data.add(3,"Oreo");
  142 + data.add(4,"Vitkat");
  143 + data.add(5,"Pie");
  144 + assertEquals(4,data.lastIndexOf("Vitkat"));
  145 + assertEquals(5,data.lastIndexOf("Pie"));
  146 + }
  147 + @Test
  148 + public void firstCallNextIteratorMethodReturnsFirstElement() {
  149 + data.addFirst("a");
  150 + itr = data.iterator();
  151 + String result = itr.next();
  152 + assertThat(result, is("a"));
  153 + }
  154 + @Test(expected = java.util.NoSuchElementException.class)
  155 + public void callNextIteratorMethodOnEmptyListThrowsException() {
  156 + itr = data.iterator();
  157 + itr.next();
  158 + }
  159 +
85 160 }
86 161 \ No newline at end of file
... ...