Skip to content
Open

123 #35

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions proj1a/src/LinkedListDeque61B.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import java.util.List;

public class LinkedListDeque61B<T> implements Deque61B<T> {

public LinkedListDeque61B() {

}
@Override
public void addFirst(T x) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'addFirst'");
}

@Override
public void addLast(T x) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'addLast'");
}

@Override
public List<T> toList() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'toList'");
}

@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'isEmpty'");
}

@Override
public int size() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'size'");
}

@Override
public T removeFirst() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'removeFirst'");
}

@Override
public T removeLast() {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'removeLast'");
}

@Override
public T get(int index) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'get'");
}

@Override
public T getRecursive(int index) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'getRecursive'");
}

}
94 changes: 47 additions & 47 deletions proj1a/tests/LinkedListDeque61BTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,53 @@
/** Performs some basic linked list tests. */
public class LinkedListDeque61BTest {

// @Test
// /** In this test, we have three different assert statements that verify that addFirst works correctly. */
// public void addFirstTestBasic() {
// Deque61B<String> lld1 = new LinkedListDeque61B<>();

// lld1.addFirst("back"); // after this call we expect: ["back"]
// assertThat(lld1.toList()).containsExactly("back").inOrder();

// lld1.addFirst("middle"); // after this call we expect: ["middle", "back"]
// assertThat(lld1.toList()).containsExactly("middle", "back").inOrder();

// lld1.addFirst("front"); // after this call we expect: ["front", "middle", "back"]
// assertThat(lld1.toList()).containsExactly("front", "middle", "back").inOrder();

// /* Note: The first two assertThat statements aren't really necessary. For example, it's hard
// to imagine a bug in your code that would lead to ["front"] and ["front", "middle"] failing,
// but not ["front", "middle", "back"].
// */
// }

// @Test
// /** In this test, we use only one assertThat statement. IMO this test is just as good as addFirstTestBasic.
// * In other words, the tedious work of adding the extra assertThat statements isn't worth it. */
// public void addLastTestBasic() {
// Deque61B<String> lld1 = new LinkedListDeque61B<>();

// lld1.addLast("front"); // after this call we expect: ["front"]
// lld1.addLast("middle"); // after this call we expect: ["front", "middle"]
// lld1.addLast("back"); // after this call we expect: ["front", "middle", "back"]
// assertThat(lld1.toList()).containsExactly("front", "middle", "back").inOrder();
// }

// @Test
// /** This test performs interspersed addFirst and addLast calls. */
// public void addFirstAndAddLastTest() {
// Deque61B<Integer> lld1 = new LinkedListDeque61B<>();

// /* I've decided to add in comments the state after each call for the convenience of the
// person reading this test. Some programmers might consider this excessively verbose. */
// lld1.addLast(0); // [0]
// lld1.addLast(1); // [0, 1]
// lld1.addFirst(-1); // [-1, 0, 1]
// lld1.addLast(2); // [-1, 0, 1, 2]
// lld1.addFirst(-2); // [-2, -1, 0, 1, 2]

// assertThat(lld1.toList()).containsExactly(-2, -1, 0, 1, 2).inOrder();
// }
@Test
/** In this test, we have three different assert statements that verify that addFirst works correctly. */
public void addFirstTestBasic() {
Deque61B<String> lld1 = new LinkedListDeque61B<>();

lld1.addFirst("back"); // after this call we expect: ["back"]
assertThat(lld1.toList()).containsExactly("back").inOrder();

lld1.addFirst("middle"); // after this call we expect: ["middle", "back"]
assertThat(lld1.toList()).containsExactly("middle", "back").inOrder();

lld1.addFirst("front"); // after this call we expect: ["front", "middle", "back"]
assertThat(lld1.toList()).containsExactly("front", "middle", "back").inOrder();

/* Note: The first two assertThat statements aren't really necessary. For example, it's hard
to imagine a bug in your code that would lead to ["front"] and ["front", "middle"] failing,
but not ["front", "middle", "back"].
*/
}

@Test
/** In this test, we use only one assertThat statement. IMO this test is just as good as addFirstTestBasic.
* In other words, the tedious work of adding the extra assertThat statements isn't worth it. */
public void addLastTestBasic() {
Deque61B<String> lld1 = new LinkedListDeque61B<>();

lld1.addLast("front"); // after this call we expect: ["front"]
lld1.addLast("middle"); // after this call we expect: ["front", "middle"]
lld1.addLast("back"); // after this call we expect: ["front", "middle", "back"]
assertThat(lld1.toList()).containsExactly("front", "middle", "back").inOrder();
}

@Test
/** This test performs interspersed addFirst and addLast calls. */
public void addFirstAndAddLastTest() {
Deque61B<Integer> lld1 = new LinkedListDeque61B<>();

/* I've decided to add in comments the state after each call for the convenience of the
person reading this test. Some programmers might consider this excessively verbose. */
lld1.addLast(0); // [0]
lld1.addLast(1); // [0, 1]
lld1.addFirst(-1); // [-1, 0, 1]
lld1.addLast(2); // [-1, 0, 1, 2]
lld1.addFirst(-2); // [-2, -1, 0, 1, 2]

assertThat(lld1.toList()).containsExactly(-2, -1, 0, 1, 2).inOrder();
}

// Below, you'll write your own tests for LinkedListDeque61B.
}