Commit f471bc76f4040a553e044ace0c4732628bec84ca

Authored by Iuliia Romanivna Ukrainets
1 parent 2fa39892

add test cases for added methods

Showing 2 changed files with 108 additions and 2 deletions   Show diff stats
TwoWayList.iml
... ... @@ -7,6 +7,27 @@
7 7 </content>
8 8 <orderEntry type="inheritedJdk" />
9 9 <orderEntry type="sourceFolder" forTests="false" />
  10 + <orderEntry type="module-library" scope="TEST">
  11 + <library name="JUnit4">
  12 + <CLASSES>
  13 + <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
  14 + <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
  15 + </CLASSES>
  16 + <JAVADOC />
  17 + <SOURCES />
  18 + </library>
  19 + </orderEntry>
  20 + <orderEntry type="module-library">
  21 + <library name="JUnit5.2">
  22 + <CLASSES>
  23 + <root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.3.1/junit-jupiter-api-5.3.1.jar!/" />
  24 + <root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
  25 + <root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.1.1/opentest4j-1.1.1.jar!/" />
  26 + <root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.3.1/junit-platform-commons-1.3.1.jar!/" />
  27 + </CLASSES>
  28 + <JAVADOC />
  29 + <SOURCES />
  30 + </library>
  31 + </orderEntry>
10 32 </component>
11   -</module>
12   -
  33 +</module>
13 34 \ No newline at end of file
... ...
src/TwoWayLinkedListTest.java 0 → 100644
  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;
  5 +
  6 +import static org.junit.jupiter.api.Assertions.assertEquals;
  7 +import static org.junit.jupiter.api.Assertions.assertNotEquals;
  8 +
  9 +public class TwoWayLinkedListTest {
  10 +
  11 + private TwoWayLinkedList<String> data;
  12 +
  13 + @BeforeEach
  14 + public void setUp(){
  15 + data = new TwoWayLinkedList<>();
  16 + }
  17 +
  18 + @Test
  19 + public void getFirst() {
  20 + String result = "Oreo";
  21 + data.addFirst("Kitkat");
  22 + data.addFirst("Pie");
  23 + data.addFirst(result);
  24 + assertEquals(result, data.getFirst());
  25 + }
  26 +
  27 + @Test
  28 + public void getLast() {
  29 + String result = "Oreo";
  30 + data.addLast("Marshmallow");
  31 + data.addLast("Kitkat");
  32 + data.addLast(result);
  33 + assertEquals(result, data.getLast());
  34 + }
  35 +
  36 + @Test
  37 + public void addFirst() {
  38 + String result = "Oreo";
  39 + data.addFirst(result);
  40 + assertEquals(result, data.getFirst());
  41 + }
  42 +
  43 + @Test
  44 + public void addLast() {
  45 + String result = "Oreo";
  46 + data.addLast(result);
  47 + assertEquals(result, data.getLast());
  48 + }
  49 +
  50 + @Test
  51 + public void add() {
  52 + int n = 5;
  53 + for (int i=0;i<=n;i++) data.add(i,"test " + i);
  54 + assertEquals(n+1, data.size());
  55 + assertEquals("test "+n, data.getLast());
  56 + }
  57 +
  58 + @Test
  59 + public void removeFirst() {
  60 + data.add("Kitkat");
  61 + data.add("Pie");
  62 + data.add("Oreo");
  63 + assertEquals("Kitkat",data.removeFirst());
  64 + assertNotEquals("Kitkat",data.getFirst());
  65 + }
  66 +
  67 + @Test
  68 + public void removeLast() {
  69 + data.add("Kitkat");
  70 + data.add("Pie");
  71 + data.add("Oreo");
  72 + assertEquals("Oreo",data.removeLast());
  73 + assertNotEquals("Oreo",data.getLast());
  74 + }
  75 +
  76 + @Test
  77 + public void remove() {
  78 + data.add("Kitkat");
  79 + data.add("Pie");
  80 + data.add("Oreo");
  81 + assertEquals("Oreo", data.remove(2));
  82 + assertEquals("Pie", data.remove(1));
  83 + assertEquals("Kitkat",data.remove(0));
  84 + }
  85 +}
0 86 \ No newline at end of file
... ...