Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync tests for practice exercise linked-list #2577

Merged
merged 1 commit into from
Nov 22, 2023
Merged
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
1 change: 1 addition & 0 deletions exercises/practice/linked-list/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"msomji",
"muzimuzhi",
"Ppapierski",
"sanderploegsma",
"SleeplessByte",
"Smarticles101",
"sshine",
Expand Down
89 changes: 89 additions & 0 deletions exercises/practice/linked-list/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[7f7e3987-b954-41b8-8084-99beca08752c]
description = "pop gets element from the list"

[c3f67e5d-cfa2-4c3e-a18f-7ce999c3c885]
description = "push/pop respectively add/remove at the end of the list"

[00ea24ce-4f5c-4432-abb4-cc6e85462657]
description = "shift gets an element from the list"

[37962ee0-3324-4a29-b588-5a4c861e6564]
description = "shift gets first element from the list"

[30a3586b-e9dc-43fb-9a73-2770cec2c718]
description = "unshift adds element at start of the list"

[042f71e4-a8a7-4cf0-8953-7e4f3a21c42d]
description = "pop, push, shift, and unshift can be used in any order"

[88f65c0c-4532-4093-8295-2384fb2f37df]
description = "count an empty list"
include = false
comment = "Count is not currently part of the exercise."

[fc055689-5cbe-4cd9-b994-02e2abbb40a5]
description = "count a list with items"
include = false
comment = "Count is not currently part of the exercise."

[8272cef5-130d-40ea-b7f6-5ffd0790d650]
description = "count is correct after mutation"
include = false
comment = "Count is not currently part of the exercise."

[229b8f7a-bd8a-4798-b64f-0dc0bb356d95]
description = "popping to empty doesn't break the list"

[4e1948b4-514e-424b-a3cf-a1ebbfa2d1ad]
description = "shifting to empty doesn't break the list"

[e8f7c600-d597-4f79-949d-8ad8bae895a6]
description = "deletes the only element"
include = false
comment = "Delete is not currently part of the exercise."

[fd65e422-51f3-45c0-9fd0-c33da638f89b]
description = "deletes the element with the specified value from the list"
include = false
comment = "Delete is not currently part of the exercise."

[59db191a-b17f-4ab7-9c5c-60711ec1d013]
description = "deletes the element with the specified value from the list, re-assigns tail"
include = false
comment = "Delete is not currently part of the exercise."

[58242222-5d39-415b-951d-8128247f8993]
description = "deletes the element with the specified value from the list, re-assigns head"
include = false
comment = "Delete is not currently part of the exercise."

[ee3729ee-3405-4bd2-9bad-de0d4aa5d647]
description = "deletes the first of two elements"
include = false
comment = "Delete is not currently part of the exercise."

[47e3b3b4-b82c-4c23-8c1a-ceb9b17cb9fb]
description = "deletes the second of two elements"
include = false
comment = "Delete is not currently part of the exercise."

[7b420958-f285-4922-b8f9-10d9dcab5179]
description = "delete does not modify the list if the element is not found"
include = false
comment = "Delete is not currently part of the exercise."

[7e04828f-6082-44e3-a059-201c63252a76]
description = "deletes only the first occurrence"
include = false
comment = "Delete is not currently part of the exercise."
121 changes: 52 additions & 69 deletions exercises/practice/linked-list/src/test/java/DoublyLinkedListTest.java
Original file line number Diff line number Diff line change
@@ -1,129 +1,112 @@
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Ignore;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;

