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

Finished all code and tests #12

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c255f6b
implementing methods
AddisonFarley Jan 4, 2024
cd074ee
finished addFront and addBack
AddisonFarley Jan 4, 2024
8f26ee0
finished get and size
AddisonFarley Jan 4, 2024
d6e1338
finished remove and contains methods
AddisonFarley Jan 9, 2024
87b67b2
created private resize method. finished clear and isEmpty. Started on…
AddisonFarley Jan 9, 2024
e1fac91
created private sizeCheck method and put into all add methods
AddisonFarley Jan 9, 2024
e8a9ab6
created private sizeCheck method and put into all add methods
AddisonFarley Jan 9, 2024
7eb802a
Created LinkedIntList.java and DoublyLinkedIntList.java
AddisonFarley Jan 16, 2024
dbee766
completed addBack() and removeBack() for DoublyLinkedIntList.java
AddisonFarley Jan 16, 2024
94495ae
completed iterator methods and classes for ArrayIntList.java and Link…
AddisonFarley Jan 18, 2024
adc28d5
finished all methods
AddisonFarley Jan 22, 2024
9f3af36
fixed traversal bugs
AddisonFarley Jan 22, 2024
01370c5
finished LinkedIntList.java methods
AddisonFarley Jan 22, 2024
a8ca925
fixed indexOutOfBoundsChecker bug
AddisonFarley Jan 22, 2024
1749a31
finished ArrayIntList.java methods
AddisonFarley Jan 22, 2024
231856a
fixed bugs in addFront(), removeFront(), remove(), and size()
AddisonFarley Jan 22, 2024
06da242
created test files
AddisonFarley Jan 22, 2024
149b8e3
created ArrayIntList.java tests
AddisonFarley Jan 22, 2024
eb4bed3
fixed bugs in removeFront() and removeBack()
AddisonFarley Jan 22, 2024
4e8346a
fixed multiple bugs
AddisonFarley Jan 22, 2024
a0db349
created tests
AddisonFarley Jan 22, 2024
7646bfc
fixed bugs added more comments
AddisonFarley Jan 22, 2024
153aa70
fixed bugs in DoublyLinkedIntList.java, created tests for DoublyLinke…
AddisonFarley Jan 24, 2024
cef78c5
added iterator for DoublyLinkedIntList.java
AddisonFarley Jan 24, 2024
1875f04
forgot testing of resizing
AddisonFarley Jan 24, 2024
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
Prev Previous commit
Next Next commit
created ArrayIntList.java tests
AddisonFarley committed Jan 22, 2024
commit 149b8e3e12f9c07ea8d37555edbbd5f584a2299c
258 changes: 256 additions & 2 deletions tests/ArrayIntListTests.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,265 @@
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class ArrayIntListTests
class ArrayIntListTest
{

@Test
void testAddFront()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
list.addFront(5);
assertEquals(1, list.size());
assertEquals(5, list.get(0));

//test when the data structure has one item
list.addFront(10);
assertEquals(2, list.size());
assertEquals(10, list.get(0));
assertEquals(5, list.get(1));

//test when the data structure has 2 or more items
list.addFront(15);
assertEquals(3, list.size());
assertEquals(15, list.get(0));
assertEquals(10, list.get(1));
assertEquals(5, list.get(2));
}

@Test
void testAddBack()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
list.addBack(5);
assertEquals(1, list.size());
assertEquals(5, list.get(0));

//test when the data structure has one item
list.addBack(10);
assertEquals(2, list.size());
assertEquals(5, list.get(0));
assertEquals(10, list.get(1));

//test when the data structure has 2 or more items
list.addBack(15);
assertEquals(3, list.size());
assertEquals(5, list.get(0));
assertEquals(10, list.get(1));
assertEquals(15, list.get(2));
}

@Test
void testRemoveFront()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
assertDoesNotThrow(list::removeFront);

//test when the data structure has one item
list.addFront(5);
assertDoesNotThrow(list::removeFront);
assertTrue(list.isEmpty());

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
assertDoesNotThrow(list::removeFront);
assertEquals(1, list.size());
assertEquals(15, list.get(0));
}

@Test
void addFront()
void testRemoveBack()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
assertDoesNotThrow(list::removeBack);

//test when the data structure has one item
list.addFront(5);
assertDoesNotThrow(list::removeBack);
assertTrue(list.isEmpty());

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
assertDoesNotThrow(list::removeBack);
assertEquals(1, list.size());
assertEquals(10, list.get(0));
}

@Test
void testRemove()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(0));

//test when the data structure has one item
list.addFront(5);
assertDoesNotThrow(() -> list.remove(0));
assertTrue(list.isEmpty());

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
assertDoesNotThrow(() -> list.remove(1));
assertEquals(1, list.size());
assertEquals(10, list.get(0));

//test when the data structure is "full"
list.addBack(20);
list.addBack(25);
list.addBack(30);
list.addBack(35);
assertDoesNotThrow(() -> list.remove(2));
assertEquals(4, list.size());
assertEquals(20, list.get(2));

//test with invalid parameter values
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(5));
assertThrows(IndexOutOfBoundsException.class, () -> list.remove(-1));
}

@Test
void testGet()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
assertThrows(IndexOutOfBoundsException.class, () -> list.get(0));

//test when the data structure has one item
list.addFront(5);
assertEquals(5, list.get(0));

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
assertEquals(10, list.get(1));

//test with invalid parameter values
assertThrows(IndexOutOfBoundsException.class, () -> list.get(5));
assertThrows(IndexOutOfBoundsException.class, () -> list.get(-1));
}

@Test
void testContains()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
assertFalse(list.contains(5));

//test when the data structure has one item
list.addFront(5);
assertTrue(list.contains(5));

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
assertTrue(list.contains(10));
assertFalse(list.contains(20));
}

@Test
void testIndexOf()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
assertEquals(-1, list.indexOf(5));

//test when the data structure has one item
list.addFront(5);
assertEquals(0, list.indexOf(5));

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
assertEquals(1, list.indexOf(10));
assertEquals(-1, list.indexOf(20));
}

@Test
void testIsEmpty()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
assertTrue(list.isEmpty());

//test when the data structure has one item
list.addFront(5);
assertFalse(list.isEmpty());

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
assertFalse(list.isEmpty());
}

@Test
void testSize()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
assertEquals(0, list.size());

//test when the data structure has one item
list.addFront(5);
assertEquals(1, list.size());

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
assertEquals(3, list.size());
}

@Test
void testClear()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
list.clear();
assertTrue(list.isEmpty());

//test when the data structure has one item
list.addFront(5);
list.clear();
assertTrue(list.isEmpty());

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
list.clear();
assertTrue(list.isEmpty());
}

@Test
void testIterator()
{
ArrayIntList list = new ArrayIntList();

//test when the data structure is empty
assertFalse(list.iterator().hasNext());

//test when the data structure has one item
list.addFront(5);
assertTrue(list.iterator().hasNext());

//test when the data structure has 2 or more items
list.addBack(10);
list.addBack(15);
assertTrue(list.iterator().hasNext());
}
}