public class DoublyLinkedListTest {

@Test
public void testPushPop() {
public void popGetsElementFromTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

list.push(10);
list.push(20);
list.push(30);
list.push(7);

assertThat(list.pop()).isEqualTo(30);
assertThat(list.pop()).isEqualTo(20);
assertThat(list.pop()).isEqualTo(10);
assertThat(list.pop()).isEqualTo(7);
}

@Ignore("Remove to run test")
@Test
public void testPushOncePopTwice() {
public void pushAndPopRespectivelyAddsAndRemovesAtEndOfList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

list.push(10);
list.push(11);
list.push(13);

assertThat(list.pop()).isEqualTo(10);
assertThat(list.pop()).isNull();
assertThat(list.pop()).isEqualTo(13);
assertThat(list.pop()).isEqualTo(11);
}

@Ignore("Remove to run test")
@Test
public void testPushShift() {
DoublyLinkedList<String> list = new DoublyLinkedList<>();
public void shiftGetsAnElementFromTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

list.push("10");
list.push("20");
list.push("30");
list.push(17);

assertThat(list.shift()).isEqualTo("10");
assertThat(list.shift()).isEqualTo("20");
assertThat(list.shift()).isEqualTo("30");
assertThat(list.shift()).isEqualTo(17);
}

@Ignore("Remove to run test")
@Test
public void testPushPopShift() {
public void shiftGetsFirstElementFromTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

list.push(10);
list.push(23);
list.push(5);

assertThat(list.pop()).isEqualTo(10);
assertThat(list.shift()).isNull();
assertThat(list.shift()).isEqualTo(23);
assertThat(list.shift()).isEqualTo(5);
}

@Ignore("Remove to run test")
@Test
public void testUnshiftShift() {
DoublyLinkedList<Character> list = new DoublyLinkedList<>();
public void unshiftAddsElementAtStartOfTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

list.unshift('1');
list.unshift('2');
list.unshift('3');
list.unshift(23);
list.unshift(5);

assertThat(list.shift()).isEqualTo('3');
assertThat(list.shift()).isEqualTo('2');
assertThat(list.shift()).isEqualTo('1');
assertThat(list.shift()).isEqualTo(5);
assertThat(list.shift()).isEqualTo(23);
}

@Ignore("Remove to run test")
@Test
public void testUnshiftOnceShiftTwice() {
public void popPushShiftUnshiftCanBeUsedInAnyOrder() {
DoublyLinkedList<String> list = new DoublyLinkedList<>();

list.unshift("10");
list.push("one");
list.push("two");

assertThat(list.shift()).isEqualTo("10");
assertThat(list.shift()).isNull();
}
assertThat(list.pop()).isEqualTo("two");

@Ignore("Remove to run test")
@Test
public void testUnshiftPop() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
list.push("three");

assertThat(list.shift()).isEqualTo("one");

list.unshift(10);
list.unshift(20);
list.unshift(30);
list.unshift("four");
list.push("five");

assertThat(list.pop()).isEqualTo(10);
assertThat(list.pop()).isEqualTo(20);
assertThat(list.pop()).isEqualTo(30);
assertThat(list.shift()).isEqualTo("four");
assertThat(list.pop()).isEqualTo("five");
assertThat(list.shift()).isEqualTo("three");
}

@Ignore("Remove to run test")
@Test
public void testUnshiftShiftPop() {
public void poppingToEmptyDoesNotBreakTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

list.unshift(10);
list.push(41);
list.push(59);
list.pop();
list.pop();
list.push(47);

assertThat(list.shift()).isEqualTo(10);
assertThat(list.pop()).isNull();
assertThat(list.pop()).isEqualTo(47);
}

@Ignore("Remove to run test")
@Test
public void testExample() {
DoublyLinkedList<String> list = new DoublyLinkedList<>();

list.push("ten");
list.push("twenty");

assertThat(list.pop()).isEqualTo("twenty");

list.push("thirty");

assertThat(list.shift()).isEqualTo("ten");
public void shiftingToEmptyDoesNotBreakTheList() {
DoublyLinkedList<Integer> list = new DoublyLinkedList<>();

list.unshift("forty");
list.push("fifty");
list.push(41);
list.push(59);
list.shift();
list.shift();
list.push(47);

assertThat(list.shift()).isEqualTo("forty");
assertThat(list.pop()).isEqualTo("fifty");
assertThat(list.shift()).isEqualTo("thirty");
assertThat(list.shift()).isEqualTo(47);
}

